From cd5ce661e2a8f9694933358ccb5b916fbed089c2 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Tue, 18 Aug 2009 21:49:39 -0600 Subject: add support for building Debian package --- ao-tools/ao-load/ao-load.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-load/ao-load.c b/ao-tools/ao-load/ao-load.c index 642af2fe..c27fcbe9 100644 --- a/ao-tools/ao-load/ao-load.c +++ b/ao-tools/ao-load/ao-load.c @@ -89,9 +89,6 @@ rewrite(struct hex_image *image, unsigned addr, char *data, int len) memcpy(image->data + addr - image->address, data, len); } -<<<<<<< HEAD:ao-tools/ao-load/ao-load.c -static const struct option -======= static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { 0, 0, 0, 0}, @@ -103,7 +100,6 @@ static void usage(char *program) exit(1); } ->>>>>>> c29275b72438637d46d7a50742882d2736eb176a:ao-tools/ao-load/ao-load.c int main (int argc, char **argv) { -- cgit v1.2.3 From 0c771d999914f9d17c723900f2987acc45fd0fbb Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 4 Sep 2009 13:00:02 -0700 Subject: Move usb scanning code to ao-tools library This will allow the scanning code to be used by the command line tools as well as the ao-view GUI. Now that ao-view depends on the ao-tools library, it has been moved to the ao-tools directory as well. Signed-off-by: Keith Packard --- INSTALL | 17 +- Makefile.am | 2 +- ao-tools/Makefile.am | 2 +- ao-tools/ao-view/.gitignore | 4 + ao-tools/ao-view/Makefile.am | 37 ++ ao-tools/ao-view/ao-view.1 | 50 +++ ao-tools/ao-view/aoview.glade | 744 +++++++++++++++++++++++++++++++++++ ao-tools/ao-view/aoview.h | 323 +++++++++++++++ ao-tools/ao-view/aoview_convert.c | 42 ++ ao-tools/ao-view/aoview_dev_dialog.c | 173 ++++++++ ao-tools/ao-view/aoview_eeprom.c | 157 ++++++++ ao-tools/ao-view/aoview_file.c | 236 +++++++++++ ao-tools/ao-view/aoview_flite.c | 135 +++++++ ao-tools/ao-view/aoview_label.c | 73 ++++ ao-tools/ao-view/aoview_log.c | 70 ++++ ao-tools/ao-view/aoview_main.c | 116 ++++++ ao-tools/ao-view/aoview_monitor.c | 229 +++++++++++ ao-tools/ao-view/aoview_replay.c | 147 +++++++ ao-tools/ao-view/aoview_serial.c | 270 +++++++++++++ ao-tools/ao-view/aoview_state.c | 373 ++++++++++++++++++ ao-tools/ao-view/aoview_table.c | 83 ++++ ao-tools/ao-view/aoview_util.c | 91 +++++ ao-tools/ao-view/aoview_voice.c | 122 ++++++ ao-tools/ao-view/design | 27 ++ ao-tools/lib/Makefile.am | 3 + ao-tools/lib/cc-usbdev.c | 228 +++++++++++ ao-tools/lib/cc-util.c | 80 ++++ ao-tools/lib/cc.h | 51 +++ ao-view/.gitignore | 4 - ao-view/Makefile.am | 35 -- ao-view/ao-view.1 | 50 --- ao-view/aoview.glade | 744 ----------------------------------- ao-view/aoview.h | 337 ---------------- ao-view/aoview_convert.c | 42 -- ao-view/aoview_dev.c | 208 ---------- ao-view/aoview_dev_dialog.c | 168 -------- ao-view/aoview_eeprom.c | 157 -------- ao-view/aoview_file.c | 236 ----------- ao-view/aoview_flite.c | 135 ------- ao-view/aoview_label.c | 73 ---- ao-view/aoview_log.c | 70 ---- ao-view/aoview_main.c | 116 ------ ao-view/aoview_monitor.c | 229 ----------- ao-view/aoview_replay.c | 147 ------- ao-view/aoview_serial.c | 270 ------------- ao-view/aoview_state.c | 373 ------------------ ao-view/aoview_table.c | 83 ---- ao-view/aoview_util.c | 91 ----- ao-view/aoview_voice.c | 122 ------ ao-view/design | 27 -- configure.ac | 2 +- 51 files changed, 3881 insertions(+), 3723 deletions(-) create mode 100644 ao-tools/ao-view/.gitignore create mode 100644 ao-tools/ao-view/Makefile.am create mode 100644 ao-tools/ao-view/ao-view.1 create mode 100644 ao-tools/ao-view/aoview.glade create mode 100644 ao-tools/ao-view/aoview.h create mode 100644 ao-tools/ao-view/aoview_convert.c create mode 100644 ao-tools/ao-view/aoview_dev_dialog.c create mode 100644 ao-tools/ao-view/aoview_eeprom.c create mode 100644 ao-tools/ao-view/aoview_file.c create mode 100644 ao-tools/ao-view/aoview_flite.c create mode 100644 ao-tools/ao-view/aoview_label.c create mode 100644 ao-tools/ao-view/aoview_log.c create mode 100644 ao-tools/ao-view/aoview_main.c create mode 100644 ao-tools/ao-view/aoview_monitor.c create mode 100644 ao-tools/ao-view/aoview_replay.c create mode 100644 ao-tools/ao-view/aoview_serial.c create mode 100644 ao-tools/ao-view/aoview_state.c create mode 100644 ao-tools/ao-view/aoview_table.c create mode 100644 ao-tools/ao-view/aoview_util.c create mode 100644 ao-tools/ao-view/aoview_voice.c create mode 100644 ao-tools/ao-view/design create mode 100644 ao-tools/lib/cc-usbdev.c create mode 100644 ao-tools/lib/cc-util.c create mode 100644 ao-tools/lib/cc.h delete mode 100644 ao-view/.gitignore delete mode 100644 ao-view/Makefile.am delete mode 100644 ao-view/ao-view.1 delete mode 100644 ao-view/aoview.glade delete mode 100644 ao-view/aoview.h delete mode 100644 ao-view/aoview_convert.c delete mode 100644 ao-view/aoview_dev.c delete mode 100644 ao-view/aoview_dev_dialog.c delete mode 100644 ao-view/aoview_eeprom.c delete mode 100644 ao-view/aoview_file.c delete mode 100644 ao-view/aoview_flite.c delete mode 100644 ao-view/aoview_label.c delete mode 100644 ao-view/aoview_log.c delete mode 100644 ao-view/aoview_main.c delete mode 100644 ao-view/aoview_monitor.c delete mode 100644 ao-view/aoview_replay.c delete mode 100644 ao-view/aoview_serial.c delete mode 100644 ao-view/aoview_state.c delete mode 100644 ao-view/aoview_table.c delete mode 100644 ao-view/aoview_util.c delete mode 100644 ao-view/aoview_voice.c delete mode 100644 ao-view/design (limited to 'ao-tools') diff --git a/INSTALL b/INSTALL index 8b82ade0..2550dab7 100644 --- a/INSTALL +++ b/INSTALL @@ -2,7 +2,7 @@ Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, -2006, 2007, 2008 Free Software Foundation, Inc. +2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is free documentation; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. @@ -159,7 +159,7 @@ Particular systems CC is not installed, it is recommended to use the following options in order to use an ANSI C compiler: - ./configure CC="cc -Ae" + ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. @@ -174,6 +174,16 @@ and if that doesn't work, try ./configure CC="cc -nodtk" + On Solaris, don't put `/usr/ucb' early in your `PATH'. This +directory contains several dysfunctional programs; working variants of +these programs are available in `/usr/bin'. So, if you need `/usr/ucb' +in your `PATH', put it _after_ `/usr/bin'. + + On Haiku, software installed for all users goes in `/boot/common', +not `/usr/local'. It is recommended to use the following options: + + ./configure --prefix=/boot/common + Specifying the System Type ========================== @@ -189,7 +199,8 @@ type, such as `sun4', or a canonical name which has the form: where SYSTEM can have one of these forms: - OS KERNEL-OS + OS + KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't diff --git a/Makefile.am b/Makefile.am index 96b9dea9..39e7c244 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=src ao-view ao-tools ao-utils +SUBDIRS=src ao-tools ao-utils EXTRA_DIST = ChangeLog diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 98b88f38..02b4785e 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-load +SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-load ao-view diff --git a/ao-tools/ao-view/.gitignore b/ao-tools/ao-view/.gitignore new file mode 100644 index 00000000..24fbc596 --- /dev/null +++ b/ao-tools/ao-view/.gitignore @@ -0,0 +1,4 @@ +*.o +aoview +aoview_glade.h +aoview_flite diff --git a/ao-tools/ao-view/Makefile.am b/ao-tools/ao-view/Makefile.am new file mode 100644 index 00000000..7b274a40 --- /dev/null +++ b/ao-tools/ao-view/Makefile.am @@ -0,0 +1,37 @@ +VERSION=$(shell git describe) + +AO_VIEW_CFLAGS=-I$(top_srcdir)/ao-tools/lib +AO_VIEW_LIBS=$(top_builddir)/ao-tools/lib/libao-tools.a +AM_CFLAGS=$(AO_VIEW_CFLAGS) $(GNOME_CFLAGS) $(ALSA_CFLAGS) -I$(top_srcdir)/src -DAOVIEW_VERSION=\"$(VERSION)\" @FLITE_INCS@ + +bin_PROGRAMS=ao-view + +ao_view_DEPENDENCIES=$(AO_VIEW_LIBS) +ao_view_LDADD=$(GNOME_LIBS) $(FLITE_LIBS) $(ALSA_LIBS) $(AO_VIEW_LIBS) $(LIBUSB_LIBS) + +ao_view_SOURCES = \ + aoview_main.c \ + aoview_dev_dialog.c \ + aoview_serial.c \ + aoview_monitor.c \ + aoview_state.c \ + aoview_convert.c \ + aoview_log.c \ + aoview_table.c \ + aoview_util.c \ + aoview_file.c \ + aoview_eeprom.c \ + aoview_voice.c \ + aoview_replay.c \ + aoview_label.c \ + aoview_flite.c \ + aoview.h + +BUILT_SOURCES = aoview_glade.h + +CLEANFILES = aoview_glade.h + +man_MANS=ao-view.1 + +aoview_glade.h: aoview.glade + sed -e 's/"/\\"/g' -e 's/^/"/' -e 's/$$/"/' $< > $@ diff --git a/ao-tools/ao-view/ao-view.1 b/ao-tools/ao-view/ao-view.1 new file mode 100644 index 00000000..99834c4e --- /dev/null +++ b/ao-tools/ao-view/ao-view.1 @@ -0,0 +1,50 @@ +.\" +.\" 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-VIEW 1 "ao-view" "" +.SH NAME +ao-view \- Rocket flight monitor +.SH SYNOPSIS +.B "ao-view" +[\--tty \fItty-device\fP] +.SH DESCRIPTION +.I ao-view +connects to a TeleDongle or TeleMetrum device through a USB serial device. +It provides a user interface to monitor, record and review rocket flight data. +.SH OPTIONS +The usual Gtk+ command line options can be used, along with +.IP "\--tty" +This selects a target device to connect at startup time to. +The target device may also be selected through the user interface. +.SH USAGE +When connected to a TeleDongle device, ao-view turns on the radio +receiver and listens for telemetry packets. It displays the received +telemetry data, and reports flight status via voice synthesis. All +received telemetry information is recorded to a file. +.P +When connected to a TeleMetrum device, ao-view downloads the eeprom +data and stores it in a file. +.SH FILES +All data log files are recorded into a user-specified directory +(default ~/AltOS). Files are named using the current date, the serial +number of the reporting device, the flight number recorded in the data +and either '.telem' for telemetry data or '.eeprom' for eeprom data. +.SH "SEE ALSO" +ao-load(1), ao-eeprom(1) +.SH AUTHOR +Keith Packard diff --git a/ao-tools/ao-view/aoview.glade b/ao-tools/ao-view/aoview.glade new file mode 100644 index 00000000..9a746110 --- /dev/null +++ b/ao-tools/ao-view/aoview.glade @@ -0,0 +1,744 @@ + + + + + + 900 + 700 + True + AltOS View + + + True + vertical + + + True + + + True + _File + True + + + True + + + gtk-new + True + True + True + + + + + gtk-open + True + True + True + + + + + gtk-save + True + True + True + + + + + gtk-save-as + True + True + True + + + + + True + + + + + gtk-quit + True + True + True + + + + + + + + + + True + _Edit + True + + + True + + + gtk-cut + True + True + True + + + + + gtk-copy + True + True + True + + + + + gtk-paste + True + True + True + + + + + gtk-delete + True + True + True + + + + + + + + + True + _Device + True + + + True + + + _Connect to device + True + True + False + + + + + True + gtk-connect + + + + + + + _Disconnect + True + True + False + + + True + gtk-disconnect + + + + + + + True + False + + + + + _Save EEPROM data + True + True + False + + + + + True + gtk-save + + + + + + + _Replay + True + True + False + + + + + True + gtk-media-play + + + + + + + + + + + True + _Log + True + + + True + + + _New log + True + True + False + + + True + gtk-new + + + + + + + _Configure Log + True + True + False + + + + True + gtk-preferences + + + + + + + + + + + True + _Voice + True + + + True + + + True + Enable _Voice + True + True + + + + + + + + + True + _Help + True + + + True + + + gtk-about + True + True + True + + + + + + + + + + False + 0 + + + + + True + 2 + 4 + 3 + True + + + True + Height (m) + center + + + + + True + State + + + 1 + 2 + + + + + True + RSSI (dBm) + + + 2 + 3 + + + + + True + 2 + 0 + True + + + 1 + 2 + + + + + True + 2 + pad + True + + + 1 + 2 + 1 + 2 + + + + + True + 2 + -50 + True + + + 2 + 3 + 1 + 2 + + + + + True + Speed (m/s) + + + 3 + 4 + + + + + True + 0 + True + + + 3 + 4 + 1 + 2 + + + + + False + 1 + + + + + True + + + True + True + False + both + + + 0 + + + + + True + True + False + both + + + 1 + + + + + True + True + False + both + + + 2 + + + + + 2 + + + + + + + 5 + normal + False + + + True + vertical + 2 + + + 300 + 100 + True + True + False + True + 0 + False + 1 + both + True + + + 1 + + + + + True + end + + + gtk-cancel + 1 + True + True + True + True + True + + + + False + False + 0 + + + + + gtk-connect + True + True + True + True + True + True + + + False + False + 1 + + + + + False + end + 0 + + + + + + + 5 + Configure Log Directory + dialog + False + select-folder + + + True + vertical + 2 + + + True + end + + + gtk-cancel + True + True + True + True + + + + False + False + 0 + + + + + gtk-ok + True + True + True + True + True + True + + + False + False + 1 + + + + + False + end + 0 + + + + + + + 5 + Failed to create log + normal + True + aoview + error + close + Cannot create log file + + + True + vertical + 2 + + + True + end + + + False + end + 0 + + + + + + + 5 + Failed to open device + normal + True + aoview + error + close + Cannot open device + + + True + vertical + 2 + + + True + end + + + False + end + 0 + + + + + + + 5 + About AoView + False + normal + aoview + False + AoView + Copyright © 2009 Keith Packard + AltOS data capture and display. + http://altusmetrum.org + AoView 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. + +AoView 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 AoView; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + Keith Packard <keithp@keithp.com> + True + + + + + True + vertical + 2 + + + True + end + + + False + end + 0 + + + + + + + 5 + EEPROM save complete + normal + True + aoview + close + Saving EEPROM data as + <filename> + + + + + True + vertical + 2 + + + True + end + + + False + end + 0 + + + + + + + 5 + True + dialog + True + aoview + False + + + True + vertical + 2 + + + True + end + + + gtk-cancel + True + True + True + True + + + + False + False + 0 + + + + + gtk-ok + True + True + True + True + + + False + False + 1 + + + + + False + end + 0 + + + + + + diff --git a/ao-tools/ao-view/aoview.h b/ao-tools/ao-view/aoview.h new file mode 100644 index 00000000..6a4753ac --- /dev/null +++ b/ao-tools/ao-view/aoview.h @@ -0,0 +1,323 @@ +/* + * 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; 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 _AOVIEW_H_ +#define _AOVIEW_H_ + +#define _GNU_SOURCE + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cc.h" + +#include +#include +#include + +struct aogps_time { + int hour; + int minute; + int second; +}; + +struct aogps { + int nsat; + int gps_locked; + int gps_connected; + struct aogps_time gps_time; + double lat; /* degrees (+N -S) */ + double lon; /* degrees (+E -W) */ + int alt; /* m */ + + int gps_extended; /* has extra data */ + double ground_speed; /* m/s */ + int course; /* degrees */ + double climb_rate; /* m/s */ + double hdop; /* unitless? */ + int h_error; /* m */ + int v_error; /* m */ +}; + +#define SIRF_SAT_STATE_ACQUIRED (1 << 0) +#define SIRF_SAT_STATE_CARRIER_PHASE_VALID (1 << 1) +#define SIRF_SAT_BIT_SYNC_COMPLETE (1 << 2) +#define SIRF_SAT_SUBFRAME_SYNC_COMPLETE (1 << 3) +#define SIRF_SAT_CARRIER_PULLIN_COMPLETE (1 << 4) +#define SIRF_SAT_CODE_LOCKED (1 << 5) +#define SIRF_SAT_ACQUISITION_FAILED (1 << 6) +#define SIRF_SAT_EPHEMERIS_AVAILABLE (1 << 7) + +struct aogps_sat { + int svid; + int state; + int c_n0; +}; + +struct aogps_tracking { + int channels; + struct aogps_sat sats[12]; +}; + +struct aodata { + char callsign[16]; + int serial; + int rssi; + char state[16]; + int tick; + int accel; + int pres; + int temp; + int batt; + int drogue; + int main; + int flight_accel; + int ground_accel; + int flight_vel; + int flight_pres; + int ground_pres; + struct aogps gps; + struct aogps_tracking gps_tracking; +}; + +struct aostate { + struct aodata data; + + /* derived data */ + + struct aodata prev_data; + + double report_time; + + gboolean ascent; /* going up? */ + + int ground_altitude; + int height; + double speed; + double acceleration; + double battery; + double temperature; + double main_sense; + double drogue_sense; + double baro_speed; + + int max_height; + double max_acceleration; + double max_speed; + + struct aogps gps; + struct aogps_tracking gps_tracking; + + int gps_valid; + double pad_lat; + double pad_lon; + double pad_alt; + double pad_lat_total; + double pad_lon_total; + double pad_alt_total; + int npad; + int prev_npad; + + double distance; + double bearing; + int gps_height; + + int speak_tick; + int speak_altitude; +}; + +extern struct aostate aostate; + +/* GPS is 'stable' when we've seen at least this many samples */ +#define MIN_PAD_SAMPLES 10 + +void +aoview_monitor_disconnect(void); + +gboolean +aoview_monitor_connect(char *tty); + +gboolean +aoview_monitor_parse(const char *line); + +void +aoview_monitor_reset(void); + +struct aoview_serial * +aoview_serial_open(const char *tty); + +void +aoview_serial_close(struct aoview_serial *serial); + +typedef void (*aoview_serial_callback)(gpointer user_data, struct aoview_serial *serial, gint revents); + +void +aoview_serial_set_callback(struct aoview_serial *serial, + aoview_serial_callback func); + +void +aoview_serial_printf(struct aoview_serial *serial, char *format, ...); + +int +aoview_serial_read(struct aoview_serial *serial, char *buf, int len); + +int +aoview_serial_getc(struct aoview_serial *serial); + +void +aoview_dev_dialog_init(GladeXML *xml); + +void +aoview_state_notify(struct aodata *data); + +void +aoview_state_new(void); + +void +aoview_state_init(GladeXML *xml); + +int16_t +aoview_pres_to_altitude(int16_t pres); + +int16_t +aoview_altitude_to_pres(int16_t alt); + +char * +aoview_fullname (char *dir, char *file); + +char * +aoview_basename(char *file); + +GtkTreeViewColumn * +aoview_add_plain_text_column (GtkTreeView *view, const gchar *title, gint model_column, gint width); + +int +aoview_mkdir(char *dir); + +void +aoview_log_init(GladeXML *xml); + +void +aoview_log_set_serial(int serial); + +int +aoview_log_get_serial(void); + +void +aoview_log_printf(char *format, ...); + +void +aoview_log_new(void); + +void +aoview_table_start(void); + +void +aoview_table_add_row(int column, char *label, char *format, ...); + +void +aoview_table_finish(void); + +void +aoview_table_init(GladeXML *xml); + +void +aoview_table_clear(void); + +struct aoview_file; + +extern char *aoview_file_dir; + +void +aoview_file_finish(struct aoview_file *file); + +gboolean +aoview_file_start(struct aoview_file *file); + +const char * +aoview_file_name(struct aoview_file *file); + +void +aoview_file_set_serial(struct aoview_file *file, int serial); + +int +aoview_file_get_serial(struct aoview_file *file); + +void +aoview_file_printf(struct aoview_file *file, char *format, ...); + +void +aoview_file_vprintf(struct aoview_file *file, char *format, va_list ap); + +struct aoview_file * +aoview_file_new(char *ext); + +void +aoview_file_destroy(struct aoview_file *file); + +void +aoview_file_init(GladeXML *xml); + +/* aoview_eeprom.c */ + +gboolean +aoview_eeprom_save(const char *device); + +void +aoview_eeprom_init(GladeXML *xml); + +/* aoview_voice.c */ +void aoview_voice_open(void); + +void aoview_voice_close(void); + +void aoview_voice_speak(char *format, ...); + +/* aoview_label.c */ + +void aoview_label_init(GladeXML *xml); + +void +aoview_label_show(struct aostate *state); + +/* aoview_flite.c */ + +FILE * +aoview_flite_start(void); + +void +aoview_flite_stop(void); + +/* aoview_main.c */ + +extern char *aoview_tty; + +#endif /* _AOVIEW_H_ */ diff --git a/ao-tools/ao-view/aoview_convert.c b/ao-tools/ao-view/aoview_convert.c new file mode 100644 index 00000000..02416647 --- /dev/null +++ b/ao-tools/ao-view/aoview_convert.c @@ -0,0 +1,42 @@ +/* + * 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; 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 "aoview.h" + +static int16_t altitude_table[2048] = { +#include "altitude.h" +}; + +int16_t +aoview_pres_to_altitude(int16_t pres) +{ + pres = pres >> 4; + if (pres < 0) pres = 0; + if (pres > 2047) pres = 2047; + return altitude_table[pres]; +} + +int16_t +aoview_altitude_to_pres(int16_t alt) +{ + int16_t pres; + + for (pres = 0; pres < 2047; pres++) + if (altitude_table[pres] <= alt) + break; + return pres << 4; +} diff --git a/ao-tools/ao-view/aoview_dev_dialog.c b/ao-tools/ao-view/aoview_dev_dialog.c new file mode 100644 index 00000000..87396c1f --- /dev/null +++ b/ao-tools/ao-view/aoview_dev_dialog.c @@ -0,0 +1,173 @@ +/* + * 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; 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 "aoview.h" + +static void +aoview_dev_dialog_map(GtkWidget *widget, gpointer data) +{ + GtkTreeView *dev_list = data; + GtkListStore *list_store; + GtkTreeIter iter; + int ndev, n; + struct cc_usbdevs *devs; + struct cc_usbdev *dev; + + list_store = gtk_list_store_new(3, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING); + + devs = cc_usbdevs_scan(); + if (devs) { + for (n = 0; n < devs->ndev; n++) { + dev = devs->dev[n]; + gtk_list_store_append(list_store, &iter); + gtk_list_store_set(list_store, &iter, + 0, dev->product, + 1, dev->serial, + 2, dev->tty, + -1); + } + } + gtk_tree_view_set_model (dev_list, GTK_TREE_MODEL(list_store)); + g_object_unref(G_OBJECT(list_store)); + gtk_tree_view_columns_autosize(dev_list); + cc_usbdevs_free(devs); +} + +static GtkMessageDialog *dev_open_fail_dialog; + +static void +aoview_dev_open_failed(char *name) +{ + char *utf8_file; + utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL); + if (!utf8_file) + utf8_file = name; + gtk_message_dialog_format_secondary_text(dev_open_fail_dialog, + "\"%s\"", utf8_file); + if (utf8_file != name) + g_free(utf8_file); + gtk_dialog_run(GTK_DIALOG(dev_open_fail_dialog)); + gtk_widget_hide(GTK_WIDGET(dev_open_fail_dialog)); +} + +gboolean dialog_save_log; + +static void +aoview_dev_selected(GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + gchar *string; + gtk_tree_model_get(model, iter, + 2, &string, + -1); + if (dialog_save_log) { + dialog_save_log = FALSE; + if (!aoview_eeprom_save(string)) + aoview_dev_open_failed(string); + } else { + if (!aoview_monitor_connect(string)) + aoview_dev_open_failed(string); + } +} + +static GtkWidget *dialog; + +static void +aoview_dev_dialog_connect(GtkWidget *widget, gpointer data) +{ + GtkTreeView *dev_list = data; + GtkListStore *list_store; + GtkTreeSelection *tree_selection; + + list_store = GTK_LIST_STORE(gtk_tree_view_get_model(dev_list)); + tree_selection = gtk_tree_view_get_selection(dev_list); + gtk_tree_selection_selected_foreach(tree_selection, + aoview_dev_selected, + data); + gtk_widget_hide(dialog); +} + +static void +aoview_dev_disconnect(GtkWidget *widget) +{ + aoview_monitor_disconnect(); +} + +static void +aoview_dev_savelog(GtkWidget *widget, gpointer data) +{ + dialog_save_log = TRUE; + gtk_widget_show(dialog); +} + +#define _(a) a + +void +aoview_dev_dialog_init(GladeXML *xml) +{ + GtkTreeView *dev_list; + GtkWidget *connect_button; + GtkTreeSelection *dev_selection; + GtkWidget *ao_disconnect; + GtkWidget *ao_savelog; + + dialog = glade_xml_get_widget(xml, "device_connect_dialog"); + assert(dialog); + + dev_list = GTK_TREE_VIEW(glade_xml_get_widget(xml, "dev_list")); + assert(dev_list); + + aoview_add_plain_text_column(dev_list, _("Product"), 0, 16); + aoview_add_plain_text_column(dev_list, _("Serial"), 1, 8); + aoview_add_plain_text_column(dev_list, _("Device"), 2, 13); + + dev_selection = gtk_tree_view_get_selection(dev_list); + gtk_tree_selection_set_mode(dev_selection, GTK_SELECTION_SINGLE); + + g_signal_connect(G_OBJECT(dialog), "map", + G_CALLBACK(aoview_dev_dialog_map), + dev_list); + + connect_button = glade_xml_get_widget(xml, "connect_button"); + assert(connect_button); + + g_signal_connect(G_OBJECT(connect_button), "clicked", + G_CALLBACK(aoview_dev_dialog_connect), + dev_list); + + + ao_disconnect = glade_xml_get_widget(xml, "ao_disconnect"); + assert(ao_disconnect); + + g_signal_connect(G_OBJECT(ao_disconnect), "activate", + G_CALLBACK(aoview_dev_disconnect), + ao_disconnect); + + ao_savelog = glade_xml_get_widget(xml, "ao_savelog"); + assert(ao_savelog); + + g_signal_connect(G_OBJECT(ao_savelog), "activate", + G_CALLBACK(aoview_dev_savelog), + dialog); + dev_open_fail_dialog = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "dev_open_fail_dialog")); + assert(dev_open_fail_dialog); +} diff --git a/ao-tools/ao-view/aoview_eeprom.c b/ao-tools/ao-view/aoview_eeprom.c new file mode 100644 index 00000000..34e2deed --- /dev/null +++ b/ao-tools/ao-view/aoview_eeprom.c @@ -0,0 +1,157 @@ +/* + * 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; 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 "aoview.h" + +#define EEPROM_LEN 1024 + +static struct aoview_file *eeprom_file; +static char eeprom_line[EEPROM_LEN + 1]; +static int eeprom_pos; +static GtkMessageDialog *eeprom_save_done; +static GtkWidget *eeprom_save_close; +static gboolean eeprom_save_shown; + +static void +aoview_eeprom_disconnect(struct aoview_serial *serial) +{ + aoview_file_finish(eeprom_file); +} + +static void +aoview_eeprom_done(struct aoview_serial *serial) +{ + gtk_window_set_title(GTK_WINDOW(eeprom_save_done), + "EEPROM data saved"); + gtk_message_dialog_set_markup(eeprom_save_done, + "EEPROM data saved as"); + if (!eeprom_save_shown) + gtk_widget_show(GTK_WIDGET(eeprom_save_done)); + eeprom_save_close = gtk_window_get_default_widget(GTK_WINDOW(eeprom_save_done)); + if (eeprom_save_close) + gtk_widget_set_sensitive(eeprom_save_close, TRUE); + aoview_eeprom_disconnect(serial); +} + +static gboolean +aoview_eeprom_parse(struct aoview_serial *serial, + char *line) +{ + char cmd; + int tick; + int a; + int b; + int serial_number; + const char *name; + char *utf8_name; + + if (!strcmp(line, "end")) { + aoview_eeprom_done(serial); + return FALSE; + } + if (sscanf(line, "serial-number %u", &serial_number) == 1) { + aoview_file_set_serial(eeprom_file, serial_number); + } else if (sscanf(line, "%c %x %x %x", &cmd, &tick, &a, &b) == 4) { + aoview_file_printf(eeprom_file, "%s\n", line); + if (cmd == 'S' && a == 8) { + aoview_eeprom_done(serial); + return FALSE; + } + + if (!eeprom_save_shown) + { + name = aoview_file_name(eeprom_file); + if (name) { + utf8_name = g_filename_to_utf8(name, -1, NULL, NULL, NULL); + if (!utf8_name) + utf8_name = (char *) name; + gtk_widget_set_sensitive(eeprom_save_close, FALSE); + gtk_window_set_title(GTK_WINDOW(eeprom_save_done), + "Saving EEPROM data"); + gtk_message_dialog_set_markup(eeprom_save_done, + "Saving EEPROM data as"); + gtk_message_dialog_format_secondary_text(eeprom_save_done, "%s", + utf8_name); + if (utf8_name != name) + g_free(utf8_name); + gtk_container_check_resize(GTK_CONTAINER(eeprom_save_done)); + gtk_widget_show(GTK_WIDGET(eeprom_save_done)); + eeprom_save_shown = TRUE; + eeprom_save_close = gtk_window_get_default_widget(GTK_WINDOW(eeprom_save_done)); + if (eeprom_save_close) + gtk_widget_set_sensitive(eeprom_save_close, FALSE); + } + } + } + return TRUE; +} + +static void +aoview_eeprom_callback(gpointer user_data, + struct aoview_serial *serial, + gint revents) +{ + int c; + + if (revents & (G_IO_HUP|G_IO_ERR)) { + aoview_eeprom_disconnect(serial); + return; + } + if (revents & G_IO_IN) { + for (;;) { + c = aoview_serial_getc(serial); + if (c == -1) + break; + if (c == '\r') + continue; + if (c == '\n') { + eeprom_line[eeprom_pos] = '\0'; + if (eeprom_pos) + if (!aoview_eeprom_parse(serial, eeprom_line)) + break; + eeprom_pos = 0; + } else if (eeprom_pos < EEPROM_LEN) + eeprom_line[eeprom_pos++] = c; + } + } +} + +gboolean +aoview_eeprom_save(const char *device) +{ + struct aoview_serial *serial; + + gtk_widget_hide(GTK_WIDGET(eeprom_save_done)); + eeprom_save_shown = FALSE; + serial = aoview_serial_open(device); + if (!serial) + return FALSE; + aoview_serial_set_callback(serial, aoview_eeprom_callback); + aoview_serial_printf(serial, "v\nl\n"); + return TRUE; +} + +void +aoview_eeprom_init(GladeXML *xml) +{ + eeprom_file = aoview_file_new("eeprom"); + assert(eeprom_file); + + eeprom_save_done = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "ao_save_done")); + assert(eeprom_save_done); + +} diff --git a/ao-tools/ao-view/aoview_file.c b/ao-tools/ao-view/aoview_file.c new file mode 100644 index 00000000..5288c2f7 --- /dev/null +++ b/ao-tools/ao-view/aoview_file.c @@ -0,0 +1,236 @@ +/* + * 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; 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 "aoview.h" + +char *aoview_file_dir; + +#define ALTOS_DIR_PATH "/apps/aoview/log_dir" +#define DEFAULT_DIR "AltOS" + +struct aoview_file { + char *ext; + FILE *file; + char *name; + int failed; + int serial; + int sequence; +}; + +static void +aoview_file_save_conf(void) +{ + GConfClient *gconf_client; + + gconf_client = gconf_client_get_default(); + if (gconf_client) + { + gconf_client_set_string(gconf_client, + ALTOS_DIR_PATH, + aoview_file_dir, + NULL); + g_object_unref(G_OBJECT(gconf_client)); + } +} + +static void +aoview_file_configure(GtkWidget *widget, gpointer data) +{ + GtkFileChooser *chooser = data; + aoview_file_dir = gtk_file_chooser_get_filename(chooser); + aoview_file_save_conf(); + gtk_widget_hide(GTK_WIDGET(chooser)); +} + +void +aoview_file_finish(struct aoview_file *file) +{ + if (file->file) { + fclose(file->file); + file->file = NULL; + free(file->name); + file->name = NULL; + } + file->failed = 0; +} + +const char * +aoview_file_name(struct aoview_file *file) +{ + return file->name; +} + +static GtkMessageDialog *file_fail_dialog; + +static void +aoview_file_open_failed(char *name) +{ + char *utf8_file; + utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL); + if (!utf8_file) + utf8_file = name; + gtk_message_dialog_format_secondary_text(file_fail_dialog, + "\"%s\"", utf8_file); + if (utf8_file != name) + g_free(utf8_file); + gtk_widget_show(GTK_WIDGET(file_fail_dialog)); +} + +gboolean +aoview_file_start(struct aoview_file *file) +{ + char base[50]; + struct tm tm; + time_t now; + char *full; + int r; + + if (file->file) + return TRUE; + + if (file->failed) + return FALSE; + + now = time(NULL); + (void) localtime_r(&now, &tm); + aoview_mkdir(aoview_file_dir); + for (;;) { + snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + file->serial, + file->sequence, + file->ext); + full = aoview_fullname(aoview_file_dir, base); + r = access(full, F_OK); + if (r < 0) { + file->file = fopen(full, "w"); + if (!file->file) { + aoview_file_open_failed(full); + free(full); + file->failed = 1; + return FALSE; + } else { + setlinebuf(file->file); + file->name = full; + return TRUE; + } + } + free(full); + file->sequence++; + } +} + +void +aoview_file_vprintf(struct aoview_file *file, char *format, va_list ap) +{ + if (!aoview_file_start(file)) + return; + vfprintf(file->file, format, ap); +} + +void +aoview_file_printf(struct aoview_file *file, char *format, ...) +{ + va_list ap; + + va_start(ap, format); + aoview_file_vprintf(file, format, ap); + va_end(ap); +} + +struct aoview_file * +aoview_file_new(char *ext) +{ + struct aoview_file *file; + + file = calloc (1, sizeof (struct aoview_file)); + if (!file) + return NULL; + file->ext = strdup(ext); + if (!file->ext) { + free(file); + return NULL; + } + return file; +} + +void +aoview_file_destroy(struct aoview_file *file) +{ + if (file->file) + fclose(file->file); + if (file->name) + free(file->name); + free(file->ext); + free(file); +} + +void +aoview_file_set_serial(struct aoview_file *file, int serial) +{ + if (serial != file->serial) + aoview_file_finish(file); + file->serial = serial; +} + +int +aoview_file_get_serial(struct aoview_file *file) +{ + return file->serial; +} + +void +aoview_file_init(GladeXML *xml) +{ + GConfClient *gconf_client; + char *file_dir = NULL; + GtkFileChooser *file_chooser_dialog; + GtkWidget *file_configure_ok; + + g_type_init(); + gconf_client = gconf_client_get_default(); + if (gconf_client) + { + file_dir = gconf_client_get_string(gconf_client, + ALTOS_DIR_PATH, + NULL); + g_object_unref(G_OBJECT(gconf_client)); + } + if (!file_dir) { + aoview_file_dir = aoview_fullname(getenv("HOME"), DEFAULT_DIR); + aoview_file_save_conf(); + } else { + aoview_file_dir = strdup(file_dir); + } + + file_chooser_dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "file_chooser_dialog")); + assert(file_chooser_dialog); + gtk_file_chooser_set_filename(file_chooser_dialog, aoview_file_dir); + + file_configure_ok = glade_xml_get_widget(xml, "file_configure_ok"); + assert(file_configure_ok); + + g_signal_connect(G_OBJECT(file_configure_ok), "clicked", + G_CALLBACK(aoview_file_configure), + file_chooser_dialog); + + + file_fail_dialog = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "file_fail_dialog")); + assert(file_fail_dialog); +} diff --git a/ao-tools/ao-view/aoview_flite.c b/ao-tools/ao-view/aoview_flite.c new file mode 100644 index 00000000..e1b75898 --- /dev/null +++ b/ao-tools/ao-view/aoview_flite.c @@ -0,0 +1,135 @@ +/* + * 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; 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 "aoview.h" +#include + +cst_voice *register_cmu_us_kal(); +static cst_voice *voice; + +static FILE *pipe_write; +static GThread *aoview_flite_thread; + +static snd_pcm_t *alsa_handle; + +gpointer +aoview_flite_task(gpointer data) +{ + FILE *input = data; + char line[1024]; + cst_wave *wave; + int rate; + int channels; + int err; + char *samples; + int num_samples; + + err = snd_pcm_open(&alsa_handle, "default", + SND_PCM_STREAM_PLAYBACK, 0); + if (err >= 0) + { + if (err < 0) { + snd_pcm_close(alsa_handle); + alsa_handle = 0; + } + } + rate = 0; + channels = 0; + while (fgets(line, sizeof (line) - 1, input) != NULL) { + if (!alsa_handle) + continue; + wave = flite_text_to_wave(line, voice); + if (wave->sample_rate != rate || + wave->num_channels != channels) + { + rate = wave->sample_rate; + channels = wave->num_channels; + err = snd_pcm_set_params(alsa_handle, + SND_PCM_FORMAT_S16, + SND_PCM_ACCESS_RW_INTERLEAVED, + channels, + rate, + 1, + 100000); + if (err < 0) + fprintf(stderr, "alsa set_params error %s\n", + strerror(-err)); + } + err = snd_pcm_prepare(alsa_handle); + if (err < 0) + fprintf(stderr, "alsa pcm_prepare error %s\n", + strerror(-err)); + samples = (char *) wave->samples; + num_samples = wave->num_samples; + while (num_samples > 0) { + err = snd_pcm_writei(alsa_handle, + samples, num_samples); + if (err <= 0) { + fprintf(stderr, "alsa write error %s\n", + strerror(-err)); + break; + } + num_samples -= err; + samples += err * 2 * channels; + } + snd_pcm_drain(alsa_handle); + delete_wave(wave); + } + snd_pcm_close(alsa_handle); + alsa_handle = 0; + return NULL; +} + +void +aoview_flite_stop(void) +{ + int status; + if (pipe_write) { + fclose(pipe_write); + pipe_write = NULL; + } + if (aoview_flite_thread) { + g_thread_join(aoview_flite_thread); + aoview_flite_thread = NULL; + } +} + +FILE * +aoview_flite_start(void) +{ + static once; + int p[2]; + GError *error; + FILE *pipe_read; + + if (!once) { + flite_init(); + voice = register_cmu_us_kal(); + if (!voice) { + perror("register voice"); + exit(1); + } + } + aoview_flite_stop(); + pipe(p); + pipe_read = fdopen(p[0], "r"); + pipe_write = fdopen(p[1], "w"); + g_thread_create(aoview_flite_task, pipe_read, TRUE, &error); + return pipe_write; +} diff --git a/ao-tools/ao-view/aoview_label.c b/ao-tools/ao-view/aoview_label.c new file mode 100644 index 00000000..24313626 --- /dev/null +++ b/ao-tools/ao-view/aoview_label.c @@ -0,0 +1,73 @@ +/* + * 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; 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 "aoview.h" + +static struct { + char *name; + char *initial_value; + GtkLabel *widget; +} label_widgets[] = { + { "height_label", "Height (m)", NULL }, + { "state_label", "State", NULL }, + { "rssi_label", "RSSI (dBm)", NULL }, + { "speed_label", "Speed (m/s)", NULL }, + { "height_value", "0", NULL }, + { "state_value", "pad", NULL }, + { "rssi_value", "-50", NULL }, + { "speed_value", "0", NULL }, +}; + +static void +aoview_label_assign(GtkLabel *widget, char *value) +{ + char *markup; + + markup = g_markup_printf_escaped("%s", value); + gtk_label_set_markup(widget, markup); + g_free(markup); +} + +void +aoview_label_show(struct aostate *state) +{ + char line[1024]; + sprintf(line, "%d", state->height); + aoview_label_assign(label_widgets[4].widget, line); + + aoview_label_assign(label_widgets[5].widget, state->data.state); + + sprintf(line, "%d", state->data.rssi); + aoview_label_assign(label_widgets[6].widget, line); + + if (state->ascent) + sprintf(line, "%6.0f", fabs(state->speed)); + else + sprintf(line, "%6.0f", fabs(state->baro_speed)); + aoview_label_assign(label_widgets[7].widget, line); +} + +void +aoview_label_init(GladeXML *xml) +{ + int i; + for (i = 0; i < sizeof(label_widgets)/sizeof(label_widgets[0]); i++) { + label_widgets[i].widget = GTK_LABEL(glade_xml_get_widget(xml, label_widgets[i].name)); + aoview_label_assign(label_widgets[i].widget, label_widgets[i].initial_value); + assert(label_widgets[i].widget); + } +} diff --git a/ao-tools/ao-view/aoview_log.c b/ao-tools/ao-view/aoview_log.c new file mode 100644 index 00000000..1b89c28c --- /dev/null +++ b/ao-tools/ao-view/aoview_log.c @@ -0,0 +1,70 @@ +/* + * 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; 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 "aoview.h" + +static struct aoview_file *aoview_log; + +void +aoview_log_new(void) +{ + aoview_file_finish(aoview_log); + aoview_state_new(); +} + +void +aoview_log_set_serial(int serial) +{ + aoview_file_set_serial(aoview_log, serial); +} + +int +aoview_log_get_serial(void) +{ + return aoview_file_get_serial(aoview_log); +} + +void +aoview_log_printf(char *format, ...) +{ + va_list ap; + + va_start(ap, format); + aoview_file_vprintf(aoview_log, format, ap); + va_end(ap); +} + +static void +aoview_log_new_item(GtkWidget *widget, gpointer data) +{ + aoview_file_finish(aoview_log); +} + +void +aoview_log_init(GladeXML *xml) +{ + GtkWidget *log_new; + + aoview_log = aoview_file_new("telem"); + assert(aoview_log); + + log_new = glade_xml_get_widget(xml, "log_new"); + assert(log_new); + g_signal_connect(G_OBJECT(log_new), "activate", + G_CALLBACK(aoview_log_new_item), + NULL); +} diff --git a/ao-tools/ao-view/aoview_main.c b/ao-tools/ao-view/aoview_main.c new file mode 100644 index 00000000..64c1c027 --- /dev/null +++ b/ao-tools/ao-view/aoview_main.c @@ -0,0 +1,116 @@ +/* + * 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; 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 "aoview.h" + +static const char aoview_glade[] = { +#include "aoview_glade.h" +}; + +static void usage(void) { + printf("aoview [--device|-d device_file]"); + exit(1); +} + +static void destroy_event(GtkWidget *widget, gpointer data) +{ + gtk_main_quit(); +} + +extern int _Xdebug; +char *aoview_tty = NULL; + +int main(int argc, char **argv) +{ + GladeXML *xml = NULL; + GtkWidget *mainwindow; + GtkAboutDialog *about_dialog; + + static struct option long_options[] = { + { "tty", 1, 0, 'T'}, + { "sync", 0, 0, 's'}, + { 0, 0, 0, 0 } + }; + for (;;) { + int c, temp; + + c = getopt_long_only(argc, argv, "sT:", long_options, &temp); + if (c == -1) + break; + + switch (c) { + case 'T': + aoview_tty = optarg; + break; + case 's': + _Xdebug = 1; + break; + default: + usage(); + } + } + + g_thread_init(NULL); + gtk_init(&argc, &argv); + glade_init(); + + xml = glade_xml_new_from_buffer(aoview_glade, sizeof (aoview_glade), NULL, NULL); + + /* connect the signals in the interface */ + glade_xml_signal_autoconnect(xml); + + /* Hook up the close button. */ + mainwindow = glade_xml_get_widget(xml, "aoview"); + assert(mainwindow); + + g_signal_connect (G_OBJECT(mainwindow), "destroy", + G_CALLBACK(destroy_event), NULL); + + about_dialog = GTK_ABOUT_DIALOG(glade_xml_get_widget(xml, "about_dialog")); + assert(about_dialog); + gtk_about_dialog_set_version(about_dialog, AOVIEW_VERSION); + + aoview_voice_init(xml); + + aoview_dev_dialog_init(xml); + + aoview_state_init(xml); + + aoview_file_init(xml); + + aoview_log_init(xml); + + aoview_table_init(xml); + + aoview_eeprom_init(xml); + + aoview_replay_init(xml); + + aoview_label_init(xml); + + if (aoview_tty) { + if (!aoview_monitor_connect(aoview_tty)) { + perror(aoview_tty); + exit(1); + } + } + aoview_voice_speak("rocket flight monitor ready\n"); + + gtk_main(); + + return 0; +} diff --git a/ao-tools/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c new file mode 100644 index 00000000..8564014b --- /dev/null +++ b/ao-tools/ao-view/aoview_monitor.c @@ -0,0 +1,229 @@ +/* + * 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; 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 "aoview.h" + +static struct aoview_serial *monitor_serial; + +#define MONITOR_LEN 1024 + +static char monitor_line[MONITOR_LEN + 1]; +static int monitor_pos; + +void +aoview_monitor_disconnect(void) +{ + if (monitor_serial) { + aoview_serial_close(monitor_serial); + monitor_serial = NULL; + } + aoview_log_new(); +} + +static void +aoview_parse_string(char *target, int len, char *source) +{ + strncpy(target, source, len-1); + target[len-1] = '\0'; +} + +static void +aoview_parse_int(int *target, char *source) +{ + *target = strtol(source, NULL, 0); +} + +static void +aoview_parse_hex(int *target, char *source) +{ + *target = strtol(source, NULL, 16); +} + +static void +aoview_parse_pos(double *target, char *source) +{ + int deg; + double min; + char dir; + double r; + + if (sscanf(source, "%d°%lf'%c", °, &min, &dir) != 3) { + *target = 0; + return; + } + r = deg + min / 60.0; + if (dir == 'S' || dir == 'W') + r = -r; + *target = r; +} + +#define PARSE_MAX_WORDS 256 + +gboolean +aoview_monitor_parse(const char *input_line) +{ + char *saveptr; + char *words[PARSE_MAX_WORDS]; + int nword; + char line_buf[8192], *line; + struct aodata data; + int tracking_pos; + + /* avoid smashing our input parameter */ + strncpy (line_buf, input_line, sizeof (line_buf)-1); + line_buf[sizeof(line_buf) - 1] = '\0'; + line = line_buf; + for (nword = 0; nword < PARSE_MAX_WORDS; nword++) { + words[nword] = strtok_r(line, " \t\n", &saveptr); + line = NULL; + if (words[nword] == NULL) + break; + } + if (nword < 36) + return FALSE; + if (strcmp(words[0], "CALL") != 0) + return FALSE; + aoview_parse_string(data.callsign, sizeof (data.callsign), words[1]); + aoview_parse_int(&data.serial, words[3]); + + aoview_parse_int(&data.rssi, words[5]); + aoview_parse_string(data.state, sizeof (data.state), words[9]); + aoview_parse_int(&data.tick, words[10]); + aoview_parse_int(&data.accel, words[12]); + aoview_parse_int(&data.pres, words[14]); + aoview_parse_int(&data.temp, words[16]); + aoview_parse_int(&data.batt, words[18]); + aoview_parse_int(&data.drogue, words[20]); + aoview_parse_int(&data.main, words[22]); + aoview_parse_int(&data.flight_accel, words[24]); + aoview_parse_int(&data.ground_accel, words[26]); + aoview_parse_int(&data.flight_vel, words[28]); + aoview_parse_int(&data.flight_pres, words[30]); + aoview_parse_int(&data.ground_pres, words[32]); + aoview_parse_int(&data.gps.nsat, words[34]); + if (strcmp (words[36], "unlocked") == 0) { + data.gps.gps_connected = 1; + data.gps.gps_locked = 0; + data.gps.gps_time.hour = data.gps.gps_time.minute = data.gps.gps_time.second = 0; + data.gps.lat = data.gps.lon = 0; + data.gps.alt = 0; + tracking_pos = 37; + } else if (nword >= 40) { + data.gps.gps_locked = 1; + data.gps.gps_connected = 1; + sscanf(words[36], "%d:%d:%d", &data.gps.gps_time.hour, &data.gps.gps_time.minute, &data.gps.gps_time.second); + aoview_parse_pos(&data.gps.lat, words[37]); + aoview_parse_pos(&data.gps.lon, words[38]); + sscanf(words[39], "%dm", &data.gps.alt); + tracking_pos = 46; + } else { + data.gps.gps_connected = 0; + data.gps.gps_locked = 0; + data.gps.gps_time.hour = data.gps.gps_time.minute = data.gps.gps_time.second = 0; + data.gps.lat = data.gps.lon = 0; + data.gps.alt = 0; + tracking_pos = -1; + } + if (nword >= 46) { + data.gps.gps_extended = 1; + sscanf(words[40], "%lfm/s", &data.gps.ground_speed); + sscanf(words[41], "%d", &data.gps.course); + sscanf(words[42], "%lfm/s", &data.gps.climb_rate); + sscanf(words[43], "%lf", &data.gps.hdop); + sscanf(words[44], "%d", &data.gps.h_error); + sscanf(words[45], "%d", &data.gps.v_error); + } else { + data.gps.gps_extended = 0; + data.gps.ground_speed = 0; + data.gps.course = 0; + data.gps.climb_rate = 0; + data.gps.hdop = 0; + data.gps.h_error = 0; + data.gps.v_error = 0; + } + if (tracking_pos >= 0 && nword >= tracking_pos + 2 && strcmp(words[tracking_pos], "SAT") == 0) { + int c, n, pos; + aoview_parse_int(&n, words[tracking_pos + 1]); + pos = tracking_pos + 2; + if (nword >= pos + n * 3) { + data.gps_tracking.channels = n; + for (c = 0; c < n; c++) { + aoview_parse_int(&data.gps_tracking.sats[c].svid, + words[pos + 0]); + aoview_parse_hex(&data.gps_tracking.sats[c].state, + words[pos + 1]); + aoview_parse_int(&data.gps_tracking.sats[c].c_n0, + words[pos + 2]); + pos += 3; + } + } else { + data.gps_tracking.channels = 0; + } + } else { + data.gps_tracking.channels = 0; + } + aoview_state_notify(&data); + return TRUE; +} + +static void +aoview_monitor_callback(gpointer user_data, + struct aoview_serial *serial, + gint revents) +{ + int c; + + if (revents & (G_IO_HUP|G_IO_ERR)) { + aoview_monitor_disconnect(); + return; + } + if (revents & G_IO_IN) { + for (;;) { + c = aoview_serial_getc(serial); + if (c == -1) + break; + if (c == '\r') + continue; + if (c == '\n') { + monitor_line[monitor_pos] = '\0'; + if (monitor_pos) { + if (aoview_monitor_parse(monitor_line)) { + aoview_log_set_serial(aostate.data.serial); + if (aoview_log_get_serial()) + aoview_log_printf ("%s\n", monitor_line); + } + } + monitor_pos = 0; + } else if (monitor_pos < MONITOR_LEN) + monitor_line[monitor_pos++] = c; + } + } +} + +gboolean +aoview_monitor_connect(char *tty) +{ + aoview_monitor_disconnect(); + monitor_serial = aoview_serial_open(tty); + if (!monitor_serial) + return FALSE; + aoview_table_clear(); + aoview_state_reset(); + aoview_serial_set_callback(monitor_serial, + aoview_monitor_callback); + return TRUE; +} diff --git a/ao-tools/ao-view/aoview_replay.c b/ao-tools/ao-view/aoview_replay.c new file mode 100644 index 00000000..da7b5d6a --- /dev/null +++ b/ao-tools/ao-view/aoview_replay.c @@ -0,0 +1,147 @@ +/* + * 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; 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 "aoview.h" + +static GtkFileChooser *replay_dialog; +static GtkWidget *replay_ok; +static FILE *replay_file; +static int replay_tick; + +static int +find_tick(char *line, gboolean *is_pad) +{ + char *state = strstr(line, "STATE"); + if (!state) + return -1; + state = strchr(state, ' '); + if (!state) + return -1; + while (*state == ' ') + state++; + *is_pad = strncmp(state, "pad", 3) == 0; + while (*state && !isdigit(*state)) + state++; + return atoi(state); +} + +static void +aoview_replay_close(void) +{ + if (replay_file) { + fclose(replay_file); + replay_file = NULL; + } +} + +static char replay_line[1024]; + +static gboolean +aoview_replay_read(gpointer data); + +static gboolean +aoview_replay_execute(gpointer data) +{ + aoview_monitor_parse(replay_line); + g_idle_add(aoview_replay_read, NULL); + return FALSE; +} + +static gboolean +aoview_replay_read(gpointer data) +{ + int tick; + gboolean is_pad; + + if (!replay_file) + return FALSE; + if (fgets(replay_line, sizeof (replay_line), replay_file)) { + tick = find_tick(replay_line, &is_pad); + if (tick >= 0 && replay_tick >= 0 && !is_pad) { + while (tick < replay_tick) + tick += 65536; + g_timeout_add((tick - replay_tick) * 10, + aoview_replay_execute, + NULL); + } else { + aoview_replay_execute(NULL); + } + replay_tick = tick; + } else { + aoview_replay_close(); + } + return FALSE; +} + +static void +aoview_replay_open(GtkWidget *widget, gpointer data) +{ + char *replay_file_name; + GtkWidget *dialog; + + aoview_replay_close(); + replay_file_name = gtk_file_chooser_get_filename(replay_dialog); + replay_file = fopen(replay_file_name, "r"); + if (!replay_file) { + dialog = gtk_message_dialog_new(GTK_WINDOW(replay_dialog), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Error loading file '%s': %s", + replay_file_name, g_strerror(errno)); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + } else { + replay_tick = -1; + aoview_state_reset(); + aoview_replay_read(NULL); + } + gtk_widget_hide(GTK_WIDGET(replay_dialog)); +} + +void +aoview_replay_init(GladeXML *xml) +{ + GtkFileFilter *telem_filter; + GtkFileFilter *all_filter; + GtkFileFilter *log_filter; + + telem_filter = gtk_file_filter_new(); + gtk_file_filter_add_pattern(telem_filter, "*.telem"); + gtk_file_filter_set_name(telem_filter, "Telemetry Files"); + + log_filter = gtk_file_filter_new(); + gtk_file_filter_add_pattern(log_filter, "*.log"); + gtk_file_filter_set_name(log_filter, "Log Files"); + + all_filter = gtk_file_filter_new(); + gtk_file_filter_add_pattern(all_filter, "*"); + gtk_file_filter_set_name(all_filter, "All Files"); + + replay_dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "ao_replay_dialog")); + assert(replay_dialog); + gtk_file_chooser_set_current_folder(replay_dialog, aoview_file_dir); + gtk_file_chooser_add_filter(replay_dialog, telem_filter); + gtk_file_chooser_add_filter(replay_dialog, log_filter); + gtk_file_chooser_add_filter(replay_dialog, all_filter); + + replay_ok = glade_xml_get_widget(xml, "ao_replay_ok"); + assert(replay_ok); + g_signal_connect(G_OBJECT(replay_ok), "clicked", + G_CALLBACK(aoview_replay_open), + replay_dialog); +} diff --git a/ao-tools/ao-view/aoview_serial.c b/ao-tools/ao-view/aoview_serial.c new file mode 100644 index 00000000..29038b79 --- /dev/null +++ b/ao-tools/ao-view/aoview_serial.c @@ -0,0 +1,270 @@ +/* + * 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; 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 "aoview.h" +#include + +#define AOVIEW_SERIAL_IN_BUF 64 +#define AOVIEW_SERIAL_OUT_BUF 64 + +struct aoview_buf { + char *buf; + int off; + int count; + int size; +}; + +static int +aoview_buf_write(struct aoview_buf *buf, char *data, int len) +{ + if (buf->count + len > buf->size) { + int new_size = buf->size * 2; + if (new_size == 0) + new_size = 1024; + if (buf->buf) + buf->buf = realloc (buf->buf, new_size); + else + buf->buf = malloc (new_size); + buf->size = new_size; + } + memcpy(buf->buf + buf->count, data, len); + buf->count += len; + return len; +} + +static int +aoview_buf_read(struct aoview_buf *buf, char *data, int len) +{ + if (len > buf->count - buf->off) + len = buf->count - buf->off; + memcpy (data, buf->buf + buf->off, len); + buf->off += len; + if (buf->off == buf->count) + buf->off = buf->count = 0; + return len; +} + +static int +aoview_buf_getc(struct aoview_buf *buf) +{ + char b; + int r; + + r = aoview_buf_read(buf, &b, 1); + if (r == 1) + return (int) b; + return -1; +} + +static void +aoview_buf_flush(struct aoview_buf *buf, int fd) +{ + int ret; + + if (buf->count > buf->off) { + ret = write(fd, buf->buf + buf->off, buf->count - buf->off); + if (ret > 0) { + buf->off += ret; + if (buf->off == buf->count) + buf->off = buf->count = 0; + } + } +} + +static void +aoview_buf_fill(struct aoview_buf *buf, int fd) +{ + int ret; + + while (buf->count >= buf->size) { + int new_size = buf->size * 2; + buf->buf = realloc (buf->buf, new_size); + buf->size = new_size; + } + + ret = read(fd, buf->buf + buf->count, buf->size - buf->count); + if (ret > 0) + buf->count += ret; +} + +static void +aoview_buf_init(struct aoview_buf *buf) +{ + buf->buf = malloc (buf->size = 1024); + buf->count = 0; +} + +static void +aoview_buf_fini(struct aoview_buf *buf) +{ + free(buf->buf); +} + +struct aoview_serial { + GSource source; + int fd; + struct termios save_termios; + struct aoview_buf in_buf; + struct aoview_buf out_buf; + GPollFD poll_fd; +}; + + +void +aoview_serial_printf(struct aoview_serial *serial, char *format, ...) +{ + char buf[1024]; + va_list ap; + int ret; + + /* sprintf to a local buffer */ + va_start(ap, format); + ret = vsnprintf(buf, sizeof(buf), format, ap); + va_end(ap); + if (ret > sizeof(buf)) { + fprintf(stderr, "printf overflow for format %s\n", + format); + } + + /* flush local buffer to the wire */ + aoview_buf_write(&serial->out_buf, buf, ret); + aoview_buf_flush(&serial->out_buf, serial->fd); +} + +int +aoview_serial_read(struct aoview_serial *serial, char *buf, int len) +{ + return aoview_buf_read(&serial->in_buf, buf, len); +} + +int +aoview_serial_getc(struct aoview_serial *serial) +{ + return aoview_buf_getc(&serial->in_buf); +} + +static gboolean +serial_prepare(GSource *source, gint *timeout) +{ + struct aoview_serial *serial = (struct aoview_serial *) source; + *timeout = -1; + + if (serial->out_buf.count) + serial->poll_fd.events |= G_IO_OUT; + else + serial->poll_fd.events &= ~G_IO_OUT; + return FALSE; +} + +static gboolean +serial_check(GSource *source) +{ + struct aoview_serial *serial = (struct aoview_serial *) source; + gint revents = serial->poll_fd.revents; + + if (revents & G_IO_NVAL) + return FALSE; + if (revents & G_IO_IN) + return TRUE; + if (revents & G_IO_OUT) + return TRUE; + return FALSE; +} + +static gboolean +serial_dispatch(GSource *source, + GSourceFunc callback, + gpointer user_data) +{ + struct aoview_serial *serial = (struct aoview_serial *) source; + aoview_serial_callback func = (aoview_serial_callback) callback; + gint revents = serial->poll_fd.revents; + + if (revents & G_IO_IN) + aoview_buf_fill(&serial->in_buf, serial->fd); + + if (revents & G_IO_OUT) + aoview_buf_flush(&serial->out_buf, serial->fd); + + if (func) + (*func)(user_data, serial, revents); + return TRUE; +} + +static void +serial_finalize(GSource *source) +{ + struct aoview_serial *serial = (struct aoview_serial *) source; + + aoview_buf_fini(&serial->in_buf); + aoview_buf_fini(&serial->out_buf); + tcsetattr(serial->fd, TCSAFLUSH, &serial->save_termios); + close (serial->fd); +} + +static GSourceFuncs serial_funcs = { + serial_prepare, + serial_check, + serial_dispatch, + serial_finalize +}; + +struct aoview_serial * +aoview_serial_open(const char *tty) +{ + struct aoview_serial *serial; + struct termios termios; + + serial = (struct aoview_serial *) g_source_new(&serial_funcs, sizeof (struct aoview_serial)); + aoview_buf_init(&serial->in_buf); + aoview_buf_init(&serial->out_buf); + serial->fd = open (tty, O_RDWR | O_NONBLOCK); + if (serial->fd < 0) { + g_source_destroy(&serial->source); + return NULL; + } + tcgetattr(serial->fd, &termios); + serial->save_termios = termios; + cfmakeraw(&termios); + tcsetattr(serial->fd, TCSAFLUSH, &termios); + + aoview_serial_printf(serial, "E 0\n"); + tcdrain(serial->fd); + usleep(15*1000); + tcflush(serial->fd, TCIFLUSH); + serial->poll_fd.fd = serial->fd; + serial->poll_fd.events = G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR; + g_source_attach(&serial->source, NULL); + g_source_add_poll(&serial->source,&serial->poll_fd); + aoview_serial_set_callback(serial, NULL); + return serial; +} + +void +aoview_serial_close(struct aoview_serial *serial) +{ + g_source_remove_poll(&serial->source, &serial->poll_fd); + close(serial->fd); + g_source_destroy(&serial->source); +} + +void +aoview_serial_set_callback(struct aoview_serial *serial, + aoview_serial_callback func) +{ + g_source_set_callback(&serial->source, (GSourceFunc) func, serial, NULL); +} diff --git a/ao-tools/ao-view/aoview_state.c b/ao-tools/ao-view/aoview_state.c new file mode 100644 index 00000000..f75066dd --- /dev/null +++ b/ao-tools/ao-view/aoview_state.c @@ -0,0 +1,373 @@ +/* + * 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; 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 "aoview.h" +#include + +static inline double sqr(double a) { return a * a; }; + +static void +aoview_great_circle (double start_lat, double start_lon, + double end_lat, double end_lon, + double *dist, double *bearing) +{ + const double rad = M_PI / 180; + const double earth_radius = 6371.2 * 1000; /* in meters */ + double lat1 = rad * start_lat; + double lon1 = rad * -start_lon; + double lat2 = rad * end_lat; + double lon2 = rad * -end_lon; + + double d_lat = lat2 - lat1; + double d_lon = lon2 - lon1; + + /* From http://en.wikipedia.org/wiki/Great-circle_distance */ + double vdn = sqrt(sqr(cos(lat2) * sin(d_lon)) + + sqr(cos(lat1) * sin(lat2) - + sin(lat1) * cos(lat2) * cos(d_lon))); + double vdd = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(d_lon); + double d = atan2(vdn,vdd); + double course; + + if (cos(lat1) < 1e-20) { + if (lat1 > 0) + course = M_PI; + else + course = -M_PI; + } else { + if (d < 1e-10) + course = 0; + else + course = acos((sin(lat2)-sin(lat1)*cos(d)) / + (sin(d)*cos(lat1))); + if (sin(lon2-lon1) > 0) + course = 2 * M_PI-course; + } + *dist = d * earth_radius; + *bearing = course * 180/M_PI; +} + +static void +aoview_state_add_deg(int column, char *label, double deg, char pos, char neg) +{ + double int_part; + double min; + char sign = pos; + + if (deg < 0) { + deg = -deg; + sign = neg; + } + int_part = floor (deg); + min = (deg - int_part) * 60.0; + aoview_table_add_row(column, label, "%d°%lf'%c", + (int) int_part, min, sign); + +} + +static char *ascent_states[] = { + "boost", + "fast", + "coast", + 0, +}; + +static double +aoview_time(void) +{ + struct timespec now; + + clock_gettime(CLOCK_MONOTONIC, &now); + return (double) now.tv_sec + (double) now.tv_nsec / 1.0e9; +} + +/* + * Fill out the derived data fields + */ +static void +aoview_state_derive(struct aodata *data, struct aostate *state) +{ + int i; + double new_height; + double height_change; + double time_change; + int tick_count; + + state->report_time = aoview_time(); + + state->prev_data = state->data; + state->prev_npad = state->npad; + state->data = *data; + tick_count = data->tick; + if (tick_count < state->prev_data.tick) + tick_count += 65536; + time_change = (tick_count - state->prev_data.tick) / 100.0; + + state->ground_altitude = aoview_pres_to_altitude(data->ground_pres); + new_height = aoview_pres_to_altitude(data->flight_pres) - state->ground_altitude; + height_change = new_height - state->height; + state->height = new_height; + if (time_change) + state->baro_speed = (state->baro_speed * 3 + (height_change / time_change)) / 4.0; + state->acceleration = (data->ground_accel - data->flight_accel) / 27.0; + state->speed = data->flight_vel / 2700.0; + state->temperature = ((data->temp / 32767.0 * 3.3) - 0.5) / 0.01; + state->drogue_sense = data->drogue / 32767.0 * 15.0; + state->main_sense = data->main / 32767.0 * 15.0; + state->battery = data->batt / 32767.0 * 5.0; + if (!strcmp(data->state, "pad")) { + if (data->gps.gps_locked && data->gps.nsat >= 4) { + state->npad++; + state->pad_lat_total += data->gps.lat; + state->pad_lon_total += data->gps.lon; + state->pad_alt_total += data->gps.alt; + if (state->npad > 1) { + state->pad_lat = (state->pad_lat * 31 + data->gps.lat) / 32.0; + state->pad_lon = (state->pad_lon * 31 + data->gps.lon) / 32.0; + state->pad_alt = (state->pad_alt * 31 + data->gps.alt) / 32.0; + } else { + state->pad_lat = data->gps.lat; + state->pad_lon = data->gps.lon; + state->pad_alt = data->gps.alt; + } + } + } + state->ascent = FALSE; + for (i = 0; ascent_states[i]; i++) + if (!strcmp(data->state, ascent_states[i])) + state->ascent = TRUE; + + /* Only look at accelerometer data on the way up */ + if (state->ascent && state->acceleration > state->max_acceleration) + state->max_acceleration = state->acceleration; + if (state->ascent && state->speed > state->max_speed) + state->max_speed = state->speed; + + if (state->height > state->max_height) + state->max_height = state->height; + state->gps.gps_locked = data->gps.gps_locked; + state->gps.gps_connected = data->gps.gps_connected; + if (data->gps.gps_locked) { + state->gps = data->gps; + state->gps_valid = 1; + if (state->npad) + aoview_great_circle(state->pad_lat, state->pad_lon, state->gps.lat, state->gps.lon, + &state->distance, &state->bearing); + } + if (data->gps_tracking.channels) + state->gps_tracking = data->gps_tracking; + if (state->npad) { + state->gps_height = state->gps.alt - state->pad_alt; + } else { + state->gps_height = 0; + } +} + +void +aoview_speak_state(struct aostate *state) +{ + if (strcmp(state->data.state, state->prev_data.state)) { + aoview_voice_speak("%s\n", state->data.state); + if (!strcmp(state->data.state, "drogue")) + aoview_voice_speak("apogee %d meters\n", + (int) state->max_height); + if (!strcmp(state->prev_data.state, "boost")) + aoview_voice_speak("max speed %d meters per second\n", + (int) state->max_speed); + } + if (state->prev_npad < MIN_PAD_SAMPLES && state->npad >= MIN_PAD_SAMPLES) + aoview_voice_speak("g p s ready\n"); +} + +void +aoview_speak_height(struct aostate *state) +{ + aoview_voice_speak("%d meters\n", state->height); +} + +struct aostate aostate; + +static guint aostate_timeout; + +#define COMPASS_LIMIT(n) ((n * 22.5) + 22.5/2) + +static char *compass_points[] = { + "north", + "north north east", + "north east", + "east north east", + "east", + "east south east", + "south east", + "south south east", + "south", + "south south west", + "south west", + "west south west", + "west", + "west north west", + "north west", + "north north west", +}; + +static char * +aoview_compass_point(double bearing) +{ + int i; + while (bearing < 0) + bearing += 360.0; + while (bearing >= 360.0) + bearing -= 360.0; + + i = floor ((bearing - 22.5/2) / 22.5 + 0.5); + if (i < 0) i = 0; + if (i >= sizeof (compass_points) / sizeof (compass_points[0])) + i = 0; + return compass_points[i]; +} + +static gboolean +aoview_state_timeout(gpointer data) +{ + double now = aoview_time(); + + if (strlen(aostate.data.state) > 0 && strcmp(aostate.data.state, "pad") != 0) + aoview_speak_height(&aostate); + if (now - aostate.report_time >= 20 || !strcmp(aostate.data.state, "landed")) { + if (!aostate.ascent) { + if (fabs(aostate.baro_speed) < 20 && aostate.height < 100) + aoview_voice_speak("rocket landed safely\n"); + else + aoview_voice_speak("rocket may have crashed\n"); + if (aostate.gps_valid) { + aoview_voice_speak("rocket reported %s of pad distance %d meters\n", + aoview_compass_point(aostate.bearing), + (int) aostate.distance); + } + } + aostate_timeout = 0; + return FALSE; + } + return TRUE; +} + +void +aoview_state_reset(void) +{ + memset(&aostate, '\0', sizeof (aostate)); +} + +void +aoview_state_notify(struct aodata *data) +{ + struct aostate *state = &aostate; + aoview_state_derive(data, state); + aoview_table_start(); + + if (state->npad >= MIN_PAD_SAMPLES) + aoview_table_add_row(0, "Ground state", "ready"); + else + aoview_table_add_row(0, "Ground state", "waiting for gps (%d)", + MIN_PAD_SAMPLES - state->npad); + aoview_table_add_row(0, "Rocket state", "%s", state->data.state); + aoview_table_add_row(0, "Callsign", "%s", state->data.callsign); + aoview_table_add_row(0, "Rocket serial", "%d", state->data.serial); + + aoview_table_add_row(0, "RSSI", "%6ddBm", state->data.rssi); + aoview_table_add_row(0, "Height", "%6dm", state->height); + aoview_table_add_row(0, "Max height", "%6dm", state->max_height); + aoview_table_add_row(0, "Acceleration", "%7.1fm/s²", state->acceleration); + aoview_table_add_row(0, "Max acceleration", "%7.1fm/s²", state->max_acceleration); + aoview_table_add_row(0, "Speed", "%7.1fm/s", state->ascent ? state->speed : state->baro_speed); + aoview_table_add_row(0, "Max Speed", "%7.1fm/s", state->max_speed); + aoview_table_add_row(0, "Temperature", "%6.2f°C", state->temperature); + aoview_table_add_row(0, "Battery", "%5.2fV", state->battery); + aoview_table_add_row(0, "Drogue", "%5.2fV", state->drogue_sense); + aoview_table_add_row(0, "Main", "%5.2fV", state->main_sense); + aoview_table_add_row(0, "Pad altitude", "%dm", state->ground_altitude); + aoview_table_add_row(1, "Satellites", "%d", state->gps.nsat); + if (state->gps.gps_locked) { + aoview_table_add_row(1, "GPS", "locked"); + } else if (state->gps.gps_connected) { + aoview_table_add_row(1, "GPS", "unlocked"); + } else { + aoview_table_add_row(1, "GPS", "not available"); + } + if (state->gps_valid) { + aoview_state_add_deg(1, "Latitude", state->gps.lat, 'N', 'S'); + aoview_state_add_deg(1, "Longitude", state->gps.lon, 'E', 'W'); + aoview_table_add_row(1, "GPS altitude", "%d", state->gps.alt); + aoview_table_add_row(1, "GPS height", "%d", state->gps_height); + aoview_table_add_row(1, "GPS time", "%02d:%02d:%02d", + state->gps.gps_time.hour, + state->gps.gps_time.minute, + state->gps.gps_time.second); + } + if (state->gps.gps_extended) { + aoview_table_add_row(1, "GPS ground speed", "%7.1fm/s %d°", + state->gps.ground_speed, + state->gps.course); + aoview_table_add_row(1, "GPS climb rate", "%7.1fm/s", + state->gps.climb_rate); + aoview_table_add_row(1, "GPS precision", "%4.1f(hdop) %3dm(h) %3dm(v)", + state->gps.hdop, state->gps.h_error, state->gps.v_error); + } + if (state->npad) { + aoview_table_add_row(1, "Distance from pad", "%5.0fm", state->distance); + aoview_table_add_row(1, "Direction from pad", "%4.0f°", state->bearing); + aoview_state_add_deg(1, "Pad latitude", state->pad_lat, 'N', 'S'); + aoview_state_add_deg(1, "Pad longitude", state->pad_lon, 'E', 'W'); + aoview_table_add_row(1, "Pad GPS alt", "%gm", state->pad_alt); + } + if (state->gps.gps_connected) { + int nsat_vis = 0; + int nsat_locked = 0; + int c; + + for (c = 0; c < state->gps_tracking.channels; c++) { + if ((state->gps_tracking.sats[c].state & 0xff) == 0xbf) + nsat_locked++; + } + aoview_table_add_row(2, "Satellites Visible", "%d", state->gps_tracking.channels); + aoview_table_add_row(2, "Satellites Locked", "%d", nsat_locked); + for (c = 0; c < state->gps_tracking.channels; c++) { + aoview_table_add_row(2, "Satellite id,state,C/N0", + "%3d,%02x,%2d%s", + state->gps_tracking.sats[c].svid, + state->gps_tracking.sats[c].state, + state->gps_tracking.sats[c].c_n0, + (state->gps_tracking.sats[c].state & 0xff) == 0xbf ? + " LOCKED" : ""); + } + } + aoview_table_finish(); + aoview_label_show(state); + aoview_speak_state(state); + if (!aostate_timeout && strcmp(state->data.state, "pad") != 0) + aostate_timeout = g_timeout_add_seconds(10, aoview_state_timeout, NULL); +} + +void +aoview_state_new(void) +{ +} + +void +aoview_state_init(GladeXML *xml) +{ + aoview_state_new(); +} diff --git a/ao-tools/ao-view/aoview_table.c b/ao-tools/ao-view/aoview_table.c new file mode 100644 index 00000000..e75ae670 --- /dev/null +++ b/ao-tools/ao-view/aoview_table.c @@ -0,0 +1,83 @@ +/* + * 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; 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 "aoview.h" + +#define NCOL 3 + +static GtkTreeView *dataview[NCOL]; +static GtkListStore *datalist[NCOL]; + +void +aoview_table_start(void) +{ + int col; + for (col = 0; col < NCOL; col++) + datalist[col] = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); +} + +void +aoview_table_add_row(int col, char *label, char *format, ...) +{ + char buf[1024]; + va_list ap; + GtkTreeIter iter; + + va_start(ap, format); + vsnprintf(buf, sizeof (buf), format, ap); + va_end(ap); + gtk_list_store_append(datalist[col], &iter); + gtk_list_store_set(datalist[col], &iter, + 0, label, + 1, buf, + -1); +} + +void +aoview_table_finish(void) +{ + int col; + for (col = 0; col < NCOL; col++) { + gtk_tree_view_set_model(dataview[col], GTK_TREE_MODEL(datalist[col])); + g_object_unref(G_OBJECT(datalist[col])); + gtk_tree_view_columns_autosize(dataview[col]); + } +} + +void +aoview_table_clear(void) +{ + int col; + for (col = 0; col < NCOL; col++) + gtk_tree_view_set_model(dataview[col], NULL); +} + +void +aoview_table_init(GladeXML *xml) +{ + int col; + + for (col = 0; col < NCOL; col++) { + char name[32]; + sprintf(name, "dataview_%d", col); + dataview[col] = GTK_TREE_VIEW(glade_xml_get_widget(xml, name)); + assert(dataview[col]); + + aoview_add_plain_text_column(dataview[col], "Field", 0, 20); + aoview_add_plain_text_column(dataview[col], "Value", 1, 32); + } +} diff --git a/ao-tools/ao-view/aoview_util.c b/ao-tools/ao-view/aoview_util.c new file mode 100644 index 00000000..6ea62ac9 --- /dev/null +++ b/ao-tools/ao-view/aoview_util.c @@ -0,0 +1,91 @@ +/* + * 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; 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 "aoview.h" + +char * +aoview_fullname (char *dir, char *file) +{ + char *new; + int dlen = strlen (dir); + int flen = strlen (file); + int slen = 0; + + if (dir[dlen-1] != '/') + slen = 1; + new = malloc (dlen + slen + flen + 1); + if (!new) + return 0; + strcpy(new, dir); + if (slen) + strcat (new, "/"); + strcat(new, file); + return new; +} + +char * +aoview_basename(char *file) +{ + char *b; + + b = strrchr(file, '/'); + if (!b) + return file; + return b + 1; +} + +int +aoview_mkdir(char *dir) +{ + char *slash; + char *d; + char *part; + + d = dir; + for (;;) { + slash = strchr (d, '/'); + if (!slash) + slash = d + strlen(d); + if (!*slash) + break; + part = strndup(dir, slash - dir); + if (!access(part, F_OK)) + if (mkdir(part, 0777) < 0) + return -errno; + free(part); + d = slash + 1; + } + return 0; +} + +GtkTreeViewColumn * +aoview_add_plain_text_column (GtkTreeView *view, const gchar *title, gint model_column, gint width) +{ + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + + renderer = gtk_cell_renderer_text_new (); + g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL); + g_object_set(renderer, "width-chars", width, NULL); + column = gtk_tree_view_column_new_with_attributes (title, renderer, + "text", model_column, + NULL); + gtk_tree_view_column_set_resizable (column, FALSE); + gtk_tree_view_append_column (view, column); + + return column; +} diff --git a/ao-tools/ao-view/aoview_voice.c b/ao-tools/ao-view/aoview_voice.c new file mode 100644 index 00000000..24422df6 --- /dev/null +++ b/ao-tools/ao-view/aoview_voice.c @@ -0,0 +1,122 @@ +/* + * 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; 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 "aoview.h" + +#if HAVE_FLITE +#include + +FILE *aoview_flite; + +void aoview_voice_open(void) +{ + int err; + + if (!aoview_flite) + aoview_flite = aoview_flite_start(); +} + +void aoview_voice_close(void) +{ + if (aoview_flite) { + aoview_flite_stop(); + aoview_flite = NULL; + } +} + +void aoview_voice_speak(char *format, ...) +{ + va_list ap; + + if (aoview_flite) { + va_start(ap, format); + vfprintf(aoview_flite, format, ap); + fflush(aoview_flite); + va_end(ap); + } +} + +#else +void aoview_voice_open(void) +{ +} + +void aoview_voice_close(void) +{ +} + +void aoview_voice_speak(char *format, ...) +{ +} +#endif + + +static GtkCheckMenuItem *voice_enable; + +#define ALTOS_VOICE_PATH "/apps/aoview/voice" + +static void +aoview_voice_enable(GtkWidget *widget, gpointer data) +{ + gboolean enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); + GError *error; + GConfClient *gconf_client; + + if (enabled) { + aoview_voice_open(); + aoview_voice_speak("enable voice\n"); + } else { + aoview_voice_speak("disable voice\n"); + aoview_voice_close(); + } + gconf_client = gconf_client_get_default(); + gconf_client_set_bool(gconf_client, + ALTOS_VOICE_PATH, + enabled, + &error); +} + +void +aoview_voice_init(GladeXML *xml) +{ + gboolean enabled; + GConfClient *gconf_client; + + voice_enable = GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "voice_enable")); + assert(voice_enable); + + gconf_client = gconf_client_get_default(); + enabled = TRUE; + if (gconf_client) + { + GError *error; + + error = NULL; + enabled = gconf_client_get_bool(gconf_client, + ALTOS_VOICE_PATH, + &error); + if (error) + enabled = TRUE; + } + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(voice_enable), enabled); + if (enabled) + aoview_voice_open(); + + g_signal_connect(G_OBJECT(voice_enable), "toggled", + G_CALLBACK(aoview_voice_enable), + voice_enable); +} diff --git a/ao-tools/ao-view/design b/ao-tools/ao-view/design new file mode 100644 index 00000000..6ec2ea70 --- /dev/null +++ b/ao-tools/ao-view/design @@ -0,0 +1,27 @@ +Requirements: + real-time display of telemetry + off-line display of logged data + Logging of telemetry + Capture of logged data to disk + +Input data: + accelerometer + barometer + thermometer + gps + drogue and main continuity + battery voltage + time + reported flight state + reported events + +Computed data: + velocity (from accelerometer) + altitude + range + direction + +Displays: + numeric display of current rocket status + (graphics come later) + text message log diff --git a/ao-tools/lib/Makefile.am b/ao-tools/lib/Makefile.am index 9584e216..f66ee0a9 100644 --- a/ao-tools/lib/Makefile.am +++ b/ao-tools/lib/Makefile.am @@ -16,6 +16,9 @@ libao_tools_a_SOURCES = \ ccdbg-state.c \ cc-usb.c \ cc-usb.h \ + cc.h \ + cc-usbdev.c \ + cc-util.c \ cc-bitbang.c \ cc-bitbang.h \ cp-usb-async.c \ diff --git a/ao-tools/lib/cc-usbdev.c b/ao-tools/lib/cc-usbdev.c new file mode 100644 index 00000000..d8bb8b11 --- /dev/null +++ b/ao-tools/lib/cc-usbdev.c @@ -0,0 +1,228 @@ +/* + * 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. + */ + +#include "cc.h" + +#include +#include +#include +#include +#include + +static char * +load_string(char *dir, char *file) +{ + char *full = cc_fullname(dir, file); + char line[4096]; + char *r; + FILE *f; + int rlen; + + f = fopen(full, "r"); + free(full); + if (!f) + return NULL; + r = fgets(line, sizeof (line), f); + fclose(f); + if (!r) + return NULL; + rlen = strlen(r); + if (r[rlen-1] == '\n') + r[rlen-1] = '\0'; + return strdup(r); +} + +static int +load_hex(char *dir, char *file) +{ + char *line; + char *end; + long i; + + line = load_string(dir, file); + if (!line) + return -1; + i = strtol(line, &end, 16); + free(line); + if (end == line) + return -1; + return i; +} + +static int +dir_filter_tty_colon(const struct dirent *d) +{ + return strncmp(d->d_name, "tty:", 4) == 0; +} + +static int +dir_filter_tty(const struct dirent *d) +{ + return strncmp(d->d_name, "tty", 3) == 0; +} + +static char * +usb_tty(char *sys) +{ + char *base; + int num_configs; + int config; + struct dirent **namelist; + int interface; + int num_interfaces; + char endpoint_base[20]; + char *endpoint_full; + char *tty_dir; + int ntty; + char *tty; + + base = cc_basename(sys); + num_configs = load_hex(sys, "bNumConfigurations"); + num_interfaces = load_hex(sys, "bNumInterfaces"); + for (config = 1; config <= num_configs; config++) { + for (interface = 0; interface < num_interfaces; interface++) { + sprintf(endpoint_base, "%s:%d.%d", + base, config, interface); + endpoint_full = cc_fullname(sys, endpoint_base); + + /* Check for tty:ttyACMx style names + */ + ntty = scandir(endpoint_full, &namelist, + dir_filter_tty_colon, + alphasort); + if (ntty > 0) { + free(endpoint_full); + tty = cc_fullname("/dev", namelist[0]->d_name + 4); + free(namelist); + return tty; + } + + /* Check for tty/ttyACMx style names + */ + tty_dir = cc_fullname(endpoint_full, "tty"); + free(endpoint_full); + ntty = scandir(tty_dir, &namelist, + dir_filter_tty, + alphasort); + free (tty_dir); + if (ntty > 0) { + tty = cc_fullname("/dev", namelist[0]->d_name); + free(namelist); + return tty; + } + } + } + return NULL; +} + +static struct cc_usbdev * +usb_scan_device(char *sys) +{ + struct cc_usbdev *usbdev; + + usbdev = calloc(1, sizeof (struct cc_usbdev)); + if (!usbdev) + return NULL; + usbdev->sys = strdup(sys); + usbdev->manufacturer = load_string(sys, "manufacturer"); + usbdev->product = load_string(sys, "product"); + usbdev->serial = load_string(sys, "serial"); + usbdev->idProduct = load_hex(sys, "idProduct"); + usbdev->idVendor = load_hex(sys, "idVendor"); + usbdev->tty = usb_tty(sys); + return usbdev; +} + +static void +usbdev_free(struct cc_usbdev *usbdev) +{ + free(usbdev->sys); + free(usbdev->manufacturer); + free(usbdev->product); + free(usbdev->serial); + free(usbdev->tty); + free(usbdev); +} + +#define USB_DEVICES "/sys/bus/usb/devices" + +static int +dir_filter_dev(const struct dirent *d) +{ + const char *n = d->d_name; + char c; + + while ((c = *n++)) { + if (isdigit(c)) + continue; + if (c == '-') + continue; + if (c == '.' && n != d->d_name + 1) + continue; + return 0; + } + return 1; +} + +struct cc_usbdevs * +cc_usbdevs_scan(void) +{ + int e; + struct dirent **ents; + char *dir; + struct cc_usbdev *dev; + struct cc_usbdevs *devs; + int n; + + devs = calloc(1, sizeof (struct cc_usbdevs)); + if (!devs) + return NULL; + + n = scandir (USB_DEVICES, &ents, + dir_filter_dev, + alphasort); + if (!n) + return 0; + for (e = 0; e < n; e++) { + dir = cc_fullname(USB_DEVICES, ents[e]->d_name); + dev = usb_scan_device(dir); + free(dir); + if (dev->idVendor == 0xfffe && dev->tty) { + if (devs->dev) + devs->dev = realloc(devs->dev, + devs->ndev + 1 * sizeof (struct usbdev *)); + else + devs->dev = malloc (sizeof (struct usbdev *)); + devs->dev[devs->ndev++] = dev; + } + } + free(ents); + return devs; +} + +void +cc_usbdevs_free(struct cc_usbdevs *usbdevs) +{ + int i; + + if (!usbdevs) + return; + for (i = 0; i < usbdevs->ndev; i++) + usbdev_free(usbdevs->dev[i]); + free(usbdevs); +} diff --git a/ao-tools/lib/cc-util.c b/ao-tools/lib/cc-util.c new file mode 100644 index 00000000..7104470c --- /dev/null +++ b/ao-tools/lib/cc-util.c @@ -0,0 +1,80 @@ +/* + * 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; 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 "cc.h" +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +char * +cc_fullname (char *dir, char *file) +{ + char *new; + int dlen = strlen (dir); + int flen = strlen (file); + int slen = 0; + + if (dir[dlen-1] != '/') + slen = 1; + new = malloc (dlen + slen + flen + 1); + if (!new) + return 0; + strcpy(new, dir); + if (slen) + strcat (new, "/"); + strcat(new, file); + return new; +} + +char * +cc_basename(char *file) +{ + char *b; + + b = strrchr(file, '/'); + if (!b) + return file; + return b + 1; +} + +int +cc_mkdir(char *dir) +{ + char *slash; + char *d; + char *part; + + d = dir; + for (;;) { + slash = strchr (d, '/'); + if (!slash) + slash = d + strlen(d); + if (!*slash) + break; + part = strndup(dir, slash - dir); + if (!access(part, F_OK)) + if (mkdir(part, 0777) < 0) + return -errno; + free(part); + d = slash + 1; + } + return 0; +} diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h new file mode 100644 index 00000000..dad11bf3 --- /dev/null +++ b/ao-tools/lib/cc.h @@ -0,0 +1,51 @@ +/* + * 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; 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 _CC_H_ +#define _CC_H_ + +char * +cc_fullname (char *dir, char *file); + +char * +cc_basename(char *file); + +int +cc_mkdir(char *dir); + +struct cc_usbdev { + char *sys; + char *tty; + char *manufacturer; + char *product; + char *serial; + int idProduct; + int idVendor; +}; + +struct cc_usbdevs { + struct cc_usbdev **dev; + int ndev; +}; + +void +cc_usbdevs_free(struct cc_usbdevs *usbdevs); + +struct cc_usbdevs * +cc_usbdevs_scan(void); + +#endif /* _CC_H_ */ diff --git a/ao-view/.gitignore b/ao-view/.gitignore deleted file mode 100644 index 24fbc596..00000000 --- a/ao-view/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.o -aoview -aoview_glade.h -aoview_flite diff --git a/ao-view/Makefile.am b/ao-view/Makefile.am deleted file mode 100644 index 17661c8e..00000000 --- a/ao-view/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -VERSION=$(shell git describe) - -AM_CFLAGS=$(GNOME_CFLAGS) $(ALSA_CFLAGS) -I$(top_srcdir)/src -DAOVIEW_VERSION=\"$(VERSION)\" @FLITE_INCS@ - -bin_PROGRAMS=ao-view - -ao_view_LDADD=$(GNOME_LIBS) $(FLITE_LIBS) $(ALSA_LIBS) - -ao_view_SOURCES = \ - aoview_main.c \ - aoview_dev.c \ - aoview_dev_dialog.c \ - aoview_serial.c \ - aoview_monitor.c \ - aoview_state.c \ - aoview_convert.c \ - aoview_log.c \ - aoview_table.c \ - aoview_util.c \ - aoview_file.c \ - aoview_eeprom.c \ - aoview_voice.c \ - aoview_replay.c \ - aoview_label.c \ - aoview_flite.c \ - aoview.h - -BUILT_SOURCES = aoview_glade.h - -CLEANFILES = aoview_glade.h - -man_MANS=ao-view.1 - -aoview_glade.h: aoview.glade - sed -e 's/"/\\"/g' -e 's/^/"/' -e 's/$$/"/' $< > $@ diff --git a/ao-view/ao-view.1 b/ao-view/ao-view.1 deleted file mode 100644 index 99834c4e..00000000 --- a/ao-view/ao-view.1 +++ /dev/null @@ -1,50 +0,0 @@ -.\" -.\" 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-VIEW 1 "ao-view" "" -.SH NAME -ao-view \- Rocket flight monitor -.SH SYNOPSIS -.B "ao-view" -[\--tty \fItty-device\fP] -.SH DESCRIPTION -.I ao-view -connects to a TeleDongle or TeleMetrum device through a USB serial device. -It provides a user interface to monitor, record and review rocket flight data. -.SH OPTIONS -The usual Gtk+ command line options can be used, along with -.IP "\--tty" -This selects a target device to connect at startup time to. -The target device may also be selected through the user interface. -.SH USAGE -When connected to a TeleDongle device, ao-view turns on the radio -receiver and listens for telemetry packets. It displays the received -telemetry data, and reports flight status via voice synthesis. All -received telemetry information is recorded to a file. -.P -When connected to a TeleMetrum device, ao-view downloads the eeprom -data and stores it in a file. -.SH FILES -All data log files are recorded into a user-specified directory -(default ~/AltOS). Files are named using the current date, the serial -number of the reporting device, the flight number recorded in the data -and either '.telem' for telemetry data or '.eeprom' for eeprom data. -.SH "SEE ALSO" -ao-load(1), ao-eeprom(1) -.SH AUTHOR -Keith Packard diff --git a/ao-view/aoview.glade b/ao-view/aoview.glade deleted file mode 100644 index 9a746110..00000000 --- a/ao-view/aoview.glade +++ /dev/null @@ -1,744 +0,0 @@ - - - - - - 900 - 700 - True - AltOS View - - - True - vertical - - - True - - - True - _File - True - - - True - - - gtk-new - True - True - True - - - - - gtk-open - True - True - True - - - - - gtk-save - True - True - True - - - - - gtk-save-as - True - True - True - - - - - True - - - - - gtk-quit - True - True - True - - - - - - - - - - True - _Edit - True - - - True - - - gtk-cut - True - True - True - - - - - gtk-copy - True - True - True - - - - - gtk-paste - True - True - True - - - - - gtk-delete - True - True - True - - - - - - - - - True - _Device - True - - - True - - - _Connect to device - True - True - False - - - - - True - gtk-connect - - - - - - - _Disconnect - True - True - False - - - True - gtk-disconnect - - - - - - - True - False - - - - - _Save EEPROM data - True - True - False - - - - - True - gtk-save - - - - - - - _Replay - True - True - False - - - - - True - gtk-media-play - - - - - - - - - - - True - _Log - True - - - True - - - _New log - True - True - False - - - True - gtk-new - - - - - - - _Configure Log - True - True - False - - - - True - gtk-preferences - - - - - - - - - - - True - _Voice - True - - - True - - - True - Enable _Voice - True - True - - - - - - - - - True - _Help - True - - - True - - - gtk-about - True - True - True - - - - - - - - - - False - 0 - - - - - True - 2 - 4 - 3 - True - - - True - Height (m) - center - - - - - True - State - - - 1 - 2 - - - - - True - RSSI (dBm) - - - 2 - 3 - - - - - True - 2 - 0 - True - - - 1 - 2 - - - - - True - 2 - pad - True - - - 1 - 2 - 1 - 2 - - - - - True - 2 - -50 - True - - - 2 - 3 - 1 - 2 - - - - - True - Speed (m/s) - - - 3 - 4 - - - - - True - 0 - True - - - 3 - 4 - 1 - 2 - - - - - False - 1 - - - - - True - - - True - True - False - both - - - 0 - - - - - True - True - False - both - - - 1 - - - - - True - True - False - both - - - 2 - - - - - 2 - - - - - - - 5 - normal - False - - - True - vertical - 2 - - - 300 - 100 - True - True - False - True - 0 - False - 1 - both - True - - - 1 - - - - - True - end - - - gtk-cancel - 1 - True - True - True - True - True - - - - False - False - 0 - - - - - gtk-connect - True - True - True - True - True - True - - - False - False - 1 - - - - - False - end - 0 - - - - - - - 5 - Configure Log Directory - dialog - False - select-folder - - - True - vertical - 2 - - - True - end - - - gtk-cancel - True - True - True - True - - - - False - False - 0 - - - - - gtk-ok - True - True - True - True - True - True - - - False - False - 1 - - - - - False - end - 0 - - - - - - - 5 - Failed to create log - normal - True - aoview - error - close - Cannot create log file - - - True - vertical - 2 - - - True - end - - - False - end - 0 - - - - - - - 5 - Failed to open device - normal - True - aoview - error - close - Cannot open device - - - True - vertical - 2 - - - True - end - - - False - end - 0 - - - - - - - 5 - About AoView - False - normal - aoview - False - AoView - Copyright © 2009 Keith Packard - AltOS data capture and display. - http://altusmetrum.org - AoView 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. - -AoView 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 AoView; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Keith Packard <keithp@keithp.com> - True - - - - - True - vertical - 2 - - - True - end - - - False - end - 0 - - - - - - - 5 - EEPROM save complete - normal - True - aoview - close - Saving EEPROM data as - <filename> - - - - - True - vertical - 2 - - - True - end - - - False - end - 0 - - - - - - - 5 - True - dialog - True - aoview - False - - - True - vertical - 2 - - - True - end - - - gtk-cancel - True - True - True - True - - - - False - False - 0 - - - - - gtk-ok - True - True - True - True - - - False - False - 1 - - - - - False - end - 0 - - - - - - diff --git a/ao-view/aoview.h b/ao-view/aoview.h deleted file mode 100644 index 9ca65298..00000000 --- a/ao-view/aoview.h +++ /dev/null @@ -1,337 +0,0 @@ -/* - * 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; 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 _AOVIEW_H_ -#define _AOVIEW_H_ - -#define _GNU_SOURCE - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -struct usbdev { - char *sys; - char *tty; - char *manufacturer; - char *product; - char *serial; - int idProduct; - int idVendor; -}; - -struct aogps_time { - int hour; - int minute; - int second; -}; - -struct aogps { - int nsat; - int gps_locked; - int gps_connected; - struct aogps_time gps_time; - double lat; /* degrees (+N -S) */ - double lon; /* degrees (+E -W) */ - int alt; /* m */ - - int gps_extended; /* has extra data */ - double ground_speed; /* m/s */ - int course; /* degrees */ - double climb_rate; /* m/s */ - double hdop; /* unitless? */ - int h_error; /* m */ - int v_error; /* m */ -}; - -#define SIRF_SAT_STATE_ACQUIRED (1 << 0) -#define SIRF_SAT_STATE_CARRIER_PHASE_VALID (1 << 1) -#define SIRF_SAT_BIT_SYNC_COMPLETE (1 << 2) -#define SIRF_SAT_SUBFRAME_SYNC_COMPLETE (1 << 3) -#define SIRF_SAT_CARRIER_PULLIN_COMPLETE (1 << 4) -#define SIRF_SAT_CODE_LOCKED (1 << 5) -#define SIRF_SAT_ACQUISITION_FAILED (1 << 6) -#define SIRF_SAT_EPHEMERIS_AVAILABLE (1 << 7) - -struct aogps_sat { - int svid; - int state; - int c_n0; -}; - -struct aogps_tracking { - int channels; - struct aogps_sat sats[12]; -}; - -struct aodata { - char callsign[16]; - int serial; - int rssi; - char state[16]; - int tick; - int accel; - int pres; - int temp; - int batt; - int drogue; - int main; - int flight_accel; - int ground_accel; - int flight_vel; - int flight_pres; - int ground_pres; - struct aogps gps; - struct aogps_tracking gps_tracking; -}; - -struct aostate { - struct aodata data; - - /* derived data */ - - struct aodata prev_data; - - double report_time; - - gboolean ascent; /* going up? */ - - int ground_altitude; - int height; - double speed; - double acceleration; - double battery; - double temperature; - double main_sense; - double drogue_sense; - double baro_speed; - - int max_height; - double max_acceleration; - double max_speed; - - struct aogps gps; - struct aogps_tracking gps_tracking; - - int gps_valid; - double pad_lat; - double pad_lon; - double pad_alt; - double pad_lat_total; - double pad_lon_total; - double pad_alt_total; - int npad; - int prev_npad; - - double distance; - double bearing; - int gps_height; - - int speak_tick; - int speak_altitude; -}; - -extern struct aostate aostate; - -/* GPS is 'stable' when we've seen at least this many samples */ -#define MIN_PAD_SAMPLES 10 - -void -aoview_monitor_disconnect(void); - -gboolean -aoview_monitor_connect(char *tty); - -gboolean -aoview_monitor_parse(const char *line); - -void -aoview_monitor_reset(void); - -struct aoview_serial * -aoview_serial_open(const char *tty); - -void -aoview_serial_close(struct aoview_serial *serial); - -typedef void (*aoview_serial_callback)(gpointer user_data, struct aoview_serial *serial, gint revents); - -void -aoview_serial_set_callback(struct aoview_serial *serial, - aoview_serial_callback func); - -void -aoview_serial_printf(struct aoview_serial *serial, char *format, ...); - -int -aoview_serial_read(struct aoview_serial *serial, char *buf, int len); - -int -aoview_serial_getc(struct aoview_serial *serial); - -void -aoview_dev_dialog_init(GladeXML *xml); - -int -aoview_usb_scan(struct usbdev ***devs_ret); - -void -aoview_usbdev_free(struct usbdev *usbdev); - -void -aoview_state_notify(struct aodata *data); - -void -aoview_state_new(void); - -void -aoview_state_init(GladeXML *xml); - -int16_t -aoview_pres_to_altitude(int16_t pres); - -int16_t -aoview_altitude_to_pres(int16_t alt); - -char * -aoview_fullname (char *dir, char *file); - -char * -aoview_basename(char *file); - -GtkTreeViewColumn * -aoview_add_plain_text_column (GtkTreeView *view, const gchar *title, gint model_column, gint width); - -int -aoview_mkdir(char *dir); - -void -aoview_log_init(GladeXML *xml); - -void -aoview_log_set_serial(int serial); - -int -aoview_log_get_serial(void); - -void -aoview_log_printf(char *format, ...); - -void -aoview_log_new(void); - -void -aoview_table_start(void); - -void -aoview_table_add_row(int column, char *label, char *format, ...); - -void -aoview_table_finish(void); - -void -aoview_table_init(GladeXML *xml); - -void -aoview_table_clear(void); - -struct aoview_file; - -extern char *aoview_file_dir; - -void -aoview_file_finish(struct aoview_file *file); - -gboolean -aoview_file_start(struct aoview_file *file); - -const char * -aoview_file_name(struct aoview_file *file); - -void -aoview_file_set_serial(struct aoview_file *file, int serial); - -int -aoview_file_get_serial(struct aoview_file *file); - -void -aoview_file_printf(struct aoview_file *file, char *format, ...); - -void -aoview_file_vprintf(struct aoview_file *file, char *format, va_list ap); - -struct aoview_file * -aoview_file_new(char *ext); - -void -aoview_file_destroy(struct aoview_file *file); - -void -aoview_file_init(GladeXML *xml); - -/* aoview_eeprom.c */ - -gboolean -aoview_eeprom_save(const char *device); - -void -aoview_eeprom_init(GladeXML *xml); - -/* aoview_voice.c */ -void aoview_voice_open(void); - -void aoview_voice_close(void); - -void aoview_voice_speak(char *format, ...); - -/* aoview_label.c */ - -void aoview_label_init(GladeXML *xml); - -void -aoview_label_show(struct aostate *state); - -/* aoview_flite.c */ - -FILE * -aoview_flite_start(void); - -void -aoview_flite_stop(void); - -/* aoview_main.c */ - -extern char *aoview_tty; - -#endif /* _AOVIEW_H_ */ diff --git a/ao-view/aoview_convert.c b/ao-view/aoview_convert.c deleted file mode 100644 index 02416647..00000000 --- a/ao-view/aoview_convert.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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; 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 "aoview.h" - -static int16_t altitude_table[2048] = { -#include "altitude.h" -}; - -int16_t -aoview_pres_to_altitude(int16_t pres) -{ - pres = pres >> 4; - if (pres < 0) pres = 0; - if (pres > 2047) pres = 2047; - return altitude_table[pres]; -} - -int16_t -aoview_altitude_to_pres(int16_t alt) -{ - int16_t pres; - - for (pres = 0; pres < 2047; pres++) - if (altitude_table[pres] <= alt) - break; - return pres << 4; -} diff --git a/ao-view/aoview_dev.c b/ao-view/aoview_dev.c deleted file mode 100644 index 9b8cc19e..00000000 --- a/ao-view/aoview_dev.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * 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; 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 "aoview.h" -#include -#include - -static char * -load_string(char *dir, char *file) -{ - char *full = aoview_fullname(dir, file); - char line[4096]; - char *r; - FILE *f; - int rlen; - - f = fopen(full, "r"); - free(full); - if (!f) - return NULL; - r = fgets(line, sizeof (line), f); - fclose(f); - if (!r) - return NULL; - rlen = strlen(r); - if (r[rlen-1] == '\n') - r[rlen-1] = '\0'; - return strdup(r); -} - -static int -load_hex(char *dir, char *file) -{ - char *line; - char *end; - long i; - - line = load_string(dir, file); - if (!line) - return -1; - i = strtol(line, &end, 16); - free(line); - if (end == line) - return -1; - return i; -} - -static int -dir_filter_tty_colon(const struct dirent *d) -{ - return strncmp(d->d_name, "tty:", 4) == 0; -} - -static int -dir_filter_tty(const struct dirent *d) -{ - return strncmp(d->d_name, "tty", 3) == 0; -} - -static char * -usb_tty(char *sys) -{ - char *base; - int num_configs; - int config; - struct dirent **namelist; - int interface; - int num_interfaces; - char endpoint_base[20]; - char *endpoint_full; - char *tty_dir; - int ntty; - char *tty; - - base = aoview_basename(sys); - num_configs = load_hex(sys, "bNumConfigurations"); - num_interfaces = load_hex(sys, "bNumInterfaces"); - for (config = 1; config <= num_configs; config++) { - for (interface = 0; interface < num_interfaces; interface++) { - sprintf(endpoint_base, "%s:%d.%d", - base, config, interface); - endpoint_full = aoview_fullname(sys, endpoint_base); - - /* Check for tty:ttyACMx style names - */ - ntty = scandir(endpoint_full, &namelist, - dir_filter_tty_colon, - alphasort); - if (ntty > 0) { - free(endpoint_full); - tty = aoview_fullname("/dev", namelist[0]->d_name + 4); - free(namelist); - return tty; - } - - /* Check for tty/ttyACMx style names - */ - tty_dir = aoview_fullname(endpoint_full, "tty"); - free(endpoint_full); - ntty = scandir(tty_dir, &namelist, - dir_filter_tty, - alphasort); - free (tty_dir); - if (ntty > 0) { - tty = aoview_fullname("/dev", namelist[0]->d_name); - free(namelist); - return tty; - } - } - } - return NULL; -} - -static struct usbdev * -usb_scan_device(char *sys) -{ - struct usbdev *usbdev; - - usbdev = calloc(1, sizeof (struct usbdev)); - if (!usbdev) - return NULL; - usbdev->sys = strdup(sys); - usbdev->manufacturer = load_string(sys, "manufacturer"); - usbdev->product = load_string(sys, "product"); - usbdev->serial = load_string(sys, "serial"); - usbdev->idProduct = load_hex(sys, "idProduct"); - usbdev->idVendor = load_hex(sys, "idVendor"); - usbdev->tty = usb_tty(sys); - return usbdev; -} - -void -aoview_usbdev_free(struct usbdev *usbdev) -{ - free(usbdev->sys); - free(usbdev->manufacturer); - free(usbdev->product); - free(usbdev->serial); - free(usbdev->tty); - free(usbdev); -} - -#define USB_DEVICES "/sys/bus/usb/devices" - -static int -dir_filter_dev(const struct dirent *d) -{ - const char *n = d->d_name; - char c; - - while ((c = *n++)) { - if (isdigit(c)) - continue; - if (c == '-') - continue; - if (c == '.' && n != d->d_name + 1) - continue; - return 0; - } - return 1; -} - -int -aoview_usb_scan(struct usbdev ***devs_ret) -{ - int n; - int ndev = 0; - int e; - struct dirent **ents; - char *dir; - struct usbdev **devs = NULL; - struct usbdev *dev; - - n = scandir (USB_DEVICES, &ents, - dir_filter_dev, - alphasort); - if (!n) - return 0; - for (e = 0; e < n; e++) { - dir = aoview_fullname(USB_DEVICES, ents[e]->d_name); - dev = usb_scan_device(dir); - free(dir); - if (dev->idVendor == 0xfffe && dev->tty) { - if (devs) - devs = realloc(devs, ndev + 1 * sizeof (struct usbdev *)); - else - devs = malloc (sizeof (struct usbdev *)); - devs[ndev++] = dev; - } - } - free(ents); - *devs_ret = devs; - return ndev; -} diff --git a/ao-view/aoview_dev_dialog.c b/ao-view/aoview_dev_dialog.c deleted file mode 100644 index 3f92085c..00000000 --- a/ao-view/aoview_dev_dialog.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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; 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 "aoview.h" - -static void -aoview_dev_dialog_map(GtkWidget *widget, gpointer data) -{ - GtkTreeView *dev_list = data; - GtkListStore *list_store; - GtkTreeIter iter; - int ndev, n; - struct usbdev **devs; - - list_store = gtk_list_store_new(3, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING); - - ndev = aoview_usb_scan(&devs); - for (n = 0; n < ndev; n++) { - gtk_list_store_append(list_store, &iter); - gtk_list_store_set(list_store, &iter, - 0, devs[n]->product, - 1, devs[n]->serial, - 2, devs[n]->tty, - -1); - } - gtk_tree_view_set_model (dev_list, GTK_TREE_MODEL(list_store)); - g_object_unref(G_OBJECT(list_store)); - gtk_tree_view_columns_autosize(dev_list); -} - -static GtkMessageDialog *dev_open_fail_dialog; - -static void -aoview_dev_open_failed(char *name) -{ - char *utf8_file; - utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL); - if (!utf8_file) - utf8_file = name; - gtk_message_dialog_format_secondary_text(dev_open_fail_dialog, - "\"%s\"", utf8_file); - if (utf8_file != name) - g_free(utf8_file); - gtk_dialog_run(GTK_DIALOG(dev_open_fail_dialog)); - gtk_widget_hide(GTK_WIDGET(dev_open_fail_dialog)); -} - -gboolean dialog_save_log; - -static void -aoview_dev_selected(GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - gchar *string; - gtk_tree_model_get(model, iter, - 2, &string, - -1); - if (dialog_save_log) { - dialog_save_log = FALSE; - if (!aoview_eeprom_save(string)) - aoview_dev_open_failed(string); - } else { - if (!aoview_monitor_connect(string)) - aoview_dev_open_failed(string); - } -} - -static GtkWidget *dialog; - -static void -aoview_dev_dialog_connect(GtkWidget *widget, gpointer data) -{ - GtkTreeView *dev_list = data; - GtkListStore *list_store; - GtkTreeSelection *tree_selection; - - list_store = GTK_LIST_STORE(gtk_tree_view_get_model(dev_list)); - tree_selection = gtk_tree_view_get_selection(dev_list); - gtk_tree_selection_selected_foreach(tree_selection, - aoview_dev_selected, - data); - gtk_widget_hide(dialog); -} - -static void -aoview_dev_disconnect(GtkWidget *widget) -{ - aoview_monitor_disconnect(); -} - -static void -aoview_dev_savelog(GtkWidget *widget, gpointer data) -{ - dialog_save_log = TRUE; - gtk_widget_show(dialog); -} - -#define _(a) a - -void -aoview_dev_dialog_init(GladeXML *xml) -{ - GtkTreeView *dev_list; - GtkWidget *connect_button; - GtkTreeSelection *dev_selection; - GtkWidget *ao_disconnect; - GtkWidget *ao_savelog; - - dialog = glade_xml_get_widget(xml, "device_connect_dialog"); - assert(dialog); - - dev_list = GTK_TREE_VIEW(glade_xml_get_widget(xml, "dev_list")); - assert(dev_list); - - aoview_add_plain_text_column(dev_list, _("Product"), 0, 16); - aoview_add_plain_text_column(dev_list, _("Serial"), 1, 8); - aoview_add_plain_text_column(dev_list, _("Device"), 2, 13); - - dev_selection = gtk_tree_view_get_selection(dev_list); - gtk_tree_selection_set_mode(dev_selection, GTK_SELECTION_SINGLE); - - g_signal_connect(G_OBJECT(dialog), "map", - G_CALLBACK(aoview_dev_dialog_map), - dev_list); - - connect_button = glade_xml_get_widget(xml, "connect_button"); - assert(connect_button); - - g_signal_connect(G_OBJECT(connect_button), "clicked", - G_CALLBACK(aoview_dev_dialog_connect), - dev_list); - - - ao_disconnect = glade_xml_get_widget(xml, "ao_disconnect"); - assert(ao_disconnect); - - g_signal_connect(G_OBJECT(ao_disconnect), "activate", - G_CALLBACK(aoview_dev_disconnect), - ao_disconnect); - - ao_savelog = glade_xml_get_widget(xml, "ao_savelog"); - assert(ao_savelog); - - g_signal_connect(G_OBJECT(ao_savelog), "activate", - G_CALLBACK(aoview_dev_savelog), - dialog); - dev_open_fail_dialog = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "dev_open_fail_dialog")); - assert(dev_open_fail_dialog); -} diff --git a/ao-view/aoview_eeprom.c b/ao-view/aoview_eeprom.c deleted file mode 100644 index 34e2deed..00000000 --- a/ao-view/aoview_eeprom.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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; 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 "aoview.h" - -#define EEPROM_LEN 1024 - -static struct aoview_file *eeprom_file; -static char eeprom_line[EEPROM_LEN + 1]; -static int eeprom_pos; -static GtkMessageDialog *eeprom_save_done; -static GtkWidget *eeprom_save_close; -static gboolean eeprom_save_shown; - -static void -aoview_eeprom_disconnect(struct aoview_serial *serial) -{ - aoview_file_finish(eeprom_file); -} - -static void -aoview_eeprom_done(struct aoview_serial *serial) -{ - gtk_window_set_title(GTK_WINDOW(eeprom_save_done), - "EEPROM data saved"); - gtk_message_dialog_set_markup(eeprom_save_done, - "EEPROM data saved as"); - if (!eeprom_save_shown) - gtk_widget_show(GTK_WIDGET(eeprom_save_done)); - eeprom_save_close = gtk_window_get_default_widget(GTK_WINDOW(eeprom_save_done)); - if (eeprom_save_close) - gtk_widget_set_sensitive(eeprom_save_close, TRUE); - aoview_eeprom_disconnect(serial); -} - -static gboolean -aoview_eeprom_parse(struct aoview_serial *serial, - char *line) -{ - char cmd; - int tick; - int a; - int b; - int serial_number; - const char *name; - char *utf8_name; - - if (!strcmp(line, "end")) { - aoview_eeprom_done(serial); - return FALSE; - } - if (sscanf(line, "serial-number %u", &serial_number) == 1) { - aoview_file_set_serial(eeprom_file, serial_number); - } else if (sscanf(line, "%c %x %x %x", &cmd, &tick, &a, &b) == 4) { - aoview_file_printf(eeprom_file, "%s\n", line); - if (cmd == 'S' && a == 8) { - aoview_eeprom_done(serial); - return FALSE; - } - - if (!eeprom_save_shown) - { - name = aoview_file_name(eeprom_file); - if (name) { - utf8_name = g_filename_to_utf8(name, -1, NULL, NULL, NULL); - if (!utf8_name) - utf8_name = (char *) name; - gtk_widget_set_sensitive(eeprom_save_close, FALSE); - gtk_window_set_title(GTK_WINDOW(eeprom_save_done), - "Saving EEPROM data"); - gtk_message_dialog_set_markup(eeprom_save_done, - "Saving EEPROM data as"); - gtk_message_dialog_format_secondary_text(eeprom_save_done, "%s", - utf8_name); - if (utf8_name != name) - g_free(utf8_name); - gtk_container_check_resize(GTK_CONTAINER(eeprom_save_done)); - gtk_widget_show(GTK_WIDGET(eeprom_save_done)); - eeprom_save_shown = TRUE; - eeprom_save_close = gtk_window_get_default_widget(GTK_WINDOW(eeprom_save_done)); - if (eeprom_save_close) - gtk_widget_set_sensitive(eeprom_save_close, FALSE); - } - } - } - return TRUE; -} - -static void -aoview_eeprom_callback(gpointer user_data, - struct aoview_serial *serial, - gint revents) -{ - int c; - - if (revents & (G_IO_HUP|G_IO_ERR)) { - aoview_eeprom_disconnect(serial); - return; - } - if (revents & G_IO_IN) { - for (;;) { - c = aoview_serial_getc(serial); - if (c == -1) - break; - if (c == '\r') - continue; - if (c == '\n') { - eeprom_line[eeprom_pos] = '\0'; - if (eeprom_pos) - if (!aoview_eeprom_parse(serial, eeprom_line)) - break; - eeprom_pos = 0; - } else if (eeprom_pos < EEPROM_LEN) - eeprom_line[eeprom_pos++] = c; - } - } -} - -gboolean -aoview_eeprom_save(const char *device) -{ - struct aoview_serial *serial; - - gtk_widget_hide(GTK_WIDGET(eeprom_save_done)); - eeprom_save_shown = FALSE; - serial = aoview_serial_open(device); - if (!serial) - return FALSE; - aoview_serial_set_callback(serial, aoview_eeprom_callback); - aoview_serial_printf(serial, "v\nl\n"); - return TRUE; -} - -void -aoview_eeprom_init(GladeXML *xml) -{ - eeprom_file = aoview_file_new("eeprom"); - assert(eeprom_file); - - eeprom_save_done = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "ao_save_done")); - assert(eeprom_save_done); - -} diff --git a/ao-view/aoview_file.c b/ao-view/aoview_file.c deleted file mode 100644 index 5288c2f7..00000000 --- a/ao-view/aoview_file.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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; 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 "aoview.h" - -char *aoview_file_dir; - -#define ALTOS_DIR_PATH "/apps/aoview/log_dir" -#define DEFAULT_DIR "AltOS" - -struct aoview_file { - char *ext; - FILE *file; - char *name; - int failed; - int serial; - int sequence; -}; - -static void -aoview_file_save_conf(void) -{ - GConfClient *gconf_client; - - gconf_client = gconf_client_get_default(); - if (gconf_client) - { - gconf_client_set_string(gconf_client, - ALTOS_DIR_PATH, - aoview_file_dir, - NULL); - g_object_unref(G_OBJECT(gconf_client)); - } -} - -static void -aoview_file_configure(GtkWidget *widget, gpointer data) -{ - GtkFileChooser *chooser = data; - aoview_file_dir = gtk_file_chooser_get_filename(chooser); - aoview_file_save_conf(); - gtk_widget_hide(GTK_WIDGET(chooser)); -} - -void -aoview_file_finish(struct aoview_file *file) -{ - if (file->file) { - fclose(file->file); - file->file = NULL; - free(file->name); - file->name = NULL; - } - file->failed = 0; -} - -const char * -aoview_file_name(struct aoview_file *file) -{ - return file->name; -} - -static GtkMessageDialog *file_fail_dialog; - -static void -aoview_file_open_failed(char *name) -{ - char *utf8_file; - utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL); - if (!utf8_file) - utf8_file = name; - gtk_message_dialog_format_secondary_text(file_fail_dialog, - "\"%s\"", utf8_file); - if (utf8_file != name) - g_free(utf8_file); - gtk_widget_show(GTK_WIDGET(file_fail_dialog)); -} - -gboolean -aoview_file_start(struct aoview_file *file) -{ - char base[50]; - struct tm tm; - time_t now; - char *full; - int r; - - if (file->file) - return TRUE; - - if (file->failed) - return FALSE; - - now = time(NULL); - (void) localtime_r(&now, &tm); - aoview_mkdir(aoview_file_dir); - for (;;) { - snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", - tm.tm_year + 1900, - tm.tm_mon + 1, - tm.tm_mday, - file->serial, - file->sequence, - file->ext); - full = aoview_fullname(aoview_file_dir, base); - r = access(full, F_OK); - if (r < 0) { - file->file = fopen(full, "w"); - if (!file->file) { - aoview_file_open_failed(full); - free(full); - file->failed = 1; - return FALSE; - } else { - setlinebuf(file->file); - file->name = full; - return TRUE; - } - } - free(full); - file->sequence++; - } -} - -void -aoview_file_vprintf(struct aoview_file *file, char *format, va_list ap) -{ - if (!aoview_file_start(file)) - return; - vfprintf(file->file, format, ap); -} - -void -aoview_file_printf(struct aoview_file *file, char *format, ...) -{ - va_list ap; - - va_start(ap, format); - aoview_file_vprintf(file, format, ap); - va_end(ap); -} - -struct aoview_file * -aoview_file_new(char *ext) -{ - struct aoview_file *file; - - file = calloc (1, sizeof (struct aoview_file)); - if (!file) - return NULL; - file->ext = strdup(ext); - if (!file->ext) { - free(file); - return NULL; - } - return file; -} - -void -aoview_file_destroy(struct aoview_file *file) -{ - if (file->file) - fclose(file->file); - if (file->name) - free(file->name); - free(file->ext); - free(file); -} - -void -aoview_file_set_serial(struct aoview_file *file, int serial) -{ - if (serial != file->serial) - aoview_file_finish(file); - file->serial = serial; -} - -int -aoview_file_get_serial(struct aoview_file *file) -{ - return file->serial; -} - -void -aoview_file_init(GladeXML *xml) -{ - GConfClient *gconf_client; - char *file_dir = NULL; - GtkFileChooser *file_chooser_dialog; - GtkWidget *file_configure_ok; - - g_type_init(); - gconf_client = gconf_client_get_default(); - if (gconf_client) - { - file_dir = gconf_client_get_string(gconf_client, - ALTOS_DIR_PATH, - NULL); - g_object_unref(G_OBJECT(gconf_client)); - } - if (!file_dir) { - aoview_file_dir = aoview_fullname(getenv("HOME"), DEFAULT_DIR); - aoview_file_save_conf(); - } else { - aoview_file_dir = strdup(file_dir); - } - - file_chooser_dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "file_chooser_dialog")); - assert(file_chooser_dialog); - gtk_file_chooser_set_filename(file_chooser_dialog, aoview_file_dir); - - file_configure_ok = glade_xml_get_widget(xml, "file_configure_ok"); - assert(file_configure_ok); - - g_signal_connect(G_OBJECT(file_configure_ok), "clicked", - G_CALLBACK(aoview_file_configure), - file_chooser_dialog); - - - file_fail_dialog = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "file_fail_dialog")); - assert(file_fail_dialog); -} diff --git a/ao-view/aoview_flite.c b/ao-view/aoview_flite.c deleted file mode 100644 index e1b75898..00000000 --- a/ao-view/aoview_flite.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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; 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 "aoview.h" -#include - -cst_voice *register_cmu_us_kal(); -static cst_voice *voice; - -static FILE *pipe_write; -static GThread *aoview_flite_thread; - -static snd_pcm_t *alsa_handle; - -gpointer -aoview_flite_task(gpointer data) -{ - FILE *input = data; - char line[1024]; - cst_wave *wave; - int rate; - int channels; - int err; - char *samples; - int num_samples; - - err = snd_pcm_open(&alsa_handle, "default", - SND_PCM_STREAM_PLAYBACK, 0); - if (err >= 0) - { - if (err < 0) { - snd_pcm_close(alsa_handle); - alsa_handle = 0; - } - } - rate = 0; - channels = 0; - while (fgets(line, sizeof (line) - 1, input) != NULL) { - if (!alsa_handle) - continue; - wave = flite_text_to_wave(line, voice); - if (wave->sample_rate != rate || - wave->num_channels != channels) - { - rate = wave->sample_rate; - channels = wave->num_channels; - err = snd_pcm_set_params(alsa_handle, - SND_PCM_FORMAT_S16, - SND_PCM_ACCESS_RW_INTERLEAVED, - channels, - rate, - 1, - 100000); - if (err < 0) - fprintf(stderr, "alsa set_params error %s\n", - strerror(-err)); - } - err = snd_pcm_prepare(alsa_handle); - if (err < 0) - fprintf(stderr, "alsa pcm_prepare error %s\n", - strerror(-err)); - samples = (char *) wave->samples; - num_samples = wave->num_samples; - while (num_samples > 0) { - err = snd_pcm_writei(alsa_handle, - samples, num_samples); - if (err <= 0) { - fprintf(stderr, "alsa write error %s\n", - strerror(-err)); - break; - } - num_samples -= err; - samples += err * 2 * channels; - } - snd_pcm_drain(alsa_handle); - delete_wave(wave); - } - snd_pcm_close(alsa_handle); - alsa_handle = 0; - return NULL; -} - -void -aoview_flite_stop(void) -{ - int status; - if (pipe_write) { - fclose(pipe_write); - pipe_write = NULL; - } - if (aoview_flite_thread) { - g_thread_join(aoview_flite_thread); - aoview_flite_thread = NULL; - } -} - -FILE * -aoview_flite_start(void) -{ - static once; - int p[2]; - GError *error; - FILE *pipe_read; - - if (!once) { - flite_init(); - voice = register_cmu_us_kal(); - if (!voice) { - perror("register voice"); - exit(1); - } - } - aoview_flite_stop(); - pipe(p); - pipe_read = fdopen(p[0], "r"); - pipe_write = fdopen(p[1], "w"); - g_thread_create(aoview_flite_task, pipe_read, TRUE, &error); - return pipe_write; -} diff --git a/ao-view/aoview_label.c b/ao-view/aoview_label.c deleted file mode 100644 index 24313626..00000000 --- a/ao-view/aoview_label.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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; 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 "aoview.h" - -static struct { - char *name; - char *initial_value; - GtkLabel *widget; -} label_widgets[] = { - { "height_label", "Height (m)", NULL }, - { "state_label", "State", NULL }, - { "rssi_label", "RSSI (dBm)", NULL }, - { "speed_label", "Speed (m/s)", NULL }, - { "height_value", "0", NULL }, - { "state_value", "pad", NULL }, - { "rssi_value", "-50", NULL }, - { "speed_value", "0", NULL }, -}; - -static void -aoview_label_assign(GtkLabel *widget, char *value) -{ - char *markup; - - markup = g_markup_printf_escaped("%s", value); - gtk_label_set_markup(widget, markup); - g_free(markup); -} - -void -aoview_label_show(struct aostate *state) -{ - char line[1024]; - sprintf(line, "%d", state->height); - aoview_label_assign(label_widgets[4].widget, line); - - aoview_label_assign(label_widgets[5].widget, state->data.state); - - sprintf(line, "%d", state->data.rssi); - aoview_label_assign(label_widgets[6].widget, line); - - if (state->ascent) - sprintf(line, "%6.0f", fabs(state->speed)); - else - sprintf(line, "%6.0f", fabs(state->baro_speed)); - aoview_label_assign(label_widgets[7].widget, line); -} - -void -aoview_label_init(GladeXML *xml) -{ - int i; - for (i = 0; i < sizeof(label_widgets)/sizeof(label_widgets[0]); i++) { - label_widgets[i].widget = GTK_LABEL(glade_xml_get_widget(xml, label_widgets[i].name)); - aoview_label_assign(label_widgets[i].widget, label_widgets[i].initial_value); - assert(label_widgets[i].widget); - } -} diff --git a/ao-view/aoview_log.c b/ao-view/aoview_log.c deleted file mode 100644 index 1b89c28c..00000000 --- a/ao-view/aoview_log.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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; 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 "aoview.h" - -static struct aoview_file *aoview_log; - -void -aoview_log_new(void) -{ - aoview_file_finish(aoview_log); - aoview_state_new(); -} - -void -aoview_log_set_serial(int serial) -{ - aoview_file_set_serial(aoview_log, serial); -} - -int -aoview_log_get_serial(void) -{ - return aoview_file_get_serial(aoview_log); -} - -void -aoview_log_printf(char *format, ...) -{ - va_list ap; - - va_start(ap, format); - aoview_file_vprintf(aoview_log, format, ap); - va_end(ap); -} - -static void -aoview_log_new_item(GtkWidget *widget, gpointer data) -{ - aoview_file_finish(aoview_log); -} - -void -aoview_log_init(GladeXML *xml) -{ - GtkWidget *log_new; - - aoview_log = aoview_file_new("telem"); - assert(aoview_log); - - log_new = glade_xml_get_widget(xml, "log_new"); - assert(log_new); - g_signal_connect(G_OBJECT(log_new), "activate", - G_CALLBACK(aoview_log_new_item), - NULL); -} diff --git a/ao-view/aoview_main.c b/ao-view/aoview_main.c deleted file mode 100644 index 64c1c027..00000000 --- a/ao-view/aoview_main.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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; 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 "aoview.h" - -static const char aoview_glade[] = { -#include "aoview_glade.h" -}; - -static void usage(void) { - printf("aoview [--device|-d device_file]"); - exit(1); -} - -static void destroy_event(GtkWidget *widget, gpointer data) -{ - gtk_main_quit(); -} - -extern int _Xdebug; -char *aoview_tty = NULL; - -int main(int argc, char **argv) -{ - GladeXML *xml = NULL; - GtkWidget *mainwindow; - GtkAboutDialog *about_dialog; - - static struct option long_options[] = { - { "tty", 1, 0, 'T'}, - { "sync", 0, 0, 's'}, - { 0, 0, 0, 0 } - }; - for (;;) { - int c, temp; - - c = getopt_long_only(argc, argv, "sT:", long_options, &temp); - if (c == -1) - break; - - switch (c) { - case 'T': - aoview_tty = optarg; - break; - case 's': - _Xdebug = 1; - break; - default: - usage(); - } - } - - g_thread_init(NULL); - gtk_init(&argc, &argv); - glade_init(); - - xml = glade_xml_new_from_buffer(aoview_glade, sizeof (aoview_glade), NULL, NULL); - - /* connect the signals in the interface */ - glade_xml_signal_autoconnect(xml); - - /* Hook up the close button. */ - mainwindow = glade_xml_get_widget(xml, "aoview"); - assert(mainwindow); - - g_signal_connect (G_OBJECT(mainwindow), "destroy", - G_CALLBACK(destroy_event), NULL); - - about_dialog = GTK_ABOUT_DIALOG(glade_xml_get_widget(xml, "about_dialog")); - assert(about_dialog); - gtk_about_dialog_set_version(about_dialog, AOVIEW_VERSION); - - aoview_voice_init(xml); - - aoview_dev_dialog_init(xml); - - aoview_state_init(xml); - - aoview_file_init(xml); - - aoview_log_init(xml); - - aoview_table_init(xml); - - aoview_eeprom_init(xml); - - aoview_replay_init(xml); - - aoview_label_init(xml); - - if (aoview_tty) { - if (!aoview_monitor_connect(aoview_tty)) { - perror(aoview_tty); - exit(1); - } - } - aoview_voice_speak("rocket flight monitor ready\n"); - - gtk_main(); - - return 0; -} diff --git a/ao-view/aoview_monitor.c b/ao-view/aoview_monitor.c deleted file mode 100644 index 8564014b..00000000 --- a/ao-view/aoview_monitor.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * 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; 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 "aoview.h" - -static struct aoview_serial *monitor_serial; - -#define MONITOR_LEN 1024 - -static char monitor_line[MONITOR_LEN + 1]; -static int monitor_pos; - -void -aoview_monitor_disconnect(void) -{ - if (monitor_serial) { - aoview_serial_close(monitor_serial); - monitor_serial = NULL; - } - aoview_log_new(); -} - -static void -aoview_parse_string(char *target, int len, char *source) -{ - strncpy(target, source, len-1); - target[len-1] = '\0'; -} - -static void -aoview_parse_int(int *target, char *source) -{ - *target = strtol(source, NULL, 0); -} - -static void -aoview_parse_hex(int *target, char *source) -{ - *target = strtol(source, NULL, 16); -} - -static void -aoview_parse_pos(double *target, char *source) -{ - int deg; - double min; - char dir; - double r; - - if (sscanf(source, "%d°%lf'%c", °, &min, &dir) != 3) { - *target = 0; - return; - } - r = deg + min / 60.0; - if (dir == 'S' || dir == 'W') - r = -r; - *target = r; -} - -#define PARSE_MAX_WORDS 256 - -gboolean -aoview_monitor_parse(const char *input_line) -{ - char *saveptr; - char *words[PARSE_MAX_WORDS]; - int nword; - char line_buf[8192], *line; - struct aodata data; - int tracking_pos; - - /* avoid smashing our input parameter */ - strncpy (line_buf, input_line, sizeof (line_buf)-1); - line_buf[sizeof(line_buf) - 1] = '\0'; - line = line_buf; - for (nword = 0; nword < PARSE_MAX_WORDS; nword++) { - words[nword] = strtok_r(line, " \t\n", &saveptr); - line = NULL; - if (words[nword] == NULL) - break; - } - if (nword < 36) - return FALSE; - if (strcmp(words[0], "CALL") != 0) - return FALSE; - aoview_parse_string(data.callsign, sizeof (data.callsign), words[1]); - aoview_parse_int(&data.serial, words[3]); - - aoview_parse_int(&data.rssi, words[5]); - aoview_parse_string(data.state, sizeof (data.state), words[9]); - aoview_parse_int(&data.tick, words[10]); - aoview_parse_int(&data.accel, words[12]); - aoview_parse_int(&data.pres, words[14]); - aoview_parse_int(&data.temp, words[16]); - aoview_parse_int(&data.batt, words[18]); - aoview_parse_int(&data.drogue, words[20]); - aoview_parse_int(&data.main, words[22]); - aoview_parse_int(&data.flight_accel, words[24]); - aoview_parse_int(&data.ground_accel, words[26]); - aoview_parse_int(&data.flight_vel, words[28]); - aoview_parse_int(&data.flight_pres, words[30]); - aoview_parse_int(&data.ground_pres, words[32]); - aoview_parse_int(&data.gps.nsat, words[34]); - if (strcmp (words[36], "unlocked") == 0) { - data.gps.gps_connected = 1; - data.gps.gps_locked = 0; - data.gps.gps_time.hour = data.gps.gps_time.minute = data.gps.gps_time.second = 0; - data.gps.lat = data.gps.lon = 0; - data.gps.alt = 0; - tracking_pos = 37; - } else if (nword >= 40) { - data.gps.gps_locked = 1; - data.gps.gps_connected = 1; - sscanf(words[36], "%d:%d:%d", &data.gps.gps_time.hour, &data.gps.gps_time.minute, &data.gps.gps_time.second); - aoview_parse_pos(&data.gps.lat, words[37]); - aoview_parse_pos(&data.gps.lon, words[38]); - sscanf(words[39], "%dm", &data.gps.alt); - tracking_pos = 46; - } else { - data.gps.gps_connected = 0; - data.gps.gps_locked = 0; - data.gps.gps_time.hour = data.gps.gps_time.minute = data.gps.gps_time.second = 0; - data.gps.lat = data.gps.lon = 0; - data.gps.alt = 0; - tracking_pos = -1; - } - if (nword >= 46) { - data.gps.gps_extended = 1; - sscanf(words[40], "%lfm/s", &data.gps.ground_speed); - sscanf(words[41], "%d", &data.gps.course); - sscanf(words[42], "%lfm/s", &data.gps.climb_rate); - sscanf(words[43], "%lf", &data.gps.hdop); - sscanf(words[44], "%d", &data.gps.h_error); - sscanf(words[45], "%d", &data.gps.v_error); - } else { - data.gps.gps_extended = 0; - data.gps.ground_speed = 0; - data.gps.course = 0; - data.gps.climb_rate = 0; - data.gps.hdop = 0; - data.gps.h_error = 0; - data.gps.v_error = 0; - } - if (tracking_pos >= 0 && nword >= tracking_pos + 2 && strcmp(words[tracking_pos], "SAT") == 0) { - int c, n, pos; - aoview_parse_int(&n, words[tracking_pos + 1]); - pos = tracking_pos + 2; - if (nword >= pos + n * 3) { - data.gps_tracking.channels = n; - for (c = 0; c < n; c++) { - aoview_parse_int(&data.gps_tracking.sats[c].svid, - words[pos + 0]); - aoview_parse_hex(&data.gps_tracking.sats[c].state, - words[pos + 1]); - aoview_parse_int(&data.gps_tracking.sats[c].c_n0, - words[pos + 2]); - pos += 3; - } - } else { - data.gps_tracking.channels = 0; - } - } else { - data.gps_tracking.channels = 0; - } - aoview_state_notify(&data); - return TRUE; -} - -static void -aoview_monitor_callback(gpointer user_data, - struct aoview_serial *serial, - gint revents) -{ - int c; - - if (revents & (G_IO_HUP|G_IO_ERR)) { - aoview_monitor_disconnect(); - return; - } - if (revents & G_IO_IN) { - for (;;) { - c = aoview_serial_getc(serial); - if (c == -1) - break; - if (c == '\r') - continue; - if (c == '\n') { - monitor_line[monitor_pos] = '\0'; - if (monitor_pos) { - if (aoview_monitor_parse(monitor_line)) { - aoview_log_set_serial(aostate.data.serial); - if (aoview_log_get_serial()) - aoview_log_printf ("%s\n", monitor_line); - } - } - monitor_pos = 0; - } else if (monitor_pos < MONITOR_LEN) - monitor_line[monitor_pos++] = c; - } - } -} - -gboolean -aoview_monitor_connect(char *tty) -{ - aoview_monitor_disconnect(); - monitor_serial = aoview_serial_open(tty); - if (!monitor_serial) - return FALSE; - aoview_table_clear(); - aoview_state_reset(); - aoview_serial_set_callback(monitor_serial, - aoview_monitor_callback); - return TRUE; -} diff --git a/ao-view/aoview_replay.c b/ao-view/aoview_replay.c deleted file mode 100644 index da7b5d6a..00000000 --- a/ao-view/aoview_replay.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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; 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 "aoview.h" - -static GtkFileChooser *replay_dialog; -static GtkWidget *replay_ok; -static FILE *replay_file; -static int replay_tick; - -static int -find_tick(char *line, gboolean *is_pad) -{ - char *state = strstr(line, "STATE"); - if (!state) - return -1; - state = strchr(state, ' '); - if (!state) - return -1; - while (*state == ' ') - state++; - *is_pad = strncmp(state, "pad", 3) == 0; - while (*state && !isdigit(*state)) - state++; - return atoi(state); -} - -static void -aoview_replay_close(void) -{ - if (replay_file) { - fclose(replay_file); - replay_file = NULL; - } -} - -static char replay_line[1024]; - -static gboolean -aoview_replay_read(gpointer data); - -static gboolean -aoview_replay_execute(gpointer data) -{ - aoview_monitor_parse(replay_line); - g_idle_add(aoview_replay_read, NULL); - return FALSE; -} - -static gboolean -aoview_replay_read(gpointer data) -{ - int tick; - gboolean is_pad; - - if (!replay_file) - return FALSE; - if (fgets(replay_line, sizeof (replay_line), replay_file)) { - tick = find_tick(replay_line, &is_pad); - if (tick >= 0 && replay_tick >= 0 && !is_pad) { - while (tick < replay_tick) - tick += 65536; - g_timeout_add((tick - replay_tick) * 10, - aoview_replay_execute, - NULL); - } else { - aoview_replay_execute(NULL); - } - replay_tick = tick; - } else { - aoview_replay_close(); - } - return FALSE; -} - -static void -aoview_replay_open(GtkWidget *widget, gpointer data) -{ - char *replay_file_name; - GtkWidget *dialog; - - aoview_replay_close(); - replay_file_name = gtk_file_chooser_get_filename(replay_dialog); - replay_file = fopen(replay_file_name, "r"); - if (!replay_file) { - dialog = gtk_message_dialog_new(GTK_WINDOW(replay_dialog), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "Error loading file '%s': %s", - replay_file_name, g_strerror(errno)); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - } else { - replay_tick = -1; - aoview_state_reset(); - aoview_replay_read(NULL); - } - gtk_widget_hide(GTK_WIDGET(replay_dialog)); -} - -void -aoview_replay_init(GladeXML *xml) -{ - GtkFileFilter *telem_filter; - GtkFileFilter *all_filter; - GtkFileFilter *log_filter; - - telem_filter = gtk_file_filter_new(); - gtk_file_filter_add_pattern(telem_filter, "*.telem"); - gtk_file_filter_set_name(telem_filter, "Telemetry Files"); - - log_filter = gtk_file_filter_new(); - gtk_file_filter_add_pattern(log_filter, "*.log"); - gtk_file_filter_set_name(log_filter, "Log Files"); - - all_filter = gtk_file_filter_new(); - gtk_file_filter_add_pattern(all_filter, "*"); - gtk_file_filter_set_name(all_filter, "All Files"); - - replay_dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "ao_replay_dialog")); - assert(replay_dialog); - gtk_file_chooser_set_current_folder(replay_dialog, aoview_file_dir); - gtk_file_chooser_add_filter(replay_dialog, telem_filter); - gtk_file_chooser_add_filter(replay_dialog, log_filter); - gtk_file_chooser_add_filter(replay_dialog, all_filter); - - replay_ok = glade_xml_get_widget(xml, "ao_replay_ok"); - assert(replay_ok); - g_signal_connect(G_OBJECT(replay_ok), "clicked", - G_CALLBACK(aoview_replay_open), - replay_dialog); -} diff --git a/ao-view/aoview_serial.c b/ao-view/aoview_serial.c deleted file mode 100644 index 29038b79..00000000 --- a/ao-view/aoview_serial.c +++ /dev/null @@ -1,270 +0,0 @@ -/* - * 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; 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 "aoview.h" -#include - -#define AOVIEW_SERIAL_IN_BUF 64 -#define AOVIEW_SERIAL_OUT_BUF 64 - -struct aoview_buf { - char *buf; - int off; - int count; - int size; -}; - -static int -aoview_buf_write(struct aoview_buf *buf, char *data, int len) -{ - if (buf->count + len > buf->size) { - int new_size = buf->size * 2; - if (new_size == 0) - new_size = 1024; - if (buf->buf) - buf->buf = realloc (buf->buf, new_size); - else - buf->buf = malloc (new_size); - buf->size = new_size; - } - memcpy(buf->buf + buf->count, data, len); - buf->count += len; - return len; -} - -static int -aoview_buf_read(struct aoview_buf *buf, char *data, int len) -{ - if (len > buf->count - buf->off) - len = buf->count - buf->off; - memcpy (data, buf->buf + buf->off, len); - buf->off += len; - if (buf->off == buf->count) - buf->off = buf->count = 0; - return len; -} - -static int -aoview_buf_getc(struct aoview_buf *buf) -{ - char b; - int r; - - r = aoview_buf_read(buf, &b, 1); - if (r == 1) - return (int) b; - return -1; -} - -static void -aoview_buf_flush(struct aoview_buf *buf, int fd) -{ - int ret; - - if (buf->count > buf->off) { - ret = write(fd, buf->buf + buf->off, buf->count - buf->off); - if (ret > 0) { - buf->off += ret; - if (buf->off == buf->count) - buf->off = buf->count = 0; - } - } -} - -static void -aoview_buf_fill(struct aoview_buf *buf, int fd) -{ - int ret; - - while (buf->count >= buf->size) { - int new_size = buf->size * 2; - buf->buf = realloc (buf->buf, new_size); - buf->size = new_size; - } - - ret = read(fd, buf->buf + buf->count, buf->size - buf->count); - if (ret > 0) - buf->count += ret; -} - -static void -aoview_buf_init(struct aoview_buf *buf) -{ - buf->buf = malloc (buf->size = 1024); - buf->count = 0; -} - -static void -aoview_buf_fini(struct aoview_buf *buf) -{ - free(buf->buf); -} - -struct aoview_serial { - GSource source; - int fd; - struct termios save_termios; - struct aoview_buf in_buf; - struct aoview_buf out_buf; - GPollFD poll_fd; -}; - - -void -aoview_serial_printf(struct aoview_serial *serial, char *format, ...) -{ - char buf[1024]; - va_list ap; - int ret; - - /* sprintf to a local buffer */ - va_start(ap, format); - ret = vsnprintf(buf, sizeof(buf), format, ap); - va_end(ap); - if (ret > sizeof(buf)) { - fprintf(stderr, "printf overflow for format %s\n", - format); - } - - /* flush local buffer to the wire */ - aoview_buf_write(&serial->out_buf, buf, ret); - aoview_buf_flush(&serial->out_buf, serial->fd); -} - -int -aoview_serial_read(struct aoview_serial *serial, char *buf, int len) -{ - return aoview_buf_read(&serial->in_buf, buf, len); -} - -int -aoview_serial_getc(struct aoview_serial *serial) -{ - return aoview_buf_getc(&serial->in_buf); -} - -static gboolean -serial_prepare(GSource *source, gint *timeout) -{ - struct aoview_serial *serial = (struct aoview_serial *) source; - *timeout = -1; - - if (serial->out_buf.count) - serial->poll_fd.events |= G_IO_OUT; - else - serial->poll_fd.events &= ~G_IO_OUT; - return FALSE; -} - -static gboolean -serial_check(GSource *source) -{ - struct aoview_serial *serial = (struct aoview_serial *) source; - gint revents = serial->poll_fd.revents; - - if (revents & G_IO_NVAL) - return FALSE; - if (revents & G_IO_IN) - return TRUE; - if (revents & G_IO_OUT) - return TRUE; - return FALSE; -} - -static gboolean -serial_dispatch(GSource *source, - GSourceFunc callback, - gpointer user_data) -{ - struct aoview_serial *serial = (struct aoview_serial *) source; - aoview_serial_callback func = (aoview_serial_callback) callback; - gint revents = serial->poll_fd.revents; - - if (revents & G_IO_IN) - aoview_buf_fill(&serial->in_buf, serial->fd); - - if (revents & G_IO_OUT) - aoview_buf_flush(&serial->out_buf, serial->fd); - - if (func) - (*func)(user_data, serial, revents); - return TRUE; -} - -static void -serial_finalize(GSource *source) -{ - struct aoview_serial *serial = (struct aoview_serial *) source; - - aoview_buf_fini(&serial->in_buf); - aoview_buf_fini(&serial->out_buf); - tcsetattr(serial->fd, TCSAFLUSH, &serial->save_termios); - close (serial->fd); -} - -static GSourceFuncs serial_funcs = { - serial_prepare, - serial_check, - serial_dispatch, - serial_finalize -}; - -struct aoview_serial * -aoview_serial_open(const char *tty) -{ - struct aoview_serial *serial; - struct termios termios; - - serial = (struct aoview_serial *) g_source_new(&serial_funcs, sizeof (struct aoview_serial)); - aoview_buf_init(&serial->in_buf); - aoview_buf_init(&serial->out_buf); - serial->fd = open (tty, O_RDWR | O_NONBLOCK); - if (serial->fd < 0) { - g_source_destroy(&serial->source); - return NULL; - } - tcgetattr(serial->fd, &termios); - serial->save_termios = termios; - cfmakeraw(&termios); - tcsetattr(serial->fd, TCSAFLUSH, &termios); - - aoview_serial_printf(serial, "E 0\n"); - tcdrain(serial->fd); - usleep(15*1000); - tcflush(serial->fd, TCIFLUSH); - serial->poll_fd.fd = serial->fd; - serial->poll_fd.events = G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR; - g_source_attach(&serial->source, NULL); - g_source_add_poll(&serial->source,&serial->poll_fd); - aoview_serial_set_callback(serial, NULL); - return serial; -} - -void -aoview_serial_close(struct aoview_serial *serial) -{ - g_source_remove_poll(&serial->source, &serial->poll_fd); - close(serial->fd); - g_source_destroy(&serial->source); -} - -void -aoview_serial_set_callback(struct aoview_serial *serial, - aoview_serial_callback func) -{ - g_source_set_callback(&serial->source, (GSourceFunc) func, serial, NULL); -} diff --git a/ao-view/aoview_state.c b/ao-view/aoview_state.c deleted file mode 100644 index f75066dd..00000000 --- a/ao-view/aoview_state.c +++ /dev/null @@ -1,373 +0,0 @@ -/* - * 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; 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 "aoview.h" -#include - -static inline double sqr(double a) { return a * a; }; - -static void -aoview_great_circle (double start_lat, double start_lon, - double end_lat, double end_lon, - double *dist, double *bearing) -{ - const double rad = M_PI / 180; - const double earth_radius = 6371.2 * 1000; /* in meters */ - double lat1 = rad * start_lat; - double lon1 = rad * -start_lon; - double lat2 = rad * end_lat; - double lon2 = rad * -end_lon; - - double d_lat = lat2 - lat1; - double d_lon = lon2 - lon1; - - /* From http://en.wikipedia.org/wiki/Great-circle_distance */ - double vdn = sqrt(sqr(cos(lat2) * sin(d_lon)) + - sqr(cos(lat1) * sin(lat2) - - sin(lat1) * cos(lat2) * cos(d_lon))); - double vdd = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(d_lon); - double d = atan2(vdn,vdd); - double course; - - if (cos(lat1) < 1e-20) { - if (lat1 > 0) - course = M_PI; - else - course = -M_PI; - } else { - if (d < 1e-10) - course = 0; - else - course = acos((sin(lat2)-sin(lat1)*cos(d)) / - (sin(d)*cos(lat1))); - if (sin(lon2-lon1) > 0) - course = 2 * M_PI-course; - } - *dist = d * earth_radius; - *bearing = course * 180/M_PI; -} - -static void -aoview_state_add_deg(int column, char *label, double deg, char pos, char neg) -{ - double int_part; - double min; - char sign = pos; - - if (deg < 0) { - deg = -deg; - sign = neg; - } - int_part = floor (deg); - min = (deg - int_part) * 60.0; - aoview_table_add_row(column, label, "%d°%lf'%c", - (int) int_part, min, sign); - -} - -static char *ascent_states[] = { - "boost", - "fast", - "coast", - 0, -}; - -static double -aoview_time(void) -{ - struct timespec now; - - clock_gettime(CLOCK_MONOTONIC, &now); - return (double) now.tv_sec + (double) now.tv_nsec / 1.0e9; -} - -/* - * Fill out the derived data fields - */ -static void -aoview_state_derive(struct aodata *data, struct aostate *state) -{ - int i; - double new_height; - double height_change; - double time_change; - int tick_count; - - state->report_time = aoview_time(); - - state->prev_data = state->data; - state->prev_npad = state->npad; - state->data = *data; - tick_count = data->tick; - if (tick_count < state->prev_data.tick) - tick_count += 65536; - time_change = (tick_count - state->prev_data.tick) / 100.0; - - state->ground_altitude = aoview_pres_to_altitude(data->ground_pres); - new_height = aoview_pres_to_altitude(data->flight_pres) - state->ground_altitude; - height_change = new_height - state->height; - state->height = new_height; - if (time_change) - state->baro_speed = (state->baro_speed * 3 + (height_change / time_change)) / 4.0; - state->acceleration = (data->ground_accel - data->flight_accel) / 27.0; - state->speed = data->flight_vel / 2700.0; - state->temperature = ((data->temp / 32767.0 * 3.3) - 0.5) / 0.01; - state->drogue_sense = data->drogue / 32767.0 * 15.0; - state->main_sense = data->main / 32767.0 * 15.0; - state->battery = data->batt / 32767.0 * 5.0; - if (!strcmp(data->state, "pad")) { - if (data->gps.gps_locked && data->gps.nsat >= 4) { - state->npad++; - state->pad_lat_total += data->gps.lat; - state->pad_lon_total += data->gps.lon; - state->pad_alt_total += data->gps.alt; - if (state->npad > 1) { - state->pad_lat = (state->pad_lat * 31 + data->gps.lat) / 32.0; - state->pad_lon = (state->pad_lon * 31 + data->gps.lon) / 32.0; - state->pad_alt = (state->pad_alt * 31 + data->gps.alt) / 32.0; - } else { - state->pad_lat = data->gps.lat; - state->pad_lon = data->gps.lon; - state->pad_alt = data->gps.alt; - } - } - } - state->ascent = FALSE; - for (i = 0; ascent_states[i]; i++) - if (!strcmp(data->state, ascent_states[i])) - state->ascent = TRUE; - - /* Only look at accelerometer data on the way up */ - if (state->ascent && state->acceleration > state->max_acceleration) - state->max_acceleration = state->acceleration; - if (state->ascent && state->speed > state->max_speed) - state->max_speed = state->speed; - - if (state->height > state->max_height) - state->max_height = state->height; - state->gps.gps_locked = data->gps.gps_locked; - state->gps.gps_connected = data->gps.gps_connected; - if (data->gps.gps_locked) { - state->gps = data->gps; - state->gps_valid = 1; - if (state->npad) - aoview_great_circle(state->pad_lat, state->pad_lon, state->gps.lat, state->gps.lon, - &state->distance, &state->bearing); - } - if (data->gps_tracking.channels) - state->gps_tracking = data->gps_tracking; - if (state->npad) { - state->gps_height = state->gps.alt - state->pad_alt; - } else { - state->gps_height = 0; - } -} - -void -aoview_speak_state(struct aostate *state) -{ - if (strcmp(state->data.state, state->prev_data.state)) { - aoview_voice_speak("%s\n", state->data.state); - if (!strcmp(state->data.state, "drogue")) - aoview_voice_speak("apogee %d meters\n", - (int) state->max_height); - if (!strcmp(state->prev_data.state, "boost")) - aoview_voice_speak("max speed %d meters per second\n", - (int) state->max_speed); - } - if (state->prev_npad < MIN_PAD_SAMPLES && state->npad >= MIN_PAD_SAMPLES) - aoview_voice_speak("g p s ready\n"); -} - -void -aoview_speak_height(struct aostate *state) -{ - aoview_voice_speak("%d meters\n", state->height); -} - -struct aostate aostate; - -static guint aostate_timeout; - -#define COMPASS_LIMIT(n) ((n * 22.5) + 22.5/2) - -static char *compass_points[] = { - "north", - "north north east", - "north east", - "east north east", - "east", - "east south east", - "south east", - "south south east", - "south", - "south south west", - "south west", - "west south west", - "west", - "west north west", - "north west", - "north north west", -}; - -static char * -aoview_compass_point(double bearing) -{ - int i; - while (bearing < 0) - bearing += 360.0; - while (bearing >= 360.0) - bearing -= 360.0; - - i = floor ((bearing - 22.5/2) / 22.5 + 0.5); - if (i < 0) i = 0; - if (i >= sizeof (compass_points) / sizeof (compass_points[0])) - i = 0; - return compass_points[i]; -} - -static gboolean -aoview_state_timeout(gpointer data) -{ - double now = aoview_time(); - - if (strlen(aostate.data.state) > 0 && strcmp(aostate.data.state, "pad") != 0) - aoview_speak_height(&aostate); - if (now - aostate.report_time >= 20 || !strcmp(aostate.data.state, "landed")) { - if (!aostate.ascent) { - if (fabs(aostate.baro_speed) < 20 && aostate.height < 100) - aoview_voice_speak("rocket landed safely\n"); - else - aoview_voice_speak("rocket may have crashed\n"); - if (aostate.gps_valid) { - aoview_voice_speak("rocket reported %s of pad distance %d meters\n", - aoview_compass_point(aostate.bearing), - (int) aostate.distance); - } - } - aostate_timeout = 0; - return FALSE; - } - return TRUE; -} - -void -aoview_state_reset(void) -{ - memset(&aostate, '\0', sizeof (aostate)); -} - -void -aoview_state_notify(struct aodata *data) -{ - struct aostate *state = &aostate; - aoview_state_derive(data, state); - aoview_table_start(); - - if (state->npad >= MIN_PAD_SAMPLES) - aoview_table_add_row(0, "Ground state", "ready"); - else - aoview_table_add_row(0, "Ground state", "waiting for gps (%d)", - MIN_PAD_SAMPLES - state->npad); - aoview_table_add_row(0, "Rocket state", "%s", state->data.state); - aoview_table_add_row(0, "Callsign", "%s", state->data.callsign); - aoview_table_add_row(0, "Rocket serial", "%d", state->data.serial); - - aoview_table_add_row(0, "RSSI", "%6ddBm", state->data.rssi); - aoview_table_add_row(0, "Height", "%6dm", state->height); - aoview_table_add_row(0, "Max height", "%6dm", state->max_height); - aoview_table_add_row(0, "Acceleration", "%7.1fm/s²", state->acceleration); - aoview_table_add_row(0, "Max acceleration", "%7.1fm/s²", state->max_acceleration); - aoview_table_add_row(0, "Speed", "%7.1fm/s", state->ascent ? state->speed : state->baro_speed); - aoview_table_add_row(0, "Max Speed", "%7.1fm/s", state->max_speed); - aoview_table_add_row(0, "Temperature", "%6.2f°C", state->temperature); - aoview_table_add_row(0, "Battery", "%5.2fV", state->battery); - aoview_table_add_row(0, "Drogue", "%5.2fV", state->drogue_sense); - aoview_table_add_row(0, "Main", "%5.2fV", state->main_sense); - aoview_table_add_row(0, "Pad altitude", "%dm", state->ground_altitude); - aoview_table_add_row(1, "Satellites", "%d", state->gps.nsat); - if (state->gps.gps_locked) { - aoview_table_add_row(1, "GPS", "locked"); - } else if (state->gps.gps_connected) { - aoview_table_add_row(1, "GPS", "unlocked"); - } else { - aoview_table_add_row(1, "GPS", "not available"); - } - if (state->gps_valid) { - aoview_state_add_deg(1, "Latitude", state->gps.lat, 'N', 'S'); - aoview_state_add_deg(1, "Longitude", state->gps.lon, 'E', 'W'); - aoview_table_add_row(1, "GPS altitude", "%d", state->gps.alt); - aoview_table_add_row(1, "GPS height", "%d", state->gps_height); - aoview_table_add_row(1, "GPS time", "%02d:%02d:%02d", - state->gps.gps_time.hour, - state->gps.gps_time.minute, - state->gps.gps_time.second); - } - if (state->gps.gps_extended) { - aoview_table_add_row(1, "GPS ground speed", "%7.1fm/s %d°", - state->gps.ground_speed, - state->gps.course); - aoview_table_add_row(1, "GPS climb rate", "%7.1fm/s", - state->gps.climb_rate); - aoview_table_add_row(1, "GPS precision", "%4.1f(hdop) %3dm(h) %3dm(v)", - state->gps.hdop, state->gps.h_error, state->gps.v_error); - } - if (state->npad) { - aoview_table_add_row(1, "Distance from pad", "%5.0fm", state->distance); - aoview_table_add_row(1, "Direction from pad", "%4.0f°", state->bearing); - aoview_state_add_deg(1, "Pad latitude", state->pad_lat, 'N', 'S'); - aoview_state_add_deg(1, "Pad longitude", state->pad_lon, 'E', 'W'); - aoview_table_add_row(1, "Pad GPS alt", "%gm", state->pad_alt); - } - if (state->gps.gps_connected) { - int nsat_vis = 0; - int nsat_locked = 0; - int c; - - for (c = 0; c < state->gps_tracking.channels; c++) { - if ((state->gps_tracking.sats[c].state & 0xff) == 0xbf) - nsat_locked++; - } - aoview_table_add_row(2, "Satellites Visible", "%d", state->gps_tracking.channels); - aoview_table_add_row(2, "Satellites Locked", "%d", nsat_locked); - for (c = 0; c < state->gps_tracking.channels; c++) { - aoview_table_add_row(2, "Satellite id,state,C/N0", - "%3d,%02x,%2d%s", - state->gps_tracking.sats[c].svid, - state->gps_tracking.sats[c].state, - state->gps_tracking.sats[c].c_n0, - (state->gps_tracking.sats[c].state & 0xff) == 0xbf ? - " LOCKED" : ""); - } - } - aoview_table_finish(); - aoview_label_show(state); - aoview_speak_state(state); - if (!aostate_timeout && strcmp(state->data.state, "pad") != 0) - aostate_timeout = g_timeout_add_seconds(10, aoview_state_timeout, NULL); -} - -void -aoview_state_new(void) -{ -} - -void -aoview_state_init(GladeXML *xml) -{ - aoview_state_new(); -} diff --git a/ao-view/aoview_table.c b/ao-view/aoview_table.c deleted file mode 100644 index e75ae670..00000000 --- a/ao-view/aoview_table.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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; 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 "aoview.h" - -#define NCOL 3 - -static GtkTreeView *dataview[NCOL]; -static GtkListStore *datalist[NCOL]; - -void -aoview_table_start(void) -{ - int col; - for (col = 0; col < NCOL; col++) - datalist[col] = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); -} - -void -aoview_table_add_row(int col, char *label, char *format, ...) -{ - char buf[1024]; - va_list ap; - GtkTreeIter iter; - - va_start(ap, format); - vsnprintf(buf, sizeof (buf), format, ap); - va_end(ap); - gtk_list_store_append(datalist[col], &iter); - gtk_list_store_set(datalist[col], &iter, - 0, label, - 1, buf, - -1); -} - -void -aoview_table_finish(void) -{ - int col; - for (col = 0; col < NCOL; col++) { - gtk_tree_view_set_model(dataview[col], GTK_TREE_MODEL(datalist[col])); - g_object_unref(G_OBJECT(datalist[col])); - gtk_tree_view_columns_autosize(dataview[col]); - } -} - -void -aoview_table_clear(void) -{ - int col; - for (col = 0; col < NCOL; col++) - gtk_tree_view_set_model(dataview[col], NULL); -} - -void -aoview_table_init(GladeXML *xml) -{ - int col; - - for (col = 0; col < NCOL; col++) { - char name[32]; - sprintf(name, "dataview_%d", col); - dataview[col] = GTK_TREE_VIEW(glade_xml_get_widget(xml, name)); - assert(dataview[col]); - - aoview_add_plain_text_column(dataview[col], "Field", 0, 20); - aoview_add_plain_text_column(dataview[col], "Value", 1, 32); - } -} diff --git a/ao-view/aoview_util.c b/ao-view/aoview_util.c deleted file mode 100644 index 6ea62ac9..00000000 --- a/ao-view/aoview_util.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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; 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 "aoview.h" - -char * -aoview_fullname (char *dir, char *file) -{ - char *new; - int dlen = strlen (dir); - int flen = strlen (file); - int slen = 0; - - if (dir[dlen-1] != '/') - slen = 1; - new = malloc (dlen + slen + flen + 1); - if (!new) - return 0; - strcpy(new, dir); - if (slen) - strcat (new, "/"); - strcat(new, file); - return new; -} - -char * -aoview_basename(char *file) -{ - char *b; - - b = strrchr(file, '/'); - if (!b) - return file; - return b + 1; -} - -int -aoview_mkdir(char *dir) -{ - char *slash; - char *d; - char *part; - - d = dir; - for (;;) { - slash = strchr (d, '/'); - if (!slash) - slash = d + strlen(d); - if (!*slash) - break; - part = strndup(dir, slash - dir); - if (!access(part, F_OK)) - if (mkdir(part, 0777) < 0) - return -errno; - free(part); - d = slash + 1; - } - return 0; -} - -GtkTreeViewColumn * -aoview_add_plain_text_column (GtkTreeView *view, const gchar *title, gint model_column, gint width) -{ - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - renderer = gtk_cell_renderer_text_new (); - g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL); - g_object_set(renderer, "width-chars", width, NULL); - column = gtk_tree_view_column_new_with_attributes (title, renderer, - "text", model_column, - NULL); - gtk_tree_view_column_set_resizable (column, FALSE); - gtk_tree_view_append_column (view, column); - - return column; -} diff --git a/ao-view/aoview_voice.c b/ao-view/aoview_voice.c deleted file mode 100644 index 24422df6..00000000 --- a/ao-view/aoview_voice.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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; 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 "aoview.h" - -#if HAVE_FLITE -#include - -FILE *aoview_flite; - -void aoview_voice_open(void) -{ - int err; - - if (!aoview_flite) - aoview_flite = aoview_flite_start(); -} - -void aoview_voice_close(void) -{ - if (aoview_flite) { - aoview_flite_stop(); - aoview_flite = NULL; - } -} - -void aoview_voice_speak(char *format, ...) -{ - va_list ap; - - if (aoview_flite) { - va_start(ap, format); - vfprintf(aoview_flite, format, ap); - fflush(aoview_flite); - va_end(ap); - } -} - -#else -void aoview_voice_open(void) -{ -} - -void aoview_voice_close(void) -{ -} - -void aoview_voice_speak(char *format, ...) -{ -} -#endif - - -static GtkCheckMenuItem *voice_enable; - -#define ALTOS_VOICE_PATH "/apps/aoview/voice" - -static void -aoview_voice_enable(GtkWidget *widget, gpointer data) -{ - gboolean enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); - GError *error; - GConfClient *gconf_client; - - if (enabled) { - aoview_voice_open(); - aoview_voice_speak("enable voice\n"); - } else { - aoview_voice_speak("disable voice\n"); - aoview_voice_close(); - } - gconf_client = gconf_client_get_default(); - gconf_client_set_bool(gconf_client, - ALTOS_VOICE_PATH, - enabled, - &error); -} - -void -aoview_voice_init(GladeXML *xml) -{ - gboolean enabled; - GConfClient *gconf_client; - - voice_enable = GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "voice_enable")); - assert(voice_enable); - - gconf_client = gconf_client_get_default(); - enabled = TRUE; - if (gconf_client) - { - GError *error; - - error = NULL; - enabled = gconf_client_get_bool(gconf_client, - ALTOS_VOICE_PATH, - &error); - if (error) - enabled = TRUE; - } - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(voice_enable), enabled); - if (enabled) - aoview_voice_open(); - - g_signal_connect(G_OBJECT(voice_enable), "toggled", - G_CALLBACK(aoview_voice_enable), - voice_enable); -} diff --git a/ao-view/design b/ao-view/design deleted file mode 100644 index 6ec2ea70..00000000 --- a/ao-view/design +++ /dev/null @@ -1,27 +0,0 @@ -Requirements: - real-time display of telemetry - off-line display of logged data - Logging of telemetry - Capture of logged data to disk - -Input data: - accelerometer - barometer - thermometer - gps - drogue and main continuity - battery voltage - time - reported flight state - reported events - -Computed data: - velocity (from accelerometer) - altitude - range - direction - -Displays: - numeric display of current rocket status - (graphics come later) - text message log diff --git a/configure.ac b/configure.ac index b52bb6e9..dfbae71d 100644 --- a/configure.ac +++ b/configure.ac @@ -73,7 +73,6 @@ PKG_CHECK_MODULES([ALSA], [alsa]) AC_OUTPUT([ Makefile -ao-view/Makefile ao-tools/Makefile ao-tools/lib/Makefile ao-tools/ao-rawload/Makefile @@ -81,5 +80,6 @@ ao-tools/ao-dbg/Makefile ao-tools/ao-bitbang/Makefile ao-tools/ao-eeprom/Makefile ao-tools/ao-load/Makefile +ao-tools/ao-view/Makefile ao-utils/Makefile ]) -- cgit v1.2.3 From 0935d6a7e907e20381a42882ae728051f9bece02 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 4 Sep 2009 14:21:19 -0700 Subject: Parse the USB serial number as an integer. AltOS devices use simple integer serial numbers, so parse the USB value as such to make matching values more forgiving. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview_dev_dialog.c | 2 +- ao-tools/lib/cc-usbdev.c | 97 ++++++++++++++++++++++++++++++++++-- ao-tools/lib/cc.h | 5 +- 3 files changed, 98 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_dev_dialog.c b/ao-tools/ao-view/aoview_dev_dialog.c index 87396c1f..2ea43203 100644 --- a/ao-tools/ao-view/aoview_dev_dialog.c +++ b/ao-tools/ao-view/aoview_dev_dialog.c @@ -29,7 +29,7 @@ aoview_dev_dialog_map(GtkWidget *widget, gpointer data) list_store = gtk_list_store_new(3, G_TYPE_STRING, - G_TYPE_STRING, + G_TYPE_INT, G_TYPE_STRING); devs = cc_usbdevs_scan(); diff --git a/ao-tools/lib/cc-usbdev.c b/ao-tools/lib/cc-usbdev.c index d8bb8b11..ed39c062 100644 --- a/ao-tools/lib/cc-usbdev.c +++ b/ao-tools/lib/cc-usbdev.c @@ -16,8 +16,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#define _GNU_SOURCE #include "cc.h" - #include #include #include @@ -64,6 +64,23 @@ load_hex(char *dir, char *file) return i; } +static int +load_dec(char *dir, char *file) +{ + char *line; + char *end; + long i; + + line = load_string(dir, file); + if (!line) + return -1; + i = strtol(line, &end, 10); + free(line); + if (end == line) + return -1; + return i; +} + static int dir_filter_tty_colon(const struct dirent *d) { @@ -141,7 +158,7 @@ usb_scan_device(char *sys) usbdev->sys = strdup(sys); usbdev->manufacturer = load_string(sys, "manufacturer"); usbdev->product = load_string(sys, "product"); - usbdev->serial = load_string(sys, "serial"); + usbdev->serial = load_dec(sys, "serial"); usbdev->idProduct = load_hex(sys, "idProduct"); usbdev->idVendor = load_hex(sys, "idVendor"); usbdev->tty = usb_tty(sys); @@ -154,8 +171,9 @@ usbdev_free(struct cc_usbdev *usbdev) free(usbdev->sys); free(usbdev->manufacturer); free(usbdev->product); - free(usbdev->serial); - free(usbdev->tty); + /* this can get used as a return value */ + if (usbdev->tty) + free(usbdev->tty); free(usbdev); } @@ -226,3 +244,74 @@ cc_usbdevs_free(struct cc_usbdevs *usbdevs) usbdev_free(usbdevs->dev[i]); free(usbdevs); } + +static char * +match_dev(char *product, int serial) +{ + struct cc_usbdevs *devs; + struct cc_usbdev *dev; + int i; + char *tty = NULL; + + devs = cc_usbdevs_scan(); + if (!devs) + return NULL; + for (i = 0; i < devs->ndev; i++) { + dev = devs->dev[i]; + if (product && strcmp (product, dev->product) != 0) + continue; + if (serial && serial != dev->serial) + continue; + break; + } + if (i < devs->ndev) { + tty = devs->dev[i]->tty; + devs->dev[i]->tty = NULL; + } + cc_usbdevs_free(devs); + return tty; +} + +char * +cc_usbdevs_find_by_arg(char *arg, char *default_product) +{ + char *product; + int serial; + char *end; + char *colon; + char *tty; + + if (arg) + { + /* check for */ + serial = strtol(arg, &end, 0); + if (end != arg) { + if (*end != '\0') + return NULL; + product = NULL; + } else { + /* check for : */ + colon = strchr(arg, ':'); + if (colon) { + product = strndup(arg, colon - arg); + serial = strtol(colon + 1, &end, 0); + if (*end != '\0') + return NULL; + } else { + product = arg; + serial = 0; + } + } + } else { + product = NULL; + serial = 0; + } + tty = NULL; + if (!product && default_product) + tty = match_dev(default_product, serial); + if (!tty) + tty = match_dev(product, serial); + if (product && product != arg) + free(product); + return tty; +} diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index dad11bf3..0933f272 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -32,7 +32,7 @@ struct cc_usbdev { char *tty; char *manufacturer; char *product; - char *serial; + int serial; /* AltOS always uses simple integer serial numbers */ int idProduct; int idVendor; }; @@ -48,4 +48,7 @@ cc_usbdevs_free(struct cc_usbdevs *usbdevs); struct cc_usbdevs * cc_usbdevs_scan(void); +char * +cc_usbdevs_find_by_arg(char *arg, char *default_product); + #endif /* _CC_H_ */ -- cgit v1.2.3 From df88ae4c5f229efcc0ea5cb0a81fc2bb8f96fea2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 4 Sep 2009 14:23:02 -0700 Subject: Add 'ao-list' utility to show attached AltOS devices Signed-off-by: Keith Packard --- ao-tools/ao-list/Makefile.am | 12 ++++++++++++ ao-tools/ao-list/ao-list.1 | 32 ++++++++++++++++++++++++++++++++ ao-tools/ao-list/ao-list.c | 41 +++++++++++++++++++++++++++++++++++++++++ configure.ac | 1 + 4 files changed, 86 insertions(+) create mode 100644 ao-tools/ao-list/Makefile.am create mode 100644 ao-tools/ao-list/ao-list.1 create mode 100644 ao-tools/ao-list/ao-list.c (limited to 'ao-tools') diff --git a/ao-tools/ao-list/Makefile.am b/ao-tools/ao-list/Makefile.am new file mode 100644 index 00000000..de3c4deb --- /dev/null +++ b/ao-tools/ao-list/Makefile.am @@ -0,0 +1,12 @@ +bin_PROGRAMS=ao-list + +AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS) +AO_LIST_LIBS=$(top_builddir)/ao-tools/lib/libao-tools.a + +ao_list_DEPENDENCIES = $(AO_LIST_LIBS) + +ao_list_LDADD=$(AO_LIST_LIBS) $(LIBUSB_LIBS) + +ao_list_SOURCES = ao-list.c + +man_MANS = ao-list.1 diff --git a/ao-tools/ao-list/ao-list.1 b/ao-tools/ao-list/ao-list.1 new file mode 100644 index 00000000..03968c25 --- /dev/null +++ b/ao-tools/ao-list/ao-list.1 @@ -0,0 +1,32 @@ +/.\" +.\" 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-LIST 1 "ao-list" "" +.SH NAME +ao-list \- List connected AltOS devices +.SH SYNOPSIS +.B "ao-list" +.SH DESCRIPTION +.I ao-list +scans the attached USB devices, locates those running AltOS and +displays their product name and serial number along with the tty +device associated with the serial port over USB provided by AltOS. +.SH USAGE +.I ao-list +.SH AUTHOR +Keith Packard diff --git a/ao-tools/ao-list/ao-list.c b/ao-tools/ao-list/ao-list.c new file mode 100644 index 00000000..c4b43d8f --- /dev/null +++ b/ao-tools/ao-list/ao-list.c @@ -0,0 +1,41 @@ +/* + * 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; 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 "cc.h" + +int +main (int argc, char **argv) +{ + struct cc_usbdevs *devs; + struct cc_usbdev *dev; + int i; + + devs = cc_usbdevs_scan(); + if (devs) { + for (i = 0; i < devs->ndev; i++) { + dev = devs->dev[i]; + printf ("%-20.20s %6d %s\n", + dev->product, dev->serial, dev->tty); + } + cc_usbdevs_free(devs); + } + return 0; +} diff --git a/configure.ac b/configure.ac index dfbae71d..56402857 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,7 @@ ao-tools/ao-rawload/Makefile ao-tools/ao-dbg/Makefile ao-tools/ao-bitbang/Makefile ao-tools/ao-eeprom/Makefile +ao-tools/ao-list/Makefile ao-tools/ao-load/Makefile ao-tools/ao-view/Makefile ao-utils/Makefile -- cgit v1.2.3 From 332b056459b1352e233a8bf5f08498df12d32160 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 4 Sep 2009 15:01:32 -0700 Subject: 'fix' ao-eeprom to read two blocks at once. Work around kernel bugs. The kernel appears to leave serial data undelivered at times. Reading two blocks at once appears to make it relinquish the queued data. Signed-off-by: Keith Packard --- ao-tools/Makefile.am | 2 +- ao-tools/ao-eeprom/ao-eeprom.c | 20 ++++++++++++++------ ao-tools/lib/cc-usb.c | 12 +++++++++--- ao-tools/lib/cc-usb.h | 2 +- 4 files changed, 25 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 02b4785e..28e77b08 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-load ao-view +SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list ao-load ao-view diff --git a/ao-tools/ao-eeprom/ao-eeprom.c b/ao-tools/ao-eeprom/ao-eeprom.c index 726cc22c..b865e298 100644 --- a/ao-tools/ao-eeprom/ao-eeprom.c +++ b/ao-tools/ao-eeprom/ao-eeprom.c @@ -21,17 +21,19 @@ #include #include #include "cc-usb.h" +#include "cc.h" #define NUM_BLOCK 512 static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, + { .name = "device", .has_arg = 1, .val = 'D' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty ]\n", program); + fprintf(stderr, "usage: %s [--tty ] [--device \n", program); exit(1); } @@ -40,23 +42,29 @@ main (int argc, char **argv) { struct cc_usb *cc; int block; - uint8_t bytes[32 * (2 + 8)]; + uint8_t bytes[2 * 32 * (2 + 8)]; uint8_t *b; int i, j; uint32_t addr; char *tty = NULL; + char *device = NULL; int c; - while ((c = getopt_long(argc, argv, "T:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; break; + case 'D': + device = optarg; + break; default: usage(argv[0]); break; } } + if (!tty) + tty = cc_usbdevs_find_by_arg(device, "TeleMetrum"); if (!tty) tty = getenv("ALTOS_TTY"); if (!tty) @@ -64,11 +72,11 @@ main (int argc, char **argv) cc = cc_usb_open(tty); if (!cc) exit(1); - for (block = 0; block < NUM_BLOCK; block++) { + for (block = 0; block < NUM_BLOCK; block += 2) { cc_queue_read(cc, bytes, sizeof (bytes)); - cc_usb_printf(cc, "e %x\n", block); + cc_usb_printf(cc, "e %x\ne %x\n", block, block + 1); cc_usb_sync(cc); - for (i = 0; i < 32; i++) { + for (i = 0; i < 32 * 2; i++) { b = bytes + (i * 10); addr = block * 256 + i * 8; printf ("%06x", addr); diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index 81309983..17f05911 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -157,7 +157,8 @@ cc_usb_dbg(int indent, uint8_t *bytes, int len) /* * Flush pending writes, fill pending reads */ -void + +int cc_usb_sync(struct cc_usb *cc) { int ret; @@ -167,7 +168,7 @@ cc_usb_sync(struct cc_usb *cc) fds.fd = cc->fd; for (;;) { if (cc->read_count || cc->out_count) - timeout = -1; + timeout = 5000; else timeout = 0; fds.events = 0; @@ -176,8 +177,13 @@ cc_usb_sync(struct cc_usb *cc) if (cc->out_count) fds.events |= POLLOUT; ret = poll(&fds, 1, timeout); - if (ret == 0) + if (ret == 0) { + if (timeout) { + fprintf(stderr, "USB link timeout\n"); + exit(1); + } break; + } if (ret < 0) { perror("poll"); break; diff --git a/ao-tools/lib/cc-usb.h b/ao-tools/lib/cc-usb.h index d7acfbd2..9baabd95 100644 --- a/ao-tools/lib/cc-usb.h +++ b/ao-tools/lib/cc-usb.h @@ -47,7 +47,7 @@ cc_usb_debug_mode(struct cc_usb *cc); int cc_usb_reset(struct cc_usb *cc); -void +int cc_usb_sync(struct cc_usb *cc); void -- cgit v1.2.3 From 73adae3661160d410dcc802873b530d255c210e5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 4 Sep 2009 15:30:22 -0700 Subject: Add --device/-D support to the command line tools and manuals Use the new cc_usbdevs_find_by_arg function to locate suitable target devices connected via USB. Signed-off-by: Keith Packard --- ao-tools/ao-dbg/ao-dbg-main.c | 5 +++++ ao-tools/ao-dbg/ao-dbg-parse.c | 5 +++++ ao-tools/ao-dbg/ao-dbg.1 | 20 +++++++++++++++++++- ao-tools/ao-dbg/ao-dbg.h | 2 ++ ao-tools/ao-eeprom/ao-eeprom.1 | 26 +++++++++++++++++++++++++- ao-tools/ao-load/ao-load.1 | 26 +++++++++++++++++++++++++- ao-tools/ao-load/ao-load.c | 12 ++++++++++-- ao-tools/ao-rawload/ao-rawload.1 | 26 +++++++++++++++++++++++++- ao-tools/ao-rawload/ao-rawload.c | 11 +++++++++-- 9 files changed, 125 insertions(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-dbg/ao-dbg-main.c b/ao-tools/ao-dbg/ao-dbg-main.c index f1e2c111..21b83a3d 100644 --- a/ao-tools/ao-dbg/ao-dbg-main.c +++ b/ao-tools/ao-dbg/ao-dbg-main.c @@ -34,6 +34,7 @@ struct ccdbg *s51_dbg; int s51_interrupted = 0; int s51_monitor = 0; char *s51_tty = NULL; +char *s51_device = NULL; static FILE *s51_input; static FILE *s51_output; @@ -52,6 +53,7 @@ void s51_sigint() static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, + { .name = "device", .has_arg = 1, .val = 'D' }, { 0, 0, 0, 0 }, }; @@ -114,6 +116,9 @@ main(int argc, char **argv) case 'T': s51_tty = optarg; break; + case 'D': + s51_device = optarg; + break; } } if (s51_port) { diff --git a/ao-tools/ao-dbg/ao-dbg-parse.c b/ao-tools/ao-dbg/ao-dbg-parse.c index 825d0e9c..dcb9099d 100644 --- a/ao-tools/ao-dbg/ao-dbg-parse.c +++ b/ao-tools/ao-dbg/ao-dbg-parse.c @@ -195,6 +195,11 @@ command_read (void) enum command_result result; struct command_function *func; + if (!s51_tty) { + if (!s51_device) + s51_device = getenv("AO_DBG_DEVICE"); + s51_tty = cc_usbdevs_find_by_arg(s51_device, "TIDongle"); + } s51_dbg = ccdbg_open (s51_tty); if (!s51_dbg) exit(1); diff --git a/ao-tools/ao-dbg/ao-dbg.1 b/ao-tools/ao-dbg/ao-dbg.1 index a850c454..00d3ac86 100644 --- a/ao-tools/ao-dbg/ao-dbg.1 +++ b/ao-tools/ao-dbg/ao-dbg.1 @@ -35,6 +35,9 @@ ao-dbg \- hex debugger for cc1111 processors [\-h] [\-m] [\-T \fItty-device\fP] +[\--tty \fItty-device\fP] +[\-D \fIaltos-device\fP] +[\--device \fIaltos-device\fP] .SH DESCRIPTION .I ao-dbg connects to a cc1111 processor through either a suitable cc1111 board @@ -80,11 +83,26 @@ This should print a usage message, but does nothing useful currently. .IP "\-m" This option is not present in the original 8051 emulator, and causes ao-dbg to dump all commands and replies that are received from and sent to sdcdb. -.IP "\-T" +.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 +TeleMetrum:2 +.br +TeleMetrum +.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 COMMANDS Once started, ao-dbg connects to the cc1111 and then reads and executes commands, either from stdin, or the nework connection to diff --git a/ao-tools/ao-dbg/ao-dbg.h b/ao-tools/ao-dbg/ao-dbg.h index c1789d10..edc650a5 100644 --- a/ao-tools/ao-dbg/ao-dbg.h +++ b/ao-tools/ao-dbg/ao-dbg.h @@ -17,12 +17,14 @@ */ #include +#include extern char *s51_prompt; extern struct ccdbg *s51_dbg; extern int s51_interrupted; extern int s51_monitor; extern char *s51_tty; +extern char *s51_device; enum command_result { command_success, command_debug, command_syntax, command_interrupt, command_error, diff --git a/ao-tools/ao-eeprom/ao-eeprom.1 b/ao-tools/ao-eeprom/ao-eeprom.1 index 8caff9d1..ed498147 100644 --- a/ao-tools/ao-eeprom/ao-eeprom.1 +++ b/ao-tools/ao-eeprom/ao-eeprom.1 @@ -21,7 +21,31 @@ ao-eeprom \- Fetch eeprom contents from TeleMetrum device .SH SYNOPSIS .B "ao-eeprom" -[\-tty \fItty-device\fP] +[\-T \fItty-device\fP] +[\--tty \fItty-device\fP] +[\-D \fIaltos-device\fP] +[\--device \fIaltos-device\fP] +.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 +TeleMetrum:2 +.br +TeleMetrum +.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 DESCRIPTION .I ao-eeprom downloads the eeprom contents from a connected TeleMetrum device. diff --git a/ao-tools/ao-load/ao-load.1 b/ao-tools/ao-load/ao-load.1 index 10484f3b..eb2bc0d8 100644 --- a/ao-tools/ao-load/ao-load.1 +++ b/ao-tools/ao-load/ao-load.1 @@ -21,13 +21,37 @@ ao-load \- flash a program to a AltOS device .SH SYNOPSIS .B "ao-load" -[\-tty \fItty-device\fP] +[\-T \fItty-device\fP] +[\--tty \fItty-device\fP] +[\-D \fIaltos-device\fP] +[\--device \fIaltos-device\fP] \fIfile.ihx\fP \fIdevice serial number\fP .SH DESCRIPTION .I ao-load loads the specified .ihx file into the target device flash memory, customizing the AltOS image with the specified serial number. +.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 +TeleMetrum:2 +.br +TeleMetrum +.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-load reads the specified .ihx file into memory, locates the matching .map diff --git a/ao-tools/ao-load/ao-load.c b/ao-tools/ao-load/ao-load.c index c27fcbe9..f5466612 100644 --- a/ao-tools/ao-load/ao-load.c +++ b/ao-tools/ao-load/ao-load.c @@ -22,6 +22,7 @@ #include #include #include "ccdbg.h" +#include "cc.h" #define AO_USB_DESC_STRING 3 @@ -91,12 +92,13 @@ rewrite(struct hex_image *image, unsigned addr, char *data, int len) static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, + { .name = "device", .has_arg = 1, .val = 'D' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty ] file.ihx serial-number\n", program); + fprintf(stderr, "usage: %s [--tty ] [--device ] file.ihx serial-number\n", program); exit(1); } @@ -122,13 +124,17 @@ main (int argc, char **argv) unsigned usb_descriptors; int string_num; char *tty = NULL; + char *device = NULL; int c; - while ((c = getopt_long(argc, argv, "T:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; break; + case 'D': + device = optarg; + break; default: usage(argv[0]); break; @@ -219,6 +225,8 @@ main (int argc, char **argv) if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len)) usage(argv[0]); + if (!tty) + tty = cc_usbdevs_find_by_arg(device, "TIDongle"); dbg = ccdbg_open(tty); if (!dbg) exit (1); diff --git a/ao-tools/ao-rawload/ao-rawload.1 b/ao-tools/ao-rawload/ao-rawload.1 index e79645f1..6b6a6e2c 100644 --- a/ao-tools/ao-rawload/ao-rawload.1 +++ b/ao-tools/ao-rawload/ao-rawload.1 @@ -21,12 +21,36 @@ ao-rawload \- flash a program to a AltOS device .SH SYNOPSIS .B "ao-rawload" -[\-tty \fItty-device\fP] +[\-T \fItty-device\fP] +[\--tty \fItty-device\fP] +[\-D \fIaltos-device\fP] +[\--device \fIaltos-device\fP] \fIfile.ihx\fP .SH DESCRIPTION .I ao-rawload loads the specified .ihx file, without modification, into the target device flash memory. +.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 +TeleMetrum:2 +.br +TeleMetrum +.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-rawload reads the specified .ihx file into memory. It then connects to the diff --git a/ao-tools/ao-rawload/ao-rawload.c b/ao-tools/ao-rawload/ao-rawload.c index 1f1537b9..255f63ec 100644 --- a/ao-tools/ao-rawload/ao-rawload.c +++ b/ao-tools/ao-rawload/ao-rawload.c @@ -22,12 +22,13 @@ static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, + { .name = "device", .has_arg = 1, .val = 'D' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty ] file.ihx\n", program); + fprintf(stderr, "usage: %s [--tty ] [--device ] file.ihx\n", program); exit(1); } @@ -42,13 +43,17 @@ main (int argc, char **argv) char *filename; FILE *file; char *tty = NULL; + char *device = NULL; int c; - while ((c = getopt_long(argc, argv, "T:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; break; + case 'D': + device = optarg; + break; default: usage(argv[0]); break; @@ -75,6 +80,8 @@ main (int argc, char **argv) } ccdbg_hex_file_free(hex); + if (!tty) + tty = cc_usbdevs_find_by_arg(device, "TIDongle"); dbg = ccdbg_open(tty); if (!dbg) exit (1); -- cgit v1.2.3 From 26f56b51bd11aa91f1d77b81827b49c28cb6ec5f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 5 Sep 2009 00:29:26 -0700 Subject: Add ao-dumplog to capture flight log from command line This duplicates the functionality of the flight log stuf in ao-view, except from the command line where it belongs. Signed-off-by: Keith Packard --- ao-tools/Makefile.am | 2 +- ao-tools/ao-dumplog/Makefile.am | 12 +++ ao-tools/ao-dumplog/ao-dumplog.1 | 68 ++++++++++++++++ ao-tools/ao-dumplog/ao-dumplog.c | 103 ++++++++++++++++++++++++ ao-tools/lib/Makefile.am | 3 +- ao-tools/lib/cc-usb.c | 164 +++++++++++++++++++++++++-------------- ao-tools/lib/cc-usb.h | 8 +- ao-tools/lib/cc.h | 9 +++ configure.ac | 1 + 9 files changed, 308 insertions(+), 62 deletions(-) create mode 100644 ao-tools/ao-dumplog/Makefile.am create mode 100644 ao-tools/ao-dumplog/ao-dumplog.1 create mode 100644 ao-tools/ao-dumplog/ao-dumplog.c (limited to 'ao-tools') diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 28e77b08..b61f045f 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list ao-load ao-view +SUBDIRS=lib ao-rawload ao-dbg ao-dumplog ao-bitbang ao-eeprom ao-list ao-load ao-view diff --git a/ao-tools/ao-dumplog/Makefile.am b/ao-tools/ao-dumplog/Makefile.am new file mode 100644 index 00000000..a80cac33 --- /dev/null +++ b/ao-tools/ao-dumplog/Makefile.am @@ -0,0 +1,12 @@ +bin_PROGRAMS=ao-dumplog + +AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS) $(GNOME_CFLAGS) +AO_DUMPLOG_LIBS=$(top_builddir)/ao-tools/lib/libao-tools.a + +ao_dumplog_DEPENDENCIES = $(AO_DUMPLOG_LIBS) + +ao_dumplog_LDADD=$(AO_DUMPLOG_LIBS) $(LIBUSB_LIBS) $(GNOME_LIBS) + +ao_dumplog_SOURCES = ao-dumplog.c + +man_MANS = ao-dumplog.1 diff --git a/ao-tools/ao-dumplog/ao-dumplog.1 b/ao-tools/ao-dumplog/ao-dumplog.1 new file mode 100644 index 00000000..8c2df7c6 --- /dev/null +++ b/ao-tools/ao-dumplog/ao-dumplog.1 @@ -0,0 +1,68 @@ +.\" +.\" 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-DUMPLOG 1 "ao-dumplog" "" +.SH NAME +ao-dumplog \- Store flight log from TeleMetrum device +.SH SYNOPSIS +.B "ao-dumplog" +[\-T \fItty-device\fP] +[\--tty \fItty-device\fP] +[\-D \fIaltos-device\fP] +[\--device \fIaltos-device\fP] +.SH OPTIONS +.TP +\-T tty-device | --tty tty-device +This selects which tty device ao-dumplog uses to communicate with +the target device. +.TP +\-D AltOS-device | --device AltOS-device +Search for a connected device. This requires an argument of one of the +following forms: +.IP +TeleMetrum:2 +.br +TeleMetrum +.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 DESCRIPTION +.I ao-dumplog +downloads the flight log from a connected TeleMetrum device and stores +it to the configured flight log directory using a name of the form +.IP +\fIyyyy\fP-\fImm\fP-\fIdd\fP-serialP-\fIsss\fP-flight-\fIfff\fP.eeprom +.PP +\fIyyyy\fP is the current year +.br +\fImm\fP is the current month +.br +\fIdd\fP is the current day +.br +\fIsss\fP is the device serial number +.br +\fIfff\fP is a flight sequence number (to make filenames unique) +.SH USAGE +.I ao-dumplog +connects to the specified target device and dumps the stored flight +log. +.SH AUTHOR +Keith Packard diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c new file mode 100644 index 00000000..4bccfd61 --- /dev/null +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -0,0 +1,103 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include "cc-usb.h" +#include "cc.h" + +#define NUM_BLOCK 512 + +static const struct option options[] = { + { .name = "tty", .has_arg = 1, .val = 'T' }, + { .name = "device", .has_arg = 1, .val = 'D' }, + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s [--tty ] [--device \n", program); + exit(1); +} + +int +main (int argc, char **argv) +{ + struct cc_usb *cc; + char *tty = NULL; + char *device = NULL; + int c; + char line[8192]; + FILE *out; + char *filename; + int serial_number; + char cmd; + int tick, a, b; + + while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { + switch (c) { + case 'T': + tty = optarg; + break; + case 'D': + device = optarg; + break; + default: + usage(argv[0]); + break; + } + } + if (!tty) + tty = cc_usbdevs_find_by_arg(device, "TeleMetrum"); + if (!tty) + tty = getenv("ALTOS_TTY"); + if (!tty) + tty="/dev/ttyACM0"; + cc = cc_usb_open(tty); + if (!cc) + exit(1); + /* send a 'version' command followed by a 'log' command */ + cc_usb_printf(cc, "v\nl\n"); + out = NULL; + for (;;) { + cc_usb_getline(cc, line, sizeof (line)); + if (!strcmp (line, "end")) + break; + if (sscanf(line, "serial-number %u", &serial_number) == 1) { + filename = cc_make_filename(serial_number, "eeprom"); + out = fopen (filename, "w"); + if (!out) { + perror(filename); + } + } else if (sscanf(line, "%c %x %x %x", &cmd, &tick, &a, &b) == 4) { + if (out) { + fprintf(out, "%s\n", line); + if (cmd == 'S' && a == 8) { + fclose(out); + out = NULL; + } + } + } + } + if (out) + fclose (out); + cc_usb_close(cc); + exit (0); +} diff --git a/ao-tools/lib/Makefile.am b/ao-tools/lib/Makefile.am index f66ee0a9..da13ede9 100644 --- a/ao-tools/lib/Makefile.am +++ b/ao-tools/lib/Makefile.am @@ -1,6 +1,6 @@ noinst_LIBRARIES = libao-tools.a -AM_CFLAGS=$(WARN_CFLAGS) $(LIBUSB_CFLAGS) +AM_CFLAGS=$(WARN_CFLAGS) $(LIBUSB_CFLAGS) $(GNOME_CFLAGS) libao_tools_a_SOURCES = \ ccdbg-command.c \ @@ -14,6 +14,7 @@ libao_tools_a_SOURCES = \ ccdbg-memory.c \ ccdbg-rom.c \ ccdbg-state.c \ + cc-log.c \ cc-usb.c \ cc-usb.h \ cc.h \ diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index 17f05911..80d9c04f 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -30,27 +30,29 @@ #include "cc-usb.h" -#define CC_NUM_READ 16 +#define CC_NUM_HEX_READ 64 /* * AltOS has different buffer sizes for in/out packets */ -#define CC_IN_BUF 256 +#define CC_IN_BUF 65536 #define CC_OUT_BUF 64 #define DEFAULT_TTY "/dev/ttyACM0" -struct cc_read { +struct cc_hex_read { uint8_t *buf; int len; }; struct cc_usb { - int fd; - uint8_t in_buf[CC_IN_BUF]; - int in_count; - uint8_t out_buf[CC_OUT_BUF]; - int out_count; - struct cc_read read_buf[CC_NUM_READ]; - int read_count; + int fd; + uint8_t in_buf[CC_IN_BUF]; + int in_pos; + int in_count; + uint8_t out_buf[CC_OUT_BUF]; + int out_count; + + struct cc_hex_read hex_buf[CC_NUM_HEX_READ]; + int hex_count; }; #define NOT_HEX 0xff @@ -72,61 +74,48 @@ cc_hex_nibble(uint8_t c) * and write them to the waiting buffer */ static void -cc_handle_in(struct cc_usb *cc) +cc_handle_hex_read(struct cc_usb *cc) { uint8_t h, l; - int in_pos; - int read_pos; + int hex_pos; - in_pos = 0; - read_pos = 0; - while (read_pos < cc->read_count && in_pos < cc->in_count) { + hex_pos = 0; + while (hex_pos < cc->hex_count && cc->in_pos < cc->in_count) { /* * Skip to next hex character */ - while (in_pos < cc->in_count && - cc_hex_nibble(cc->in_buf[in_pos]) == NOT_HEX) - in_pos++; + while (cc->in_pos < cc->in_count && + cc_hex_nibble(cc->in_buf[cc->in_pos]) == NOT_HEX) + cc->in_pos++; /* * Make sure we have two characters left */ - if (cc->in_count - in_pos < 2) + if (cc->in_count - cc->in_pos < 2) break; /* * Parse hex number */ - h = cc_hex_nibble(cc->in_buf[in_pos]); - l = cc_hex_nibble(cc->in_buf[in_pos+1]); + h = cc_hex_nibble(cc->in_buf[cc->in_pos]); + l = cc_hex_nibble(cc->in_buf[cc->in_pos+1]); if (h == NOT_HEX || l == NOT_HEX) { fprintf(stderr, "hex read error\n"); break; } - in_pos += 2; + cc->in_pos += 2; /* * Store hex number */ - *cc->read_buf[read_pos].buf++ = (h << 4) | l; - if (--cc->read_buf[read_pos].len <= 0) - read_pos++; - } - - /* Move remaining bytes to the start of the input buffer */ - if (in_pos) { - memmove(cc->in_buf, cc->in_buf + in_pos, - cc->in_count - in_pos); - cc->in_count -= in_pos; + *cc->hex_buf[hex_pos].buf++ = (h << 4) | l; + if (--cc->hex_buf[hex_pos].len <= 0) + hex_pos++; } - /* Move pending reads to the start of the array */ - if (read_pos) { - memmove(cc->read_buf, cc->read_buf + read_pos, - (cc->read_count - read_pos) * sizeof (cc->read_buf[0])); - cc->read_count -= read_pos; + /* Move pending hex reads to the start of the array */ + if (hex_pos) { + memmove(cc->hex_buf, cc->hex_buf + hex_pos, + (cc->hex_count - hex_pos) * sizeof (cc->hex_buf[0])); + cc->hex_count -= hex_pos; } - - /* Once we're done reading, flush any pending input */ - if (cc->read_count == 0) - cc->in_count = 0; } static void @@ -158,8 +147,8 @@ cc_usb_dbg(int indent, uint8_t *bytes, int len) * Flush pending writes, fill pending reads */ -int -cc_usb_sync(struct cc_usb *cc) +static int +_cc_usb_sync(struct cc_usb *cc, int wait_for_input) { int ret; struct pollfd fds; @@ -167,26 +156,33 @@ cc_usb_sync(struct cc_usb *cc) fds.fd = cc->fd; for (;;) { - if (cc->read_count || cc->out_count) + if (cc->hex_count || cc->out_count) timeout = 5000; + else if (wait_for_input && cc->in_pos == cc->in_count) + timeout = wait_for_input; else timeout = 0; fds.events = 0; + /* Move remaining bytes to the start of the input buffer */ + if (cc->in_pos) { + memmove(cc->in_buf, cc->in_buf + cc->in_pos, + cc->in_count - cc->in_pos); + cc->in_count -= cc->in_pos; + cc->in_pos = 0; + } if (cc->in_count < CC_IN_BUF) fds.events |= POLLIN; if (cc->out_count) fds.events |= POLLOUT; ret = poll(&fds, 1, timeout); if (ret == 0) { - if (timeout) { - fprintf(stderr, "USB link timeout\n"); - exit(1); - } + if (timeout) + return -1; break; } if (ret < 0) { perror("poll"); - break; + return -1; } if (fds.revents & POLLIN) { ret = read(cc->fd, cc->in_buf + cc->in_count, @@ -194,7 +190,8 @@ cc_usb_sync(struct cc_usb *cc) if (ret > 0) { cc_usb_dbg(24, cc->in_buf + cc->in_count, ret); cc->in_count += ret; - cc_handle_in(cc); + if (cc->hex_count) + cc_handle_hex_read(cc); } else if (ret < 0) perror("read"); } @@ -211,6 +208,16 @@ cc_usb_sync(struct cc_usb *cc) perror("write"); } } + return 0; +} + +void +cc_usb_sync(struct cc_usb *cc) +{ + if (_cc_usb_sync(cc, 0) < 0) { + fprintf(stderr, "USB link timeout\n"); + exit(1); + } } void @@ -244,6 +251,38 @@ cc_usb_printf(struct cc_usb *cc, char *format, ...) } } +int +cc_usb_getchar(struct cc_usb *cc) +{ + while (cc->in_pos == cc->in_count) { + if (_cc_usb_sync(cc, 5000) < 0) { + fprintf(stderr, "USB link timeout\n"); + exit(1); + } + } + return cc->in_buf[cc->in_pos++]; +} + +void +cc_usb_getline(struct cc_usb *cc, char *line, int max) +{ + int c; + + while ((c = cc_usb_getchar(cc)) != '\n') { + switch (c) { + case '\r': + break; + default: + if (max > 1) { + *line++ = c; + max--; + } + break; + } + } + *line++ = '\0'; +} + int cc_usb_send_bytes(struct cc_usb *cc, uint8_t *bytes, int len) { @@ -266,12 +305,18 @@ cc_usb_send_bytes(struct cc_usb *cc, uint8_t *bytes, int len) void cc_queue_read(struct cc_usb *cc, uint8_t *buf, int len) { - struct cc_read *read_buf; - while (cc->read_count >= CC_NUM_READ) + struct cc_hex_read *hex_buf; + + /* At the start of a command sequence, flush any pending input */ + if (cc->hex_count == 0) { cc_usb_sync(cc); - read_buf = &cc->read_buf[cc->read_count++]; - read_buf->buf = buf; - read_buf->len = len; + cc->in_count = 0; + } + while (cc->hex_count >= CC_NUM_HEX_READ) + cc_usb_sync(cc); + hex_buf = &cc->hex_buf[cc->hex_count++]; + hex_buf->buf = buf; + hex_buf->len = len; } int @@ -351,9 +396,10 @@ cc_usb_open(char *tty) cfmakeraw(&termios); tcsetattr(cc->fd, TCSAFLUSH, &termios); cc_usb_printf(cc, "E 0\nm 0\n"); - cc_usb_sync(cc); - sleep(1); - cc_usb_sync(cc); + do { + cc->in_count = cc->in_pos = 0; + _cc_usb_sync(cc, 100); + } while (cc->in_count > 0); return cc; } diff --git a/ao-tools/lib/cc-usb.h b/ao-tools/lib/cc-usb.h index 9baabd95..7b6be350 100644 --- a/ao-tools/lib/cc-usb.h +++ b/ao-tools/lib/cc-usb.h @@ -47,12 +47,18 @@ cc_usb_debug_mode(struct cc_usb *cc); int cc_usb_reset(struct cc_usb *cc); -int +void cc_usb_sync(struct cc_usb *cc); void cc_queue_read(struct cc_usb *cc, uint8_t *buf, int len); +int +cc_usb_getchar(struct cc_usb *cc); + +void +cc_usb_getline(struct cc_usb *cc, char *line, int max); + void cc_usb_printf(struct cc_usb *cc, char *format, ...); diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 0933f272..f92a29f7 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -51,4 +51,13 @@ cc_usbdevs_scan(void); char * cc_usbdevs_find_by_arg(char *arg, char *default_product); +void +cc_set_log_dir(char *dir); + +char * +cc_get_log_dir(void); + +char * +cc_make_filename(int serial, char *ext); + #endif /* _CC_H_ */ diff --git a/configure.ac b/configure.ac index 56402857..73a33ac3 100644 --- a/configure.ac +++ b/configure.ac @@ -77,6 +77,7 @@ ao-tools/Makefile ao-tools/lib/Makefile ao-tools/ao-rawload/Makefile ao-tools/ao-dbg/Makefile +ao-tools/ao-dumplog/Makefile ao-tools/ao-bitbang/Makefile ao-tools/ao-eeprom/Makefile ao-tools/ao-list/Makefile -- cgit v1.2.3 From c46e832b28820d7c5be4efaacbbd7c0607927fe5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 5 Sep 2009 22:03:31 -0700 Subject: Add simple post-flight analysis tool (ao-postflight) This tool reads either an eeprom or telem log file and displays some rudimentary data (max accel/alt for each flight stage). Signed-off-by: Keith Packard --- .gitignore | 4 + ao-tools/Makefile.am | 2 +- ao-tools/ao-dumplog/ao-dumplog.c | 1 + ao-tools/ao-postflight/Makefile.am | 12 ++ ao-tools/ao-postflight/ao-postflight.1 | 29 ++++ ao-tools/ao-postflight/ao-postflight.c | 166 ++++++++++++++++++++ ao-tools/lib/Makefile.am | 4 + ao-tools/lib/cc-analyse.c | 58 +++++++ ao-tools/lib/cc-convert.c | 275 +++++++++++++++++++++++++++++++++ ao-tools/lib/cc-log.c | 114 ++++++++++++++ ao-tools/lib/cc-logfile.c | 218 ++++++++++++++++++++++++++ ao-tools/lib/cc-telem.c | 164 ++++++++++++++++++++ ao-tools/lib/cc-util.c | 2 +- ao-tools/lib/cc.h | 207 +++++++++++++++++++++++++ configure.ac | 1 + 15 files changed, 1255 insertions(+), 2 deletions(-) create mode 100644 ao-tools/ao-postflight/Makefile.am create mode 100644 ao-tools/ao-postflight/ao-postflight.1 create mode 100644 ao-tools/ao-postflight/ao-postflight.c create mode 100644 ao-tools/lib/cc-analyse.c create mode 100644 ao-tools/lib/cc-convert.c create mode 100644 ao-tools/lib/cc-log.c create mode 100644 ao-tools/lib/cc-logfile.c create mode 100644 ao-tools/lib/cc-telem.c (limited to 'ao-tools') diff --git a/.gitignore b/.gitignore index b3d2d562..0ca4bed4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,9 +22,13 @@ ao-teleterra.h ao-tidongle.h ao-tools/ao-bitbang/ao-bitbang ao-tools/ao-dbg/ao-dbg +ao-tools/ao-dumplog/ao-dumplog ao-tools/ao-eeprom/ao-eeprom +ao-tools/ao-list/ao-list ao-tools/ao-load/ao-load +ao-tools/ao-postflight/ao-postflight ao-tools/ao-rawload/ao-rawload +ao-tools/ao-view/ao-view ao-view/Makefile ao-view/ao-view autom4te.cache diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index b61f045f..2850e909 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-dumplog ao-bitbang ao-eeprom ao-list ao-load ao-view +SUBDIRS=lib ao-rawload ao-dbg ao-dumplog ao-bitbang ao-eeprom ao-list ao-load ao-postflight ao-view diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c index 4bccfd61..b930f0e5 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.c +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -86,6 +86,7 @@ main (int argc, char **argv) if (!out) { perror(filename); } + fprintf (out, "%s\n", line); } else if (sscanf(line, "%c %x %x %x", &cmd, &tick, &a, &b) == 4) { if (out) { fprintf(out, "%s\n", line); diff --git a/ao-tools/ao-postflight/Makefile.am b/ao-tools/ao-postflight/Makefile.am new file mode 100644 index 00000000..301ac454 --- /dev/null +++ b/ao-tools/ao-postflight/Makefile.am @@ -0,0 +1,12 @@ +bin_PROGRAMS=ao-postflight + +AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS) $(GNOME_CFLAGS) +AO_POSTFLIGHT_LIBS=$(top_builddir)/ao-tools/lib/libao-tools.a + +ao_postflight_DEPENDENCIES = $(AO_POSTFLIGHT_LIBS) + +ao_postflight_LDADD=$(AO_POSTFLIGHT_LIBS) $(LIBUSB_LIBS) $(GNOME_LIBS) + +ao_postflight_SOURCES = ao-postflight.c + +man_MANS = ao-postflight.1 diff --git a/ao-tools/ao-postflight/ao-postflight.1 b/ao-tools/ao-postflight/ao-postflight.1 new file mode 100644 index 00000000..fe02587f --- /dev/null +++ b/ao-tools/ao-postflight/ao-postflight.1 @@ -0,0 +1,29 @@ +.\" +.\" 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-POSTFLIGHT 1 "ao-postflight" "" +.SH NAME +ao-postflight \- Analyse a flight log (either telemetry or eeprom) +.SH SYNOPSIS +.B "ao-postflight" +{flight.eeprom|flight.telem} +.SH DESCRIPTION +.I ao-postflight +reads the specified flight log and produces a summary of the flight on stdout. +.SH AUTHOR +Keith Packard diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c new file mode 100644 index 00000000..f0e2c2ae --- /dev/null +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -0,0 +1,166 @@ +/* + * 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. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include "cc-usb.h" +#include "cc.h" + +#define NUM_BLOCK 512 + +static const struct option options[] = { + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s {flight-log} ...\n", program); + exit(1); +} + +static const char *state_names[] = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid" +}; + +void +analyse_flight(struct cc_flightraw *f) +{ + double height; + double accel; + double boost_start, boost_stop; + double min_pres; + int i; + int pres_i, accel_i; + int boost_start_set = 0; + int boost_stop_set = 0; + enum ao_flight_state state; + double state_start, state_stop; + + printf ("Flight: %9d\nSerial: %9d\n", + f->flight, f->serial); + boost_start = f->accel.data[0].time; + boost_stop = f->accel.data[f->accel.num-1].time; + for (i = 0; i < f->state.num; i++) { + if (f->state.data[i].value == ao_flight_boost && !boost_start_set) { + boost_start = f->state.data[i].time; + boost_start_set = 1; + } + if (f->state.data[i].value > ao_flight_boost && !boost_stop_set) { + boost_stop = f->state.data[i].time; + boost_stop_set = 1; + } + } + + pres_i = cc_timedata_min(&f->pres, f->pres.data[0].time, + f->pres.data[f->pres.num-1].time); + min_pres = f->pres.data[pres_i].value; + height = cc_barometer_to_altitude(min_pres) - + cc_barometer_to_altitude(f->ground_pres); + printf ("Max height: %9.2fm %9.2fft %9.2fs\n", + height, height * 100 / 2.54 / 12, + (f->pres.data[pres_i].time - boost_start) / 100.0); + + accel_i = cc_timedata_min(&f->accel, boost_start, boost_stop); + accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, + f->ground_accel); + printf ("Max accel: %9.2fm/s² %9.2fg %9.2fs\n", + accel, accel / 9.80665, + (f->accel.data[accel_i].time - boost_start) / 100.0); + for (i = 0; i < f->state.num; i++) { + state = f->state.data[i].value; + state_start = f->state.data[i].time; + if (i < f->state.num - 1) + state_stop = f->state.data[i+1].time; + else + state_stop = f->accel.data[f->accel.num-1].time; + printf("State: %s\n", state_names[state]); + printf("\tStart: %9.2fs\n", (state_start - boost_start) / 100.0); + printf("\tDuration: %9.2fs\n", (state_stop - state_start) / 100.0); + accel_i = cc_timedata_min(&f->accel, state_start, state_stop); + accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, + f->ground_accel); + printf("\tMax accel: %9.2fm/s² %9.2fg %9.2fs\n", + accel, accel / 9.80665, + (f->accel.data[accel_i].time - boost_start) / 100.0); + + pres_i = cc_timedata_min(&f->pres, state_start, state_stop); + min_pres = f->pres.data[pres_i].value; + height = cc_barometer_to_altitude(min_pres) - + cc_barometer_to_altitude(f->ground_pres); + printf ("\tMax height: %9.2fm %9.2fft %9.2fs\n", + height, height * 100 / 2.54 / 12, + (f->pres.data[pres_i].time - boost_start) / 100.0); + } +} + +int +main (int argc, char **argv) +{ + FILE *file; + int i; + int ret = 0; + struct cc_flightraw *raw; + int c; + int serial; + char *s; + + while ((c = getopt_long(argc, argv, "", options, NULL)) != -1) { + switch (c) { + default: + usage(argv[0]); + break; + } + } + for (i = optind; i < argc; i++) { + file = fopen(argv[i], "r"); + if (!file) { + perror(argv[i]); + ret++; + continue; + } + s = strstr(argv[i], "-serial-"); + if (s) + serial = atoi(s + 8); + else + serial = 0; + raw = cc_log_read(file); + if (!raw) { + perror(argv[i]); + ret++; + continue; + } + if (!raw->serial) + raw->serial = serial; + analyse_flight(raw); + cc_flightraw_free(raw); + } + return ret; +} diff --git a/ao-tools/lib/Makefile.am b/ao-tools/lib/Makefile.am index da13ede9..e682f757 100644 --- a/ao-tools/lib/Makefile.am +++ b/ao-tools/lib/Makefile.am @@ -14,6 +14,8 @@ libao_tools_a_SOURCES = \ ccdbg-memory.c \ ccdbg-rom.c \ ccdbg-state.c \ + cc-analyse.c \ + cc-convert.c \ cc-log.c \ cc-usb.c \ cc-usb.h \ @@ -22,5 +24,7 @@ libao_tools_a_SOURCES = \ cc-util.c \ cc-bitbang.c \ cc-bitbang.h \ + cc-logfile.c \ + cc-telem.c \ cp-usb-async.c \ cp-usb-async.h diff --git a/ao-tools/lib/cc-analyse.c b/ao-tools/lib/cc-analyse.c new file mode 100644 index 00000000..6fd36cdc --- /dev/null +++ b/ao-tools/lib/cc-analyse.c @@ -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; 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 "cc.h" + +int +cc_timedata_min(struct cc_timedata *d, double min_time, double max_time) +{ + int i; + int set = 0; + int min_i; + double min; + + if (d->num == 0) + return 0; + for (i = 0; i < d->num; i++) + if (min_time <= d->data[i].time && d->data[i].time <= max_time) + if (!set || d->data[i].value < min) { + min_i = i; + min = d->data[i].value; + set = 1; + } + return min_i; +} + +int +cc_timedata_max(struct cc_timedata *d, double min_time, double max_time) +{ + int i; + double max; + int max_i; + int set = 0; + + if (d->num == 0) + return 0; + for (i = 0; i < d->num; i++) + if (min_time <= d->data[i].time && d->data[i].time <= max_time) + if (!set || d->data[i].value > max) { + max_i = i; + max = d->data[i].value; + set = 1; + } + return max_i; +} diff --git a/ao-tools/lib/cc-convert.c b/ao-tools/lib/cc-convert.c new file mode 100644 index 00000000..ac6962ba --- /dev/null +++ b/ao-tools/lib/cc-convert.c @@ -0,0 +1,275 @@ +/* + * 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; 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 "cc.h" +#include + +/* + * Pressure Sensor Model, version 1.1 + * + * written by Holly Grimes + * + * Uses the International Standard Atmosphere as described in + * "A Quick Derivation relating altitude to air pressure" (version 1.03) + * from the Portland State Aerospace Society, except that the atmosphere + * is divided into layers with each layer having a different lapse rate. + * + * Lapse rate data for each layer was obtained from Wikipedia on Sept. 1, 2007 + * at site MAXIMUM_ALTITUDE) /* FIX ME: use sensor data to improve model */ + return 0; + + /* calculate the base temperature and pressure for the atmospheric layer + associated with the inputted altitude */ + for(layer_number = 0; layer_number < NUMBER_OF_LAYERS - 1 && altitude > base_altitude[layer_number + 1]; layer_number++) { + delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number]; + if (lapse_rate[layer_number] == 0.0) { + exponent = GRAVITATIONAL_ACCELERATION * delta_z + / AIR_GAS_CONSTANT / base_temperature; + base_pressure *= exp(exponent); + } + else { + base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; + exponent = GRAVITATIONAL_ACCELERATION / + (AIR_GAS_CONSTANT * lapse_rate[layer_number]); + base_pressure *= pow(base, exponent); + } + base_temperature += delta_z * lapse_rate[layer_number]; + } + + /* calculate the pressure at the inputted altitude */ + delta_z = altitude - base_altitude[layer_number]; + if (lapse_rate[layer_number] == 0.0) { + exponent = GRAVITATIONAL_ACCELERATION * delta_z + / AIR_GAS_CONSTANT / base_temperature; + pressure = base_pressure * exp(exponent); + } + else { + base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; + exponent = GRAVITATIONAL_ACCELERATION / + (AIR_GAS_CONSTANT * lapse_rate[layer_number]); + pressure = base_pressure * pow(base, exponent); + } + + return pressure; +} + + +/* outputs the altitude associated with the given pressure. the altitude + returned is measured with respect to the mean sea level */ +double +cc_pressure_to_altitude(double pressure) +{ + + double next_base_temperature = LAYER0_BASE_TEMPERATURE; + double next_base_pressure = LAYER0_BASE_PRESSURE; + + double altitude; + double base_pressure; + double base_temperature; + double base; /* base for function to determine base pressure of next layer */ + double exponent; /* exponent for function to determine base pressure + of next layer */ + double coefficient; + int layer_number; /* identifies layer in the atmosphere */ + int delta_z; /* difference between two altitudes */ + + if (pressure < 0) /* illegal pressure */ + return -1; + if (pressure < MINIMUM_PRESSURE) /* FIX ME: use sensor data to improve model */ + return MAXIMUM_ALTITUDE; + + /* calculate the base temperature and pressure for the atmospheric layer + associated with the inputted pressure. */ + layer_number = -1; + do { + layer_number++; + base_pressure = next_base_pressure; + base_temperature = next_base_temperature; + delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number]; + if (lapse_rate[layer_number] == 0.0) { + exponent = GRAVITATIONAL_ACCELERATION * delta_z + / AIR_GAS_CONSTANT / base_temperature; + next_base_pressure *= exp(exponent); + } + else { + base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; + exponent = GRAVITATIONAL_ACCELERATION / + (AIR_GAS_CONSTANT * lapse_rate[layer_number]); + next_base_pressure *= pow(base, exponent); + } + next_base_temperature += delta_z * lapse_rate[layer_number]; + } + while(layer_number < NUMBER_OF_LAYERS - 1 && pressure < next_base_pressure); + + /* calculate the altitude associated with the inputted pressure */ + if (lapse_rate[layer_number] == 0.0) { + coefficient = (AIR_GAS_CONSTANT / GRAVITATIONAL_ACCELERATION) + * base_temperature; + altitude = base_altitude[layer_number] + + coefficient * log(pressure / base_pressure); + } + else { + base = pressure / base_pressure; + exponent = AIR_GAS_CONSTANT * lapse_rate[layer_number] + / GRAVITATIONAL_ACCELERATION; + coefficient = base_temperature / lapse_rate[layer_number]; + altitude = base_altitude[layer_number] + + coefficient * (pow(base, exponent) - 1); + } + + return altitude; +} + +/* + * 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 const double counts_per_kPa = 27 * 2047 / 3300; +static const double counts_at_101_3kPa = 1674.0; + +double +cc_barometer_to_pressure(double count) +{ + return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; +} + +double +cc_barometer_to_altitude(double baro) +{ + double Pa = cc_barometer_to_pressure(baro); + return cc_pressure_to_altitude(Pa); +} + +static const double count_per_mss = 27.0; + +double +cc_accelerometer_to_acceleration(double accel, double ground_accel) +{ + return (ground_accel - accel) / count_per_mss; +} + +double +cc_thermometer_to_temperature(double thermo) +{ + return ((thermo / 32767 * 3.3) - 0.5) / 0.01; +} + +double +cc_battery_to_voltage(double battery) +{ + return battery / 32767.0 * 5.0; +} + +double +cc_ignitor_to_voltage(double ignite) +{ + return ignite / 32767 * 15.0; +} + +static inline double sqr(double a) { return a * a; } + +void +cc_great_circle (double start_lat, double start_lon, + double end_lat, double end_lon, + double *dist, double *bearing) +{ + const double rad = M_PI / 180; + const double earth_radius = 6371.2 * 1000; /* in meters */ + double lat1 = rad * start_lat; + double lon1 = rad * -start_lon; + double lat2 = rad * end_lat; + double lon2 = rad * -end_lon; + +// double d_lat = lat2 - lat1; + double d_lon = lon2 - lon1; + + /* From http://en.wikipedia.org/wiki/Great-circle_distance */ + double vdn = sqrt(sqr(cos(lat2) * sin(d_lon)) + + sqr(cos(lat1) * sin(lat2) - + sin(lat1) * cos(lat2) * cos(d_lon))); + double vdd = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(d_lon); + double d = atan2(vdn,vdd); + double course; + + if (cos(lat1) < 1e-20) { + if (lat1 > 0) + course = M_PI; + else + course = -M_PI; + } else { + if (d < 1e-10) + course = 0; + else + course = acos((sin(lat2)-sin(lat1)*cos(d)) / + (sin(d)*cos(lat1))); + if (sin(lon2-lon1) > 0) + course = 2 * M_PI-course; + } + *dist = d * earth_radius; + *bearing = course * 180/M_PI; +} diff --git a/ao-tools/lib/cc-log.c b/ao-tools/lib/cc-log.c new file mode 100644 index 00000000..dd8177f4 --- /dev/null +++ b/ao-tools/lib/cc-log.c @@ -0,0 +1,114 @@ +/* + * 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; 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 "cc.h" + +static char *cc_file_dir; + +#define ALTOS_DIR_PATH "/apps/aoview/log_dir" +#define DEFAULT_DIR "AltOS" + +static void +cc_file_save_conf(void) +{ + GConfClient *gconf_client; + + g_type_init(); + gconf_client = gconf_client_get_default(); + if (gconf_client) + { + gconf_client_set_string(gconf_client, + ALTOS_DIR_PATH, + cc_file_dir, + NULL); + g_object_unref(G_OBJECT(gconf_client)); + } +} + +static void +cc_file_load_conf(void) +{ + char *file_dir; + GConfClient *gconf_client; + + g_type_init(); + gconf_client = gconf_client_get_default(); + if (gconf_client) + { + file_dir = gconf_client_get_string(gconf_client, + ALTOS_DIR_PATH, + NULL); + g_object_unref(G_OBJECT(gconf_client)); + if (file_dir) + cc_file_dir = strdup(file_dir); + } +} + +void +cc_set_log_dir(char *dir) +{ + cc_file_dir = strdup(dir); + cc_file_save_conf(); +} + +char * +cc_get_log_dir(void) +{ + cc_file_load_conf(); + if (!cc_file_dir) { + cc_file_dir = cc_fullname(getenv("HOME"), DEFAULT_DIR); + cc_file_save_conf(); + } + return cc_file_dir; +} + +char * +cc_make_filename(int serial, char *ext) +{ + char base[50]; + struct tm tm; + time_t now; + char *full; + int r; + int sequence; + + now = time(NULL); + (void) localtime_r(&now, &tm); + cc_mkdir(cc_get_log_dir()); + sequence = 0; + for (;;) { + snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + serial, + sequence, + ext); + full = cc_fullname(cc_get_log_dir(), base); + r = access(full, F_OK); + if (r < 0) + return full; + free(full); + sequence++; + } + +} diff --git a/ao-tools/lib/cc-logfile.c b/ao-tools/lib/cc-logfile.c new file mode 100644 index 00000000..444ff089 --- /dev/null +++ b/ao-tools/lib/cc-logfile.c @@ -0,0 +1,218 @@ +/* + * 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; 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 "cc.h" +#include +#include + +static int +timedata_add(struct cc_timedata *data, double time, double value) +{ + struct cc_timedataelt *newdata; + int newsize; + if (data->size == data->num) { + if (data->size == 0) + newdata = malloc((newsize = 256) * sizeof (struct cc_timedataelt)); + else + newdata = realloc (data->data, (newsize = data->size * 2) + * sizeof (struct cc_timedataelt)); + if (!newdata) + return 0; + data->size = newsize; + data->data = newdata; + } + if (data->num && data->data[data->num-1].time > time) + time += 65536; + data->data[data->num].time = time; + data->data[data->num].value = value; + data->num++; + return 1; +} + +static void +timedata_free(struct cc_timedata *data) +{ + if (data->data) + free(data->data); +} + +static int +gpsdata_add(struct cc_gpsdata *data, struct cc_gpselt *elt) +{ + struct cc_gpselt *newdata; + int newsize; + if (data->size == data->num) { + if (data->size == 0) + newdata = malloc((newsize = 256) * sizeof (struct cc_gpselt)); + else + newdata = realloc (data->data, (newsize = data->size * 2) + * sizeof (struct cc_gpselt)); + if (!newdata) + return 0; + data->size = newsize; + data->data = newdata; + } + data->data[data->num] = *elt; + data->num++; + return 1; +} + +static void +gpsdata_free(struct cc_gpsdata *data) +{ + if (data->data) + free(data->data); +} + +#define AO_LOG_FLIGHT 'F' +#define AO_LOG_SENSOR 'A' +#define AO_LOG_TEMP_VOLT 'T' +#define AO_LOG_DEPLOY 'D' +#define AO_LOG_STATE 'S' +#define AO_LOG_GPS_TIME 'G' +#define AO_LOG_GPS_LAT 'N' +#define AO_LOG_GPS_LON 'W' +#define AO_LOG_GPS_ALT 'H' +#define AO_LOG_GPS_SAT 'V' + +#define AO_LOG_POS_NONE (~0UL) + +static int +read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int *ground_pres_count) +{ + char type; + int tick; + int a, b; + struct cc_gpselt gps; + int serial; + + if (sscanf(line, "serial-number %u", &serial) == 1) { + f->serial = serial; + return 1; + } + if (sscanf(line, "%c %x %x %x", &type, &tick, &a, &b) != 4) + return 0; + switch (type) { + case AO_LOG_FLIGHT: + f->ground_accel = a; + f->ground_pres = 0; + f->flight = b; + *ground_pres = 0; + *ground_pres_count = 0; + break; + case AO_LOG_SENSOR: + timedata_add(&f->accel, tick, a); + timedata_add(&f->pres, tick, b); + if (*ground_pres_count < 20) { + *ground_pres += b; + (*ground_pres_count)++; + if (*ground_pres_count >= 20) + f->ground_pres = *ground_pres / *ground_pres_count; + } + break; + case AO_LOG_TEMP_VOLT: + timedata_add(&f->temp, tick, a); + timedata_add(&f->volt, tick, b); + break; + case AO_LOG_DEPLOY: + timedata_add(&f->drogue, tick, a); + timedata_add(&f->main, tick, b); + break; + case AO_LOG_STATE: + timedata_add(&f->state, tick, a); + break; + case AO_LOG_GPS_TIME: + gps.time = tick; + break; + case AO_LOG_GPS_LAT: + gps.lat = ((int32_t) (a + (b << 16))) / 10000000.0; + break; + case AO_LOG_GPS_LON: + gps.lon = ((int32_t) (a + (b << 16))) / 10000000.0; + break; + case AO_LOG_GPS_ALT: + gps.alt = ((int32_t) (a + (b << 16))); + gpsdata_add(&f->gps, &gps); + break; + case AO_LOG_GPS_SAT: + break; + default: + return 0; + } + return 1; +} + +static int +read_telem(const char *line, struct cc_flightraw *f) +{ + struct cc_telem telem; + struct cc_gpselt gps; + if (!cc_telem_parse(line, &telem)) + return 0; + f->ground_accel = telem.ground_accel; + f->ground_pres = telem.ground_pres; + f->flight = 0; + timedata_add(&f->accel, telem.tick, telem.flight_accel); + timedata_add(&f->pres, telem.tick, telem.flight_pres); + timedata_add(&f->temp, telem.tick, telem.temp); + timedata_add(&f->volt, telem.tick, telem.batt); + timedata_add(&f->drogue, telem.tick, telem.drogue); + timedata_add(&f->main, telem.tick, telem.main); + if (telem.gps.gps_locked) { + gps.time = telem.tick; + gps.lat = telem.gps.lat; + gps.lon = telem.gps.lon; + gps.alt = telem.gps.alt; + gpsdata_add(&f->gps, &gps); + } + return 1; +} + +struct cc_flightraw * +cc_log_read(FILE *file) +{ + struct cc_flightraw *f; + char line[8192]; + double ground_pres; + int ground_pres_count; + + f = calloc(1, sizeof (struct cc_flightraw)); + if (!f) + return NULL; + while (fgets(line, sizeof (line), file)) { + if (read_eeprom(line, f, &ground_pres, &ground_pres_count)) + continue; + if (read_telem(line, f)) + continue; + fprintf (stderr, "invalid line: %s", line); + } + return f; +} + +void +cc_flightraw_free(struct cc_flightraw *raw) +{ + timedata_free(&raw->accel); + timedata_free(&raw->pres); + timedata_free(&raw->temp); + timedata_free(&raw->volt); + timedata_free(&raw->main); + timedata_free(&raw->drogue); + timedata_free(&raw->state); + gpsdata_free(&raw->gps); + free(raw); +} diff --git a/ao-tools/lib/cc-telem.c b/ao-tools/lib/cc-telem.c new file mode 100644 index 00000000..a6ac0313 --- /dev/null +++ b/ao-tools/lib/cc-telem.c @@ -0,0 +1,164 @@ +/* + * 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; 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 "cc.h" +#include +#include + +static void +cc_parse_string(char *target, int len, char *source) +{ + strncpy(target, source, len-1); + target[len-1] = '\0'; +} + +static void +cc_parse_int(int *target, char *source) +{ + *target = strtol(source, NULL, 0); +} + +static void +cc_parse_hex(int *target, char *source) +{ + *target = strtol(source, NULL, 16); +} + +static void +cc_parse_pos(double *target, char *source) +{ + int deg; + double min; + char dir; + double r; + + if (sscanf(source, "%d°%lf'%c", °, &min, &dir) != 3) { + *target = 0; + return; + } + r = deg + min / 60.0; + if (dir == 'S' || dir == 'W') + r = -r; + *target = r; +} + +#define PARSE_MAX_WORDS 512 + +int +cc_telem_parse(const char *input_line, struct cc_telem *telem) +{ + char *saveptr; + char *words[PARSE_MAX_WORDS]; + int nword; + char line_buf[8192], *line; + int tracking_pos; + + /* avoid smashing our input parameter */ + strncpy (line_buf, input_line, sizeof (line_buf)-1); + line_buf[sizeof(line_buf) - 1] = '\0'; + line = line_buf; + for (nword = 0; nword < PARSE_MAX_WORDS; nword++) { + words[nword] = strtok_r(line, " \t\n", &saveptr); + line = NULL; + if (words[nword] == NULL) + break; + } + if (nword < 36) + return FALSE; + if (strcmp(words[0], "CALL") != 0) + return FALSE; + cc_parse_string(telem->callsign, sizeof (telem->callsign), words[1]); + cc_parse_int(&telem->serial, words[3]); + + cc_parse_int(&telem->rssi, words[5]); + cc_parse_string(telem->state, sizeof (telem->state), words[9]); + cc_parse_int(&telem->tick, words[10]); + cc_parse_int(&telem->accel, words[12]); + cc_parse_int(&telem->pres, words[14]); + cc_parse_int(&telem->temp, words[16]); + cc_parse_int(&telem->batt, words[18]); + cc_parse_int(&telem->drogue, words[20]); + cc_parse_int(&telem->main, words[22]); + cc_parse_int(&telem->flight_accel, words[24]); + cc_parse_int(&telem->ground_accel, words[26]); + cc_parse_int(&telem->flight_vel, words[28]); + cc_parse_int(&telem->flight_pres, words[30]); + cc_parse_int(&telem->ground_pres, words[32]); + cc_parse_int(&telem->gps.nsat, words[34]); + if (strcmp (words[36], "unlocked") == 0) { + telem->gps.gps_connected = 1; + telem->gps.gps_locked = 0; + telem->gps.gps_time.hour = telem->gps.gps_time.minute = telem->gps.gps_time.second = 0; + telem->gps.lat = telem->gps.lon = 0; + telem->gps.alt = 0; + tracking_pos = 37; + } else if (nword >= 40) { + telem->gps.gps_locked = 1; + telem->gps.gps_connected = 1; + sscanf(words[36], "%d:%d:%d", &telem->gps.gps_time.hour, &telem->gps.gps_time.minute, &telem->gps.gps_time.second); + cc_parse_pos(&telem->gps.lat, words[37]); + cc_parse_pos(&telem->gps.lon, words[38]); + sscanf(words[39], "%dm", &telem->gps.alt); + tracking_pos = 46; + } else { + telem->gps.gps_connected = 0; + telem->gps.gps_locked = 0; + telem->gps.gps_time.hour = telem->gps.gps_time.minute = telem->gps.gps_time.second = 0; + telem->gps.lat = telem->gps.lon = 0; + telem->gps.alt = 0; + tracking_pos = -1; + } + if (nword >= 46) { + telem->gps.gps_extended = 1; + sscanf(words[40], "%lfm/s", &telem->gps.ground_speed); + sscanf(words[41], "%d", &telem->gps.course); + sscanf(words[42], "%lfm/s", &telem->gps.climb_rate); + sscanf(words[43], "%lf", &telem->gps.hdop); + sscanf(words[44], "%d", &telem->gps.h_error); + sscanf(words[45], "%d", &telem->gps.v_error); + } else { + telem->gps.gps_extended = 0; + telem->gps.ground_speed = 0; + telem->gps.course = 0; + telem->gps.climb_rate = 0; + telem->gps.hdop = 0; + telem->gps.h_error = 0; + telem->gps.v_error = 0; + } + if (tracking_pos >= 0 && nword >= tracking_pos + 2 && strcmp(words[tracking_pos], "SAT") == 0) { + int c, n, pos; + cc_parse_int(&n, words[tracking_pos + 1]); + pos = tracking_pos + 2; + if (nword >= pos + n * 3) { + telem->gps_tracking.channels = n; + for (c = 0; c < n; c++) { + cc_parse_int(&telem->gps_tracking.sats[c].svid, + words[pos + 0]); + cc_parse_hex(&telem->gps_tracking.sats[c].state, + words[pos + 1]); + cc_parse_int(&telem->gps_tracking.sats[c].c_n0, + words[pos + 2]); + pos += 3; + } + } else { + telem->gps_tracking.channels = 0; + } + } else { + telem->gps_tracking.channels = 0; + } + return TRUE; +} diff --git a/ao-tools/lib/cc-util.c b/ao-tools/lib/cc-util.c index 7104470c..65488ee9 100644 --- a/ao-tools/lib/cc-util.c +++ b/ao-tools/lib/cc-util.c @@ -15,8 +15,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include "cc.h" #define _GNU_SOURCE +#include "cc.h" #include #include #include diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index f92a29f7..3975cf1b 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -18,6 +18,8 @@ #ifndef _CC_H_ #define _CC_H_ +#include + char * cc_fullname (char *dir, char *file); @@ -60,4 +62,209 @@ cc_get_log_dir(void); char * cc_make_filename(int serial, char *ext); +/* + * For sequential data which are not evenly spaced + */ + +struct cc_timedataelt { + double time; + double value; +}; + +struct cc_timedata { + int num; + int size; + struct cc_timedataelt *data; +}; + + +/* + * For GPS data + */ + +struct cc_gpselt { + double time; + double lat; + double lon; + double alt; +}; + +struct cc_gpsdata { + int num; + int size; + double time_offset; + struct cc_gpselt *data; +}; + +/* + * For sequential data which are evenly spaced + */ +struct cc_perioddata { + int num; + double start; + double step; + double *data; +}; + +enum ao_flight_state { + ao_flight_startup = 0, + ao_flight_idle = 1, + ao_flight_pad = 2, + ao_flight_boost = 3, + ao_flight_fast = 4, + ao_flight_coast = 5, + ao_flight_drogue = 6, + ao_flight_main = 7, + ao_flight_landed = 8, + ao_flight_invalid = 9 +}; + +struct cc_flightraw { + int flight; + int serial; + double ground_accel; + double ground_pres; + struct cc_timedata accel; + struct cc_timedata pres; + struct cc_timedata temp; + struct cc_timedata volt; + struct cc_timedata main; + struct cc_timedata drogue; + struct cc_timedata state; + struct cc_gpsdata gps; +}; + +struct cc_flightraw * +cc_log_read(FILE *file); + +void +cc_flightraw_free(struct cc_flightraw *raw); + +struct cc_flightcooked { + struct cc_perioddata accel_accel; + struct cc_perioddata accel_speed; + struct cc_perioddata accel_pos; + struct cc_perioddata pres_pos; + struct cc_perioddata pres_speed; + struct cc_perioddata pres_accel; + struct cc_perioddata gps_lat; + struct cc_perioddata gps_lon; + struct cc_perioddata gps_alt; + struct cc_timedata state; +}; + +/* + * Telemetry data contents + */ + + +struct cc_gps_time { + int hour; + int minute; + int second; +}; + +struct cc_gps { + int nsat; + int gps_locked; + int gps_connected; + struct cc_gps_time gps_time; + double lat; /* degrees (+N -S) */ + double lon; /* degrees (+E -W) */ + int alt; /* m */ + + int gps_extended; /* has extra data */ + double ground_speed; /* m/s */ + int course; /* degrees */ + double climb_rate; /* m/s */ + double hdop; /* unitless? */ + int h_error; /* m */ + int v_error; /* m */ +}; + +#define SIRF_SAT_STATE_ACQUIRED (1 << 0) +#define SIRF_SAT_STATE_CARRIER_PHASE_VALID (1 << 1) +#define SIRF_SAT_BIT_SYNC_COMPLETE (1 << 2) +#define SIRF_SAT_SUBFRAME_SYNC_COMPLETE (1 << 3) +#define SIRF_SAT_CARRIER_PULLIN_COMPLETE (1 << 4) +#define SIRF_SAT_CODE_LOCKED (1 << 5) +#define SIRF_SAT_ACQUISITION_FAILED (1 << 6) +#define SIRF_SAT_EPHEMERIS_AVAILABLE (1 << 7) + +struct cc_gps_sat { + int svid; + int state; + int c_n0; +}; + +struct cc_gps_tracking { + int channels; + struct cc_gps_sat sats[12]; +}; + +struct cc_telem { + char callsign[16]; + int serial; + int rssi; + char state[16]; + int tick; + int accel; + int pres; + int temp; + int batt; + int drogue; + int main; + int flight_accel; + int ground_accel; + int flight_vel; + int flight_pres; + int ground_pres; + struct cc_gps gps; + struct cc_gps_tracking gps_tracking; +}; + +int +cc_telem_parse(const char *input_line, struct cc_telem *telem); + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +/* Conversion functions */ +double +cc_pressure_to_altitude(double pressure); + +double +cc_altitude_to_pressure(double altitude); + +double +cc_barometer_to_pressure(double baro); + +double +cc_barometer_to_altitude(double baro); + +double +cc_accelerometer_to_acceleration(double accel, double ground_accel); + +double +cc_thermometer_to_temperature(double thermo); + +double +cc_battery_to_voltage(double battery); + +double +cc_ignitor_to_voltage(double ignite); + +void +cc_great_circle (double start_lat, double start_lon, + double end_lat, double end_lon, + double *dist, double *bearing); + +int +cc_timedata_min(struct cc_timedata *d, double min_time, double max_time); + +int +cc_timedata_max(struct cc_timedata *d, double min_time, double max_time); + #endif /* _CC_H_ */ diff --git a/configure.ac b/configure.ac index 73a33ac3..c668df04 100644 --- a/configure.ac +++ b/configure.ac @@ -82,6 +82,7 @@ ao-tools/ao-bitbang/Makefile ao-tools/ao-eeprom/Makefile ao-tools/ao-list/Makefile ao-tools/ao-load/Makefile +ao-tools/ao-postflight/Makefile ao-tools/ao-view/Makefile ao-utils/Makefile ]) -- cgit v1.2.3 From 6d018ab933832e2d80bb1564c339d9fb18b57be2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 5 Sep 2009 22:45:49 -0700 Subject: Handle vageries of .telem files in ao-postflight Telem files have multiple entries of the same state, and sometimes long gaps between recordings. Deal with this as best as possible. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 60 +++++++++++++++++++++------------- ao-tools/lib/cc-analyse.c | 8 ++--- ao-tools/lib/cc-logfile.c | 35 +++++++++++++++++++- ao-tools/lib/cc.h | 3 +- 4 files changed, 77 insertions(+), 29 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index f0e2c2ae..9371f351 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -81,43 +81,57 @@ analyse_flight(struct cc_flightraw *f) pres_i = cc_timedata_min(&f->pres, f->pres.data[0].time, f->pres.data[f->pres.num-1].time); - min_pres = f->pres.data[pres_i].value; - height = cc_barometer_to_altitude(min_pres) - - cc_barometer_to_altitude(f->ground_pres); - printf ("Max height: %9.2fm %9.2fft %9.2fs\n", - height, height * 100 / 2.54 / 12, - (f->pres.data[pres_i].time - boost_start) / 100.0); + if (pres_i) + { + min_pres = f->pres.data[pres_i].value; + height = cc_barometer_to_altitude(min_pres) - + cc_barometer_to_altitude(f->ground_pres); + printf ("Max height: %9.2fm %9.2fft %9.2fs\n", + height, height * 100 / 2.54 / 12, + (f->pres.data[pres_i].time - boost_start) / 100.0); + } accel_i = cc_timedata_min(&f->accel, boost_start, boost_stop); - accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, - f->ground_accel); - printf ("Max accel: %9.2fm/s² %9.2fg %9.2fs\n", - accel, accel / 9.80665, - (f->accel.data[accel_i].time - boost_start) / 100.0); + if (accel_i) + { + accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, + f->ground_accel); + printf ("Max accel: %9.2fm/s² %9.2fg %9.2fs\n", + accel, accel / 9.80665, + (f->accel.data[accel_i].time - boost_start) / 100.0); + } for (i = 0; i < f->state.num; i++) { state = f->state.data[i].value; state_start = f->state.data[i].time; + while (i < f->state.num - 1 && f->state.data[i+1].value == state) + i++; if (i < f->state.num - 1) - state_stop = f->state.data[i+1].time; + state_stop = f->state.data[i + 1].time; else state_stop = f->accel.data[f->accel.num-1].time; printf("State: %s\n", state_names[state]); printf("\tStart: %9.2fs\n", (state_start - boost_start) / 100.0); printf("\tDuration: %9.2fs\n", (state_stop - state_start) / 100.0); accel_i = cc_timedata_min(&f->accel, state_start, state_stop); - accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, - f->ground_accel); - printf("\tMax accel: %9.2fm/s² %9.2fg %9.2fs\n", - accel, accel / 9.80665, - (f->accel.data[accel_i].time - boost_start) / 100.0); + if (accel_i >= 0) + { + accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, + f->ground_accel); + printf("\tMax accel: %9.2fm/s² %9.2fg %9.2fs\n", + accel, accel / 9.80665, + (f->accel.data[accel_i].time - boost_start) / 100.0); + } pres_i = cc_timedata_min(&f->pres, state_start, state_stop); - min_pres = f->pres.data[pres_i].value; - height = cc_barometer_to_altitude(min_pres) - - cc_barometer_to_altitude(f->ground_pres); - printf ("\tMax height: %9.2fm %9.2fft %9.2fs\n", - height, height * 100 / 2.54 / 12, - (f->pres.data[pres_i].time - boost_start) / 100.0); + if (pres_i >= 0) + { + min_pres = f->pres.data[pres_i].value; + height = cc_barometer_to_altitude(min_pres) - + cc_barometer_to_altitude(f->ground_pres); + printf ("\tMax height: %9.2fm %9.2fft %9.2fs\n", + height, height * 100 / 2.54 / 12, + (f->pres.data[pres_i].time - boost_start) / 100.0); + } } } diff --git a/ao-tools/lib/cc-analyse.c b/ao-tools/lib/cc-analyse.c index 6fd36cdc..fc8a8417 100644 --- a/ao-tools/lib/cc-analyse.c +++ b/ao-tools/lib/cc-analyse.c @@ -22,11 +22,11 @@ cc_timedata_min(struct cc_timedata *d, double min_time, double max_time) { int i; int set = 0; - int min_i; + int min_i = -1; double min; if (d->num == 0) - return 0; + return -1; for (i = 0; i < d->num; i++) if (min_time <= d->data[i].time && d->data[i].time <= max_time) if (!set || d->data[i].value < min) { @@ -42,11 +42,11 @@ cc_timedata_max(struct cc_timedata *d, double min_time, double max_time) { int i; double max; - int max_i; + int max_i = -1; int set = 0; if (d->num == 0) - return 0; + return -1; for (i = 0; i < d->num; i++) if (min_time <= d->data[i].time && d->data[i].time <= max_time) if (!set || d->data[i].value > max) { diff --git a/ao-tools/lib/cc-logfile.c b/ao-tools/lib/cc-logfile.c index 444ff089..4abf7eb6 100644 --- a/ao-tools/lib/cc-logfile.c +++ b/ao-tools/lib/cc-logfile.c @@ -18,6 +18,7 @@ #include "cc.h" #include #include +#include static int timedata_add(struct cc_timedata *data, double time, double value) @@ -35,8 +36,11 @@ timedata_add(struct cc_timedata *data, double time, double value) data->size = newsize; data->data = newdata; } - if (data->num && data->data[data->num-1].time > time) + time += data->time_offset; + if (data->num && data->data[data->num-1].time > time) { + data->time_offset += 65536; time += 65536; + } data->data[data->num].time = time; data->data[data->num].value = value; data->num++; @@ -66,6 +70,11 @@ gpsdata_add(struct cc_gpsdata *data, struct cc_gpselt *elt) data->size = newsize; data->data = newdata; } + elt->time += data->time_offset; + if (data->num && data->data[data->num-1].time > elt->time) { + data->time_offset += 65536; + elt->time += 65536; + } data->data[data->num] = *elt; data->num++; return 1; @@ -156,6 +165,29 @@ read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int * return 1; } +static const char *state_names[] = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid" +}; + +static enum ao_flight_state +state_name_to_state(char *state_name) +{ + enum ao_flight_state state; + for (state = ao_flight_startup; state < ao_flight_invalid; state++) + if (!strcmp(state_names[state], state_name)) + return state; + return ao_flight_invalid; +} + static int read_telem(const char *line, struct cc_flightraw *f) { @@ -172,6 +204,7 @@ read_telem(const char *line, struct cc_flightraw *f) timedata_add(&f->volt, telem.tick, telem.batt); timedata_add(&f->drogue, telem.tick, telem.drogue); timedata_add(&f->main, telem.tick, telem.main); + timedata_add(&f->state, telem.tick, state_name_to_state(telem.state)); if (telem.gps.gps_locked) { gps.time = telem.tick; gps.lat = telem.gps.lat; diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 3975cf1b..57f80b8d 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -75,6 +75,7 @@ struct cc_timedata { int num; int size; struct cc_timedataelt *data; + double time_offset; }; @@ -92,8 +93,8 @@ struct cc_gpselt { struct cc_gpsdata { int num; int size; - double time_offset; struct cc_gpselt *data; + double time_offset; }; /* -- cgit v1.2.3 From 7a19aac5e881e635962a64fff73027ca2143b96f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Sep 2009 12:51:48 -0700 Subject: Add DSP code to filter data, allowing for integration/differentiation This adds the computation of speed from both accelerometer and barometer measurements and then presents a periodic flight profile using filtered data as a detailed flight record. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 135 +++++++++-- ao-tools/lib/Makefile.am | 10 +- ao-tools/lib/cc-analyse.c | 57 +++++ ao-tools/lib/cc-dsp.c | 145 ++++++++++++ ao-tools/lib/cc-integrate.c | 78 +++++++ ao-tools/lib/cc-period.c | 64 +++++ ao-tools/lib/cc-process.c | 140 +++++++++++ ao-tools/lib/cc.h | 28 +++ ao-tools/lib/cephes.h | 122 ++++++++++ ao-tools/lib/chbevl.c | 81 +++++++ ao-tools/lib/cmath.h | 179 ++++++++++++++ ao-tools/lib/i0.c | 414 +++++++++++++++++++++++++++++++++ ao-tools/lib/mconf.h | 211 +++++++++++++++++ 13 files changed, 1639 insertions(+), 25 deletions(-) create mode 100644 ao-tools/lib/cc-dsp.c create mode 100644 ao-tools/lib/cc-integrate.c create mode 100644 ao-tools/lib/cc-period.c create mode 100644 ao-tools/lib/cc-process.c create mode 100644 ao-tools/lib/cephes.h create mode 100644 ao-tools/lib/chbevl.c create mode 100644 ao-tools/lib/cmath.h create mode 100644 ao-tools/lib/i0.c create mode 100644 ao-tools/lib/mconf.h (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 9371f351..c5814c93 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -27,16 +27,6 @@ #define NUM_BLOCK 512 -static const struct option options[] = { - { 0, 0, 0, 0}, -}; - -static void usage(char *program) -{ - fprintf(stderr, "usage: %s {flight-log} ...\n", program); - exit(1); -} - static const char *state_names[] = { "startup", "idle", @@ -51,20 +41,23 @@ static const char *state_names[] = { }; void -analyse_flight(struct cc_flightraw *f) +analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file) { double height; double accel; + double speed; double boost_start, boost_stop; double min_pres; int i; - int pres_i, accel_i; + int pres_i, accel_i, speed_i; int boost_start_set = 0; int boost_stop_set = 0; enum ao_flight_state state; double state_start, state_stop; + struct cc_flightcooked *cooked; + double apogee; - printf ("Flight: %9d\nSerial: %9d\n", + fprintf(summary_file, "Flight: %9d\nSerial: %9d\n", f->flight, f->serial); boost_start = f->accel.data[0].time; boost_stop = f->accel.data[f->accel.num-1].time; @@ -81,25 +74,37 @@ analyse_flight(struct cc_flightraw *f) pres_i = cc_timedata_min(&f->pres, f->pres.data[0].time, f->pres.data[f->pres.num-1].time); - if (pres_i) + if (pres_i >= 0) { min_pres = f->pres.data[pres_i].value; height = cc_barometer_to_altitude(min_pres) - cc_barometer_to_altitude(f->ground_pres); - printf ("Max height: %9.2fm %9.2fft %9.2fs\n", + fprintf(summary_file, "Max height: %9.2fm %9.2fft %9.2fs\n", height, height * 100 / 2.54 / 12, (f->pres.data[pres_i].time - boost_start) / 100.0); + apogee = f->pres.data[pres_i].time; } + cooked = cc_flight_cook(f); + if (cooked) { + speed_i = cc_perioddata_max(&cooked->accel_speed, boost_start, boost_stop); + if (speed_i >= 0) { + speed = cooked->accel_speed.data[speed_i]; + fprintf(summary_file, "Max speed: %9.2fm/s %9.2fft/s %9.2fs\n", + speed, speed * 100 / 2.4 / 12.0, + (cooked->accel_speed.start + speed_i * cooked->accel_speed.step - boost_start) / 100.0); + } + } accel_i = cc_timedata_min(&f->accel, boost_start, boost_stop); - if (accel_i) + if (accel_i >= 0) { accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, f->ground_accel); - printf ("Max accel: %9.2fm/s² %9.2fg %9.2fs\n", + fprintf(summary_file, "Max accel: %9.2fm/s² %9.2fg %9.2fs\n", accel, accel / 9.80665, (f->accel.data[accel_i].time - boost_start) / 100.0); } + for (i = 0; i < f->state.num; i++) { state = f->state.data[i].value; state_start = f->state.data[i].time; @@ -109,50 +114,132 @@ analyse_flight(struct cc_flightraw *f) state_stop = f->state.data[i + 1].time; else state_stop = f->accel.data[f->accel.num-1].time; - printf("State: %s\n", state_names[state]); - printf("\tStart: %9.2fs\n", (state_start - boost_start) / 100.0); - printf("\tDuration: %9.2fs\n", (state_stop - state_start) / 100.0); + fprintf(summary_file, "State: %s\n", state_names[state]); + fprintf(summary_file, "\tStart: %9.2fs\n", (state_start - boost_start) / 100.0); + fprintf(summary_file, "\tDuration: %9.2fs\n", (state_stop - state_start) / 100.0); accel_i = cc_timedata_min(&f->accel, state_start, state_stop); if (accel_i >= 0) { accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, f->ground_accel); - printf("\tMax accel: %9.2fm/s² %9.2fg %9.2fs\n", + fprintf(summary_file, "\tMax accel: %9.2fm/s² %9.2fg %9.2fs\n", accel, accel / 9.80665, (f->accel.data[accel_i].time - boost_start) / 100.0); } + if (cooked) { + if (state_start < apogee) { + speed_i = cc_perioddata_max(&cooked->accel_speed, state_start, state_stop); + if (speed_i >= 0) + speed = cooked->accel_speed.data[speed_i]; + } else { + speed_i = cc_perioddata_max(&cooked->pres_speed, state_start, state_stop); + if (speed_i >= 0) + speed = cooked->pres_speed.data[speed_i]; + } + if (speed_i >= 0) + fprintf(summary_file, "\tMax speed: %9.2fm/s %9.2fft/s %9.2fs\n", + speed, speed * 100 / 2.4 / 12.0, + (cooked->accel_speed.start + speed_i * cooked->accel_speed.step - boost_start) / 100.0); + } pres_i = cc_timedata_min(&f->pres, state_start, state_stop); if (pres_i >= 0) { min_pres = f->pres.data[pres_i].value; height = cc_barometer_to_altitude(min_pres) - cc_barometer_to_altitude(f->ground_pres); - printf ("\tMax height: %9.2fm %9.2fft %9.2fs\n", + fprintf(summary_file, "\tMax height: %9.2fm %9.2fft %9.2fs\n", height, height * 100 / 2.54 / 12, (f->pres.data[pres_i].time - boost_start) / 100.0); } } + if (cooked && detail_file) { + double apogee_time; + double max_height = 0; + int i; + + for (i = 0; i < cooked->pres_pos.num; i++) { + if (cooked->pres_pos.data[i] > max_height) { + max_height = cooked->pres_pos.data[i]; + apogee_time = cooked->pres_pos.start + cooked->pres_pos.step * i; + } + } + fprintf(detail_file, "%9s %9s %9s %9s\n", + "time", "height", "speed", "accel"); + for (i = 0; i < cooked->pres_pos.num; i++) { + double time = (cooked->accel_accel.start + i * cooked->accel_accel.step - boost_start) / 100.0; + double accel = cooked->accel_accel.data[i]; + double pos = cooked->pres_pos.data[i]; + double speed; + if (cooked->pres_pos.start + cooked->pres_pos.step * i < apogee_time) + speed = cooked->accel_speed.data[i]; + else + speed = cooked->pres_speed.data[i]; + fprintf(detail_file, "%9.2f %9.2f %9.2f %9.2f\n", + time, pos, speed, accel); + } + } +} + +static const struct option options[] = { + { .name = "summary", .has_arg = 1, .val = 'S' }, + { .name = "detail", .has_arg = 1, .val = 'D' }, + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s [--summary=] [--detail=serial) raw->serial = serial; - analyse_flight(raw); + analyse_flight(raw, summary_file, detail_file); cc_flightraw_free(raw); } return ret; diff --git a/ao-tools/lib/Makefile.am b/ao-tools/lib/Makefile.am index e682f757..79972f46 100644 --- a/ao-tools/lib/Makefile.am +++ b/ao-tools/lib/Makefile.am @@ -16,7 +16,11 @@ libao_tools_a_SOURCES = \ ccdbg-state.c \ cc-analyse.c \ cc-convert.c \ + cc-dsp.c \ cc-log.c \ + cc-integrate.c \ + cc-period.c \ + cc-process.c \ cc-usb.c \ cc-usb.h \ cc.h \ @@ -27,4 +31,8 @@ libao_tools_a_SOURCES = \ cc-logfile.c \ cc-telem.c \ cp-usb-async.c \ - cp-usb-async.h + cp-usb-async.h \ + i0.c \ + chbevl.c \ + mconf.h \ + cephes.h diff --git a/ao-tools/lib/cc-analyse.c b/ao-tools/lib/cc-analyse.c index fc8a8417..0e020115 100644 --- a/ao-tools/lib/cc-analyse.c +++ b/ao-tools/lib/cc-analyse.c @@ -16,6 +16,7 @@ */ #include "cc.h" +#include int cc_timedata_min(struct cc_timedata *d, double min_time, double max_time) @@ -56,3 +57,59 @@ cc_timedata_max(struct cc_timedata *d, double min_time, double max_time) } return max_i; } + +int +cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time) +{ + int start, stop; + int i; + double min; + int min_i; + + if (d->num == 0) + return -1; + start = (int) ceil((min_time - d->start) / d->step); + if (start < 0) + start = 0; + stop = (int) floor((max_time - d->start) / d->step); + if (stop >= d->num) + stop = d->num - 1; + if (stop < start) + return -1; + min = d->data[start]; + min_i = start; + for (i = start + 1; i <= stop; i++) + if (d->data[i] < min) { + min = d->data[i]; + min_i = i; + } + return min_i; +} + +int +cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time) +{ + int start, stop; + int i; + double max; + int max_i; + + if (d->num == 0) + return -1; + start = (int) ceil((min_time - d->start) / d->step); + if (start < 0) + start = 0; + stop = (int) floor((max_time - d->start) / d->step); + if (stop >= d->num) + stop = d->num - 1; + if (stop < start) + return -1; + max = d->data[start]; + max_i = start; + for (i = start + 1; i <= stop; i++) + if (fabs(d->data[i]) > max) { + max = fabs(d->data[i]); + max_i = i; + } + return max_i; +} diff --git a/ao-tools/lib/cc-dsp.c b/ao-tools/lib/cc-dsp.c new file mode 100644 index 00000000..518c1a68 --- /dev/null +++ b/ao-tools/lib/cc-dsp.c @@ -0,0 +1,145 @@ +/* + * 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; 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 "cc.h" +#include "cephes.h" +#include +#include + +static inline double sqr (double x) { return x * x; } + +/* + * Kaiser Window digital filter + */ + +#if 0 +/* not used in this program */ +static double highpass (double n, double m, double wc) +{ + double alpha = m/2; + double dist; + + dist = n - alpha; + if (dist == 0) + return (M_PI/2 - wc) / M_PI; + return -sin(dist * (M_PI/2-wc)) / (M_PI * dist); +} +#endif + +static double lowpass (double n, double m, double wc) +{ + double alpha = m/2; + double dist; + dist = n - alpha; + if (dist == 0) + return wc / M_PI; + return sin (wc * dist) / (M_PI * dist); +} + +static double kaiser (double n, double m, double beta) +{ + double alpha = m / 2; + return i0 (beta * sqrt (1 - sqr((n - alpha) / alpha))) / i0(beta); +} + +static double beta (double A) +{ + if (A > 50) + return 0.1102 * (A - 8.7); + else if (A >= 21) + return 0.5842 * pow((A - 21), 0.4) + 0.07886 * (A - 21); + else + return 0.0; +} + +static int M (double A, double delta_omega) +{ + if (A > 21) + return ceil ((A - 7.95) / (2.285 * delta_omega)); + else + return ceil(5.79 / delta_omega); +} + +struct filter_param { + double omega_pass; + double delta_omega; + double A; + double beta; + int M; +} filter_param_t; + +static struct filter_param +filter (double omega_pass, double omega_stop, double error) +{ + struct filter_param p; + p.omega_pass = omega_pass; + p.delta_omega = omega_stop - omega_pass; + p.A = -20 * log10 (error); + p.beta = beta (p.A); + p.M = M (p.A, p.delta_omega); + if ((p.M & 1) == 1) + p.M++; + return p; +} + +static double * +make_low_pass_filter(double omega_pass, double omega_stop, double error, int *length_p) +{ + struct filter_param p = filter(omega_pass, omega_stop, error); + int length; + int n; + double *lpf; + + length = p.M + 1; + lpf = calloc (length, sizeof(double)); + for (n = 0; n < length; n++) + lpf[n] = lowpass(n, p.M, omega_pass) * kaiser(n, p.M, p.beta); + *length_p = length; + return lpf; +} + +static double * +convolve(double *d, int d_len, double *e, int e_len) +{ + int w = (e_len - 1) / 2; + int n; + double *con = calloc (d_len, sizeof (double)); + + for (n = 0; n < d_len; n++) { + double v = 0; + int o; + for (o = -w; o <= w; o++) { + int p = n + o; + double sample = p < 0 ? d[0] : p >= d_len ? d[d_len-1] : d[p]; + v += sample * e[o + w]; + } + con[n] = v; + } + return con; +} + +double * +cc_low_pass(double *data, int data_len, double omega_pass, double omega_stop, double error) +{ + int fir_len; + double *fir = make_low_pass_filter(omega_pass, omega_stop, error, &fir_len); + double *result; + + result = convolve(data, data_len, fir, fir_len); + free(fir); + return result; +} diff --git a/ao-tools/lib/cc-integrate.c b/ao-tools/lib/cc-integrate.c new file mode 100644 index 00000000..08ca295c --- /dev/null +++ b/ao-tools/lib/cc-integrate.c @@ -0,0 +1,78 @@ +/* + * 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; 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 "cc.h" +#include + +struct cc_timedata * +cc_timedata_convert(struct cc_timedata *d, double (*f)(double v, double a), double a) +{ + struct cc_timedata *r; + int n; + + r = calloc (1, sizeof (struct cc_timedata)); + r->num = d->num; + r->size = d->num; + r->data = calloc (r->size, sizeof (struct cc_timedataelt)); + r->time_offset = d->time_offset; + for (n = 0; n < d->num; n++) { + r->data[n].time = d->data[n].time; + r->data[n].value = f(d->data[n].value, a); + } + return r; +} + +struct cc_timedata * +cc_timedata_integrate(struct cc_timedata *d) +{ + struct cc_timedata *i; + int n; + + i = calloc (1, sizeof (struct cc_timedata)); + i->num = d->num; + i->size = d->num; + i->data = calloc (i->size, sizeof (struct cc_timedataelt)); + i->time_offset = d->time_offset; + for (n = 0; n < d->num; n++) { + i->data[n].time = d->data[n].time; + if (n == 0) { + i->data[n].value = 0; + } else { + i->data[n].value = i->data[n-1].value + + (d->data[n].value + d->data[n-1].value) / 2 * + ((d->data[n].time - d->data[n-1].time) / 100.0); + } + } + return i; +} + +struct cc_perioddata * +cc_perioddata_differentiate(struct cc_perioddata *i) +{ + struct cc_perioddata *d; + int n; + + d = calloc (1, sizeof (struct cc_perioddata)); + d->num = i->num; + d->start = i->start; + d->step = i->step; + d->data = calloc (d->num, sizeof(double)); + for (n = 1; n < d->num; n++) + d->data[n] = (i->data[n] - i->data[n-1]) / i->step; + d->data[0] = d->data[1]; + return d; +} diff --git a/ao-tools/lib/cc-period.c b/ao-tools/lib/cc-period.c new file mode 100644 index 00000000..c74cf9dc --- /dev/null +++ b/ao-tools/lib/cc-period.c @@ -0,0 +1,64 @@ +/* + * 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; 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 "cc.h" +#include + +struct cc_perioddata * +cc_period_make(struct cc_timedata *td, double start_time, double stop_time) +{ + int len = stop_time - start_time + 1; + struct cc_perioddata *pd; + int i; + double prev_time; + double next_time; + double interval; + + pd = calloc(1, sizeof (struct cc_perioddata)); + pd->start = start_time; + pd->step = 1; + pd->num = len; + pd->data = calloc(len, sizeof(double)); + prev_time = start_time; + for (i = 0; i < td->num; i++) { + if (start_time <= td->data[i].time && td->data[i].time <= stop_time) { + int pos = td->data[i].time - start_time; + + if (i < td->num - 1 && td->data[i+1].time < stop_time) + next_time = (td->data[i].time + td->data[i+1].time) / 2.0; + else + next_time = stop_time; + interval = next_time - prev_time; + pd->data[pos] = td->data[i].value * interval; + prev_time = next_time; + } + } + return pd; +} + +struct cc_perioddata * +cc_period_low_pass(struct cc_perioddata *raw, double omega_pass, double omega_stop, double error) +{ + struct cc_perioddata *filtered; + + filtered = calloc (1, sizeof (struct cc_perioddata)); + filtered->start = raw->start; + filtered->step = raw->step; + filtered->num = raw->num; + filtered->data = cc_low_pass(raw->data, raw->num, omega_pass, omega_stop, error); + return filtered; +} diff --git a/ao-tools/lib/cc-process.c b/ao-tools/lib/cc-process.c new file mode 100644 index 00000000..e906b635 --- /dev/null +++ b/ao-tools/lib/cc-process.c @@ -0,0 +1,140 @@ +/* + * 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; 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 "cc.h" +#include +#include +#include + +static void +cook_timed(struct cc_timedata *td, struct cc_perioddata *pd, + double start_time, double stop_time, + double omega_pass, double omega_stop, double error) +{ + struct cc_perioddata *unfiltered, *filtered; + + unfiltered = cc_period_make(td, start_time, stop_time); + filtered = cc_period_low_pass (unfiltered, omega_pass, omega_stop, error); + *pd = *filtered; + free (filtered); + free (unfiltered->data); + free (unfiltered); + free (td->data); + free (td); +} + +static double +barometer_to_altitude(double b, double pad_alt) +{ + return cc_barometer_to_altitude(b) - pad_alt; +} + +struct cc_flightcooked * +cc_flight_cook(struct cc_flightraw *raw) +{ + struct cc_flightcooked *cooked; + double flight_start; + double flight_stop; + int start_set = 0; + int stop_set = 0; + int i; + struct cc_timedata *accel; + struct cc_timedata *accel_speed; + struct cc_timedata *accel_pos; + struct cc_timedata *pres; + struct cc_perioddata *pres_speed; + struct cc_perioddata *pres_accel; + + if (raw->accel.num == 0) + return NULL; + + cooked = calloc (1, sizeof (struct cc_flightcooked)); + + /* + * Find flight start and stop times by looking at + * state transitions. The stop time is set to the time + * of landing, which may be long after it landed (due to radio + * issues). Refine this value by looking through the sensor data + */ + for (i = 0; i < raw->state.num; i++) { + if (!start_set && raw->state.data[i].value > ao_flight_pad) { + flight_start = raw->state.data[i].time; + start_set = 1; + } + if (!stop_set && raw->state.data[i].value > ao_flight_main) { + flight_stop = raw->state.data[i].time; + stop_set = 1; + } + } + + if (!start_set) + flight_start = raw->accel.data[0].time; + if (stop_set) { + for (i = 0; i < raw->accel.num - 1; i++) { + if (raw->accel.data[i+1].time >= flight_stop) { + flight_stop = raw->accel.data[i].time; + break; + } + } + } else { + flight_stop = raw->accel.data[raw->accel.num-1].time; + } + + /* Integrate the accelerometer data to get speed and position */ + accel = cc_timedata_convert(&raw->accel, cc_accelerometer_to_acceleration, raw->ground_accel); + accel_speed = cc_timedata_integrate(accel); + accel_pos = cc_timedata_integrate(accel_speed); + +#define ACCEL_OMEGA_PASS (2 * M_PI * 5 / 100) +#define ACCEL_OMEGA_STOP (2 * M_PI * 8 / 100) +#define BARO_OMEGA_PASS (2 * M_PI * .5 / 100) +#define BARO_OMEGA_STOP (2 * M_PI * 1 / 100) +#define FILTER_ERROR (1e-8) + + cook_timed(accel, &cooked->accel_accel, + flight_start, flight_stop, + ACCEL_OMEGA_PASS, ACCEL_OMEGA_STOP, FILTER_ERROR); + cook_timed(accel_speed, &cooked->accel_speed, + flight_start, flight_stop, + ACCEL_OMEGA_PASS, ACCEL_OMEGA_STOP, FILTER_ERROR); + cook_timed(accel_pos, &cooked->accel_pos, + flight_start, flight_stop, + ACCEL_OMEGA_PASS, ACCEL_OMEGA_STOP, FILTER_ERROR); + + /* Filter the pressure data */ + pres = cc_timedata_convert(&raw->pres, barometer_to_altitude, + cc_barometer_to_altitude(raw->ground_pres)); + cook_timed(pres, &cooked->pres_pos, + flight_start, flight_stop, + BARO_OMEGA_PASS, BARO_OMEGA_STOP, FILTER_ERROR); + /* differentiate twice to get to acceleration */ + pres_speed = cc_perioddata_differentiate(&cooked->pres_pos); + pres_accel = cc_perioddata_differentiate(pres_speed); + + cooked->pres_speed = *pres_speed; + free(pres_speed); + cooked->pres_accel = *pres_accel; + free(pres_accel); + + /* copy state */ + cooked->state.num = raw->state.num; + cooked->state.size = raw->state.num; + cooked->state.data = calloc(cooked->state.num, sizeof (struct cc_timedataelt)); + memcpy(cooked->state.data, raw->state.data, cooked->state.num * sizeof (struct cc_timedataelt)); + cooked->state.time_offset = raw->state.time_offset; + return cooked; +} diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 57f80b8d..356794e0 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -268,4 +268,32 @@ cc_timedata_min(struct cc_timedata *d, double min_time, double max_time); int cc_timedata_max(struct cc_timedata *d, double min_time, double max_time); +int +cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time); + +int +cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time); + +double * +cc_low_pass(double *data, int data_len, double omega_pass, double omega_stop, double error); + +struct cc_perioddata * +cc_period_make(struct cc_timedata *td, double start_time, double stop_time); + +struct cc_perioddata * +cc_period_low_pass(struct cc_perioddata *raw, double omega_pass, double omega_stop, double error); + +struct cc_timedata * +cc_timedata_convert(struct cc_timedata *d, double (*f)(double v, double a), double a); + +struct cc_timedata * +cc_timedata_integrate(struct cc_timedata *d); + +struct cc_perioddata * +cc_perioddata_differentiate(struct cc_perioddata *i); + +struct cc_flightcooked * +cc_flight_cook(struct cc_flightraw *raw); + + #endif /* _CC_H_ */ diff --git a/ao-tools/lib/cephes.h b/ao-tools/lib/cephes.h new file mode 100644 index 00000000..f8ec264f --- /dev/null +++ b/ao-tools/lib/cephes.h @@ -0,0 +1,122 @@ +/* + * This file comes from the cephes math library, which was + * released under the GPLV2+ license as a part of the Debian labplot + * package (I've included the GPLV2 license reference here to make + * this clear) - Keith Packard + * + * Cephes Math Library Release 2.0: April, 1987 + * Copyright 1984, 1987 by Stephen L. Moshier + * Direct inquiries to 30 Frost Street, Cambridge, MA 02140 + * + * 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. + */ +/* + * Prototypes of Cephes functions + */ + +#ifndef _CEPHES_H_ +#define _CEPHES_H_ + +/* Variable for error reporting. See mtherr.c. */ +extern int merror; + +#if 0 +extern int airy ( double x, double *ai, double *aip, double *bi, double *bip ); +extern double beta ( double a, double b ); +extern double lbeta ( double a, double b ); +extern double chdtrc ( double df, double x ); +extern double chdtr ( double df, double x ); +extern double chdtri ( double df, double y ); +extern double dawsn ( double xx ); +extern double ellie ( double phi, double m ); +extern double ellik ( double phi, double m ); +extern double ellpe ( double x ); +extern double ellpk ( double x ); +extern double expn ( int n, double x ); +extern double fac ( int i ); +extern double fdtrc ( int ia, int ib, double x ); +extern double fdtr ( int ia, int ib, double x ); +extern double fdtri ( int ia, int ib, double y ); +extern double frexp ( double x, int *pw2 ); +extern double ldexp ( double x, int pw2 ); +extern int fresnl ( double xxa, double *ssa, double *cca ); +extern double gdtr ( double a, double b, double x ); +extern double gdtrc ( double a, double b, double x ); +extern double hyp2f0 ( double a, double b, double x, int type, double *err ); +extern double hyp2f1 ( double a, double b, double c, double x ); +extern double hyperg ( double a, double b, double x ); +#endif +extern double i0 ( double x ); +extern double i0e ( double x ); +#if 0 +extern double i1 ( double x ); +extern double i1e ( double x ); +extern double iv ( double v, double x ); +extern double igamc ( double a, double x ); +extern double igam ( double a, double x ); +extern double igami ( double a, double y0_ ); +extern double incbet ( double aa, double bb, double xx ); +extern double incbi ( double aa, double bb, double yy0 ); +extern double jv ( double n, double x ); +extern double k0 ( double x ); +extern double k0e ( double x ); +extern double k1 ( double x ); +extern double k1e ( double x ); +extern double kn ( int nn, double x ); +extern int mtherr ( char *name, int code ); +extern double ndtr ( double a ); +extern double ndtri ( double y0_ ); +extern double pdtrc ( int k, double m ); +extern double pdtr ( int k, double m ); +extern double pdtri ( int k, double y ); +extern double psi ( double x ); +extern void revers ( double y[], double x[], int n ); +extern double true_gamma ( double x ); +extern double rgamma ( double x ); +extern int shichi ( double x, double *si, double *ci ); +extern int sici ( double x, double *si, double *ci ); +extern double spence ( double x ); +extern double stdtr ( int k, double t ); +extern double stdtri ( int k, double p ); +extern double onef2 ( double a, double b, double c, double x, double *err ); +extern double threef0 ( double a, double b, double c, double x, double *err ); +extern double struve ( double v, double x ); +extern double log1p ( double x ); +extern double expm1 ( double x ); +extern double cosm1 ( double x ); +extern double yv ( double v, double x ); +extern double zeta ( double x, double q ); +extern double zetac ( double x ); + +#endif +extern double chbevl ( double x, void *P, int n ); +#if 0 +extern double polevl ( double x, void *P, int n ); +extern double p1evl ( double x, void *P, int n ); + +/* polyn.c */ +extern void polini ( int maxdeg ); +extern void polprt ( double a[], int na, int d ); +extern void polclr ( double *a, int n ); +extern void polmov ( double *a, int na, double *b ); +extern void polmul ( double a[], int na, double b[], int nb, double c[] ); +extern void poladd ( double a[], int na, double b[], int nb, double c[] ); +extern void polsub ( double a[], int na, double b[], int nb, double c[] ); +extern int poldiv ( double a[], int na, double b[], int nb, double c[] ); +extern void polsbt ( double a[], int na, double b[], int nb, double c[] ); +extern double poleva ( double a[], int na, double x ); + +#endif + +#endif /* _CEPHES_H_ */ diff --git a/ao-tools/lib/chbevl.c b/ao-tools/lib/chbevl.c new file mode 100644 index 00000000..22892413 --- /dev/null +++ b/ao-tools/lib/chbevl.c @@ -0,0 +1,81 @@ +/* chbevl.c + * + * Evaluate Chebyshev series + * + * + * + * SYNOPSIS: + * + * int N; + * double x, y, coef[N], chebevl(); + * + * y = chbevl( x, coef, N ); + * + * + * + * DESCRIPTION: + * + * Evaluates the series + * + * N-1 + * - ' + * y = > coef[i] T (x/2) + * - i + * i=0 + * + * of Chebyshev polynomials Ti at argument x/2. + * + * Coefficients are stored in reverse order, i.e. the zero + * order term is last in the array. Note N is the number of + * coefficients, not the order. + * + * If coefficients are for the interval a to b, x must + * have been transformed to x -> 2(2x - b - a)/(b-a) before + * entering the routine. This maps x from (a, b) to (-1, 1), + * over which the Chebyshev polynomials are defined. + * + * If the coefficients are for the inverted interval, in + * which (a, b) is mapped to (1/b, 1/a), the transformation + * required is x -> 2(2ab/x - b - a)/(b-a). If b is infinity, + * this becomes x -> 4a/x - 1. + * + * + * + * SPEED: + * + * Taking advantage of the recurrence properties of the + * Chebyshev polynomials, the routine requires one more + * addition per loop than evaluating a nested polynomial of + * the same degree. + * + */ + /* chbevl.c */ + +/* +Cephes Math Library Release 2.0: April, 1987 +Copyright 1985, 1987 by Stephen L. Moshier +Direct inquiries to 30 Frost Street, Cambridge, MA 02140 +*/ + +#include "cephes.h" + +double chbevl(double x,void* array,int n ) +{ +double b0, b1, b2, *p; +int i; + +p = (double *) array; +b0 = *p++; +b1 = 0.0; +i = n - 1; + +do + { + b2 = b1; + b1 = b0; + b0 = x * b1 - b2 + *p++; + } +while( --i ); + +return( 0.5*(b0-b2) ); +} diff --git a/ao-tools/lib/cmath.h b/ao-tools/lib/cmath.h new file mode 100644 index 00000000..2751aecf --- /dev/null +++ b/ao-tools/lib/cmath.h @@ -0,0 +1,179 @@ +/* + * Grace - GRaphing, Advanced Computation and Exploration of data + * + * Home page: http://plasma-gate.weizmann.ac.il/Grace/ + * + * Copyright (c) 1991-1995 Paul J Turner, Portland, OR + * Copyright (c) 1996-2000 Grace Development Team + * + * Maintained by Evgeny Stambulchik + * + * + * All Rights Reserved + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* cmath.h - replacement for math.h or missing in libm functions */ + +#if defined(HAVE_MATH_H) +# include +#endif +#if defined(HAVE_FLOAT_H) +# include +#endif +#if defined(HAVE_IEEEFP_H) +# include +#endif + +#ifndef __GRACE_SOURCE_ + +#ifndef MACHEP +extern double MACHEP; +#endif + +#ifndef UFLOWTHRESH +extern double UFLOWTHRESH; +#endif + +#ifndef MAXNUM +extern double MAXNUM; +#endif + +#endif /* __GRACE_SOURCE_ */ + +#ifndef M_PI +# define M_PI 3.14159265358979323846 +#endif + +#ifndef M_SQRT2 +# define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +#endif + +#ifndef M_SQRT1_2 +# define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ +#endif + +#ifndef M_SQRT1_3 +# define M_SQRT1_3 0.57735026918962576451 /* 1/sqrt(3) */ +#endif + +#ifndef HAVE_HYPOT +# define hypot(x, y) sqrt((x)*(x) + (y)*(y)) +#endif + +extern double round ( double x ); +#ifndef HAVE_RINT +# define rint round +#else +# ifndef HAVE_RINT_DECL +extern double rint ( double x ); +# endif +#endif + +#ifndef HAVE_CBRT_DECL +extern double cbrt ( double x ); +#endif + +/* Cygnus gnuwin32 has the log2 macro */ +#ifdef log2 +# undef log2 +#endif + +#ifndef HAVE_LOG2_DECL +extern double log2 ( double x ); +#endif + +#ifndef HAVE_LGAMMA +extern int sgngam; +# define lgamma lgam +# define signgam sgngam +extern double lgam ( double x ); +#else +# ifndef HAVE_LGAMMA_DECL +extern double lgamma ( double x ); +# endif +# ifndef HAVE_SIGNGAM_DECL +extern int signgam; +# endif +# define lgam lgamma +# define sgngam signgam +#endif + +#ifndef HAVE_ACOSH_DECL +extern double acosh ( double x ); +#endif + +#ifndef HAVE_ASINH_DECL +extern double asinh ( double x ); +#endif + +#ifndef HAVE_ATANH_DECL +extern double atanh ( double x ); +#endif + +#ifndef HAVE_ERF_DECL +extern double erf ( double x ); +#endif + +#ifndef HAVE_ERFC_DECL +extern double erfc ( double x ); +#endif + +#ifndef HAVE_Y0_DECL +extern double y0 ( double x ); +#endif +#ifndef HAVE_Y1_DECL +extern double y1 ( double x ); +#endif +#ifndef HAVE_YN_DECL +extern double yn ( int n, double x ); +#endif +#ifndef HAVE_J0_DECL +extern double j0 ( double x ); +#endif +#ifndef HAVE_J1_DECL +extern double j1 ( double x ); +#endif +#ifndef HAVE_JN_DECL +extern double jn ( int n, double x ); +#endif + +/* isfinite is a macro */ +#ifdef isfinite +# define HAVE_ISFINITE_MACRO +#endif + +#ifndef HAVE_FINITE +# define finite isfinite +# if !defined(HAVE_ISFINITE_DECL) && !defined(HAVE_ISFINITE_MACRO) +extern int isfinite ( double x ); +# endif +#else +# ifndef HAVE_FINITE_DECL +extern int finite ( double x ); +# endif +#endif + +#ifndef HAVE_ISNAN_DECL +#ifdef __FreeBSD__ +# include +# if __FreeBSD_version < 500100 +extern int isnan ( double x ); +# endif +#endif +#else +extern int isnan ( double x ); +#endif diff --git a/ao-tools/lib/i0.c b/ao-tools/lib/i0.c new file mode 100644 index 00000000..6f7b5a57 --- /dev/null +++ b/ao-tools/lib/i0.c @@ -0,0 +1,414 @@ +/* + * This file comes from the cephes math library, which was + * released under the GPLV2+ license as a part of the Debian labplot + * package (I've included the GPLV2 license reference here to make + * this clear) - Keith Packard + * + * Cephes Math Library Release 2.0: April, 1987 + * Copyright 1984, 1987 by Stephen L. Moshier + * Direct inquiries to 30 Frost Street, Cambridge, MA 02140 + * + * 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. + */ + +/* i0.c + * + * Modified Bessel function of order zero + * + * + * + * SYNOPSIS: + * + * double x, y, i0(); + * + * y = i0( x ); + * + * + * + * DESCRIPTION: + * + * Returns modified Bessel function of order zero of the + * argument. + * + * The function is defined as i0(x) = j0( ix ). + * + * The range is partitioned into the two intervals [0,8] and + * (8, infinity). Chebyshev polynomial expansions are employed + * in each interval. + * + * + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * DEC 0,30 6000 8.2e-17 1.9e-17 + * IEEE 0,30 30000 5.8e-16 1.4e-16 + * + */ + /* i0e.c + * + * Modified Bessel function of order zero, + * exponentially scaled + * + * + * + * SYNOPSIS: + * + * double x, y, i0e(); + * + * y = i0e( x ); + * + * + * + * DESCRIPTION: + * + * Returns exponentially scaled modified Bessel function + * of order zero of the argument. + * + * The function is defined as i0e(x) = exp(-|x|) j0( ix ). + * + * + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * IEEE 0,30 30000 5.4e-16 1.2e-16 + * See i0(). + * + */ + +/* i0.c */ + + +/* +Cephes Math Library Release 2.0: April, 1987 +Copyright 1984, 1987 by Stephen L. Moshier +Direct inquiries to 30 Frost Street, Cambridge, MA 02140 +*/ + +#include +#include "mconf.h" +#include "cephes.h" + +/* Chebyshev coefficients for exp(-x) I0(x) + * in the interval [0,8]. + * + * lim(x->0){ exp(-x) I0(x) } = 1. + */ + +#ifdef UNK +static double A[] = +{ +-4.41534164647933937950E-18, + 3.33079451882223809783E-17, +-2.43127984654795469359E-16, + 1.71539128555513303061E-15, +-1.16853328779934516808E-14, + 7.67618549860493561688E-14, +-4.85644678311192946090E-13, + 2.95505266312963983461E-12, +-1.72682629144155570723E-11, + 9.67580903537323691224E-11, +-5.18979560163526290666E-10, + 2.65982372468238665035E-9, +-1.30002500998624804212E-8, + 6.04699502254191894932E-8, +-2.67079385394061173391E-7, + 1.11738753912010371815E-6, +-4.41673835845875056359E-6, + 1.64484480707288970893E-5, +-5.75419501008210370398E-5, + 1.88502885095841655729E-4, +-5.76375574538582365885E-4, + 1.63947561694133579842E-3, +-4.32430999505057594430E-3, + 1.05464603945949983183E-2, +-2.37374148058994688156E-2, + 4.93052842396707084878E-2, +-9.49010970480476444210E-2, + 1.71620901522208775349E-1, +-3.04682672343198398683E-1, + 6.76795274409476084995E-1 +}; +#endif + +#ifdef DEC +static unsigned short A[] = { +0121642,0162671,0004646,0103567, +0022431,0115424,0135755,0026104, +0123214,0023533,0110365,0156635, +0023767,0033304,0117662,0172716, +0124522,0100426,0012277,0157531, +0025254,0155062,0054461,0030465, +0126010,0131143,0013560,0153604, +0026517,0170577,0006336,0114437, +0127227,0162253,0152243,0052734, +0027724,0142766,0061641,0160200, +0130416,0123760,0116564,0125262, +0031066,0144035,0021246,0054641, +0131537,0053664,0060131,0102530, +0032201,0155664,0165153,0020652, +0132617,0061434,0074423,0176145, +0033225,0174444,0136147,0122542, +0133624,0031576,0056453,0020470, +0034211,0175305,0172321,0041314, +0134561,0054462,0147040,0165315, +0035105,0124333,0120203,0162532, +0135427,0013750,0174257,0055221, +0035726,0161654,0050220,0100162, +0136215,0131361,0000325,0041110, +0036454,0145417,0117357,0017352, +0136702,0072367,0104415,0133574, +0037111,0172126,0072505,0014544, +0137302,0055601,0120550,0033523, +0037457,0136543,0136544,0043002, +0137633,0177536,0001276,0066150, +0040055,0041164,0100655,0010521 +}; +#endif + +#ifdef IBMPC +static unsigned short A[] = { +0xd0ef,0x2134,0x5cb7,0xbc54, +0xa589,0x977d,0x3362,0x3c83, +0xbbb4,0x721e,0x84eb,0xbcb1, +0x5eba,0x93f6,0xe6d8,0x3cde, +0xfbeb,0xc297,0x5022,0xbd0a, +0x2627,0x4b26,0x9b46,0x3d35, +0x1af0,0x62ee,0x164c,0xbd61, +0xd324,0xe19b,0xfe2f,0x3d89, +0x6abc,0x7a94,0xfc95,0xbdb2, +0x3c10,0xcc74,0x98be,0x3dda, +0x9556,0x13ae,0xd4fe,0xbe01, +0xcb34,0xa454,0xd903,0x3e26, +0x30ab,0x8c0b,0xeaf6,0xbe4b, +0x6435,0x9d4d,0x3b76,0x3e70, +0x7f8d,0x8f22,0xec63,0xbe91, +0xf4ac,0x978c,0xbf24,0x3eb2, +0x6427,0xcba5,0x866f,0xbed2, +0x2859,0xbe9a,0x3f58,0x3ef1, +0x1d5a,0x59c4,0x2b26,0xbf0e, +0x7cab,0x7410,0xb51b,0x3f28, +0xeb52,0x1f15,0xe2fd,0xbf42, +0x100e,0x8a12,0xdc75,0x3f5a, +0xa849,0x201a,0xb65e,0xbf71, +0xe3dd,0xf3dd,0x9961,0x3f85, +0xb6f0,0xf121,0x4e9e,0xbf98, +0xa32d,0xcea8,0x3e8a,0x3fa9, +0x06ea,0x342d,0x4b70,0xbfb8, +0x88c0,0x77ac,0xf7ac,0x3fc5, +0xcd8d,0xc057,0x7feb,0xbfd3, +0xa22a,0x9035,0xa84e,0x3fe5, +}; +#endif + +#ifdef MIEEE +static unsigned short A[] = { +0xbc54,0x5cb7,0x2134,0xd0ef, +0x3c83,0x3362,0x977d,0xa589, +0xbcb1,0x84eb,0x721e,0xbbb4, +0x3cde,0xe6d8,0x93f6,0x5eba, +0xbd0a,0x5022,0xc297,0xfbeb, +0x3d35,0x9b46,0x4b26,0x2627, +0xbd61,0x164c,0x62ee,0x1af0, +0x3d89,0xfe2f,0xe19b,0xd324, +0xbdb2,0xfc95,0x7a94,0x6abc, +0x3dda,0x98be,0xcc74,0x3c10, +0xbe01,0xd4fe,0x13ae,0x9556, +0x3e26,0xd903,0xa454,0xcb34, +0xbe4b,0xeaf6,0x8c0b,0x30ab, +0x3e70,0x3b76,0x9d4d,0x6435, +0xbe91,0xec63,0x8f22,0x7f8d, +0x3eb2,0xbf24,0x978c,0xf4ac, +0xbed2,0x866f,0xcba5,0x6427, +0x3ef1,0x3f58,0xbe9a,0x2859, +0xbf0e,0x2b26,0x59c4,0x1d5a, +0x3f28,0xb51b,0x7410,0x7cab, +0xbf42,0xe2fd,0x1f15,0xeb52, +0x3f5a,0xdc75,0x8a12,0x100e, +0xbf71,0xb65e,0x201a,0xa849, +0x3f85,0x9961,0xf3dd,0xe3dd, +0xbf98,0x4e9e,0xf121,0xb6f0, +0x3fa9,0x3e8a,0xcea8,0xa32d, +0xbfb8,0x4b70,0x342d,0x06ea, +0x3fc5,0xf7ac,0x77ac,0x88c0, +0xbfd3,0x7feb,0xc057,0xcd8d, +0x3fe5,0xa84e,0x9035,0xa22a +}; +#endif + + +/* Chebyshev coefficients for exp(-x) sqrt(x) I0(x) + * in the inverted interval [8,infinity]. + * + * lim(x->inf){ exp(-x) sqrt(x) I0(x) } = 1/sqrt(2pi). + */ + +#ifdef UNK +static double B[] = +{ +-7.23318048787475395456E-18, +-4.83050448594418207126E-18, + 4.46562142029675999901E-17, + 3.46122286769746109310E-17, +-2.82762398051658348494E-16, +-3.42548561967721913462E-16, + 1.77256013305652638360E-15, + 3.81168066935262242075E-15, +-9.55484669882830764870E-15, +-4.15056934728722208663E-14, + 1.54008621752140982691E-14, + 3.85277838274214270114E-13, + 7.18012445138366623367E-13, +-1.79417853150680611778E-12, +-1.32158118404477131188E-11, +-3.14991652796324136454E-11, + 1.18891471078464383424E-11, + 4.94060238822496958910E-10, + 3.39623202570838634515E-9, + 2.26666899049817806459E-8, + 2.04891858946906374183E-7, + 2.89137052083475648297E-6, + 6.88975834691682398426E-5, + 3.36911647825569408990E-3, + 8.04490411014108831608E-1 +}; +#endif + +#ifdef DEC +static unsigned short B[] = { +0122005,0066672,0123124,0054311, +0121662,0033323,0030214,0104602, +0022515,0170300,0113314,0020413, +0022437,0117350,0035402,0007146, +0123243,0000135,0057220,0177435, +0123305,0073476,0144106,0170702, +0023777,0071755,0017527,0154373, +0024211,0052214,0102247,0033270, +0124454,0017763,0171453,0012322, +0125072,0166316,0075505,0154616, +0024612,0133770,0065376,0025045, +0025730,0162143,0056036,0001632, +0026112,0015077,0150464,0063542, +0126374,0101030,0014274,0065457, +0127150,0077271,0125763,0157617, +0127412,0104350,0040713,0120445, +0027121,0023765,0057500,0001165, +0030407,0147146,0003643,0075644, +0031151,0061445,0044422,0156065, +0031702,0132224,0003266,0125551, +0032534,0000076,0147153,0005555, +0033502,0004536,0004016,0026055, +0034620,0076433,0142314,0171215, +0036134,0146145,0013454,0101104, +0040115,0171425,0062500,0047133 +}; +#endif + +#ifdef IBMPC +static unsigned short B[] = { +0x8b19,0x54ca,0xadb7,0xbc60, +0x9130,0x6611,0x46da,0xbc56, +0x8421,0x12d9,0xbe18,0x3c89, +0x41cd,0x0760,0xf3dd,0x3c83, +0x1fe4,0xabd2,0x600b,0xbcb4, +0xde38,0xd908,0xaee7,0xbcb8, +0xfb1f,0xa3ea,0xee7d,0x3cdf, +0xe6d7,0x9094,0x2a91,0x3cf1, +0x629a,0x7e65,0x83fe,0xbd05, +0xbb32,0xcf68,0x5d99,0xbd27, +0xc545,0x0d5f,0x56ff,0x3d11, +0xc073,0x6b83,0x1c8c,0x3d5b, +0x8cec,0xfa26,0x4347,0x3d69, +0x8d66,0x0317,0x9043,0xbd7f, +0x7bf2,0x357e,0x0fd7,0xbdad, +0x7425,0x0839,0x511d,0xbdc1, +0x004f,0xabe8,0x24fe,0x3daa, +0x6f75,0xc0f4,0xf9cc,0x3e00, +0x5b87,0xa922,0x2c64,0x3e2d, +0xd56d,0x80d6,0x5692,0x3e58, +0x616e,0xd9cd,0x8007,0x3e8b, +0xc586,0xc101,0x412b,0x3ec8, +0x9e52,0x7899,0x0fa3,0x3f12, +0x9049,0xa2e5,0x998c,0x3f6b, +0x09cb,0xaca8,0xbe62,0x3fe9 +}; +#endif + +#ifdef MIEEE +static unsigned short B[] = { +0xbc60,0xadb7,0x54ca,0x8b19, +0xbc56,0x46da,0x6611,0x9130, +0x3c89,0xbe18,0x12d9,0x8421, +0x3c83,0xf3dd,0x0760,0x41cd, +0xbcb4,0x600b,0xabd2,0x1fe4, +0xbcb8,0xaee7,0xd908,0xde38, +0x3cdf,0xee7d,0xa3ea,0xfb1f, +0x3cf1,0x2a91,0x9094,0xe6d7, +0xbd05,0x83fe,0x7e65,0x629a, +0xbd27,0x5d99,0xcf68,0xbb32, +0x3d11,0x56ff,0x0d5f,0xc545, +0x3d5b,0x1c8c,0x6b83,0xc073, +0x3d69,0x4347,0xfa26,0x8cec, +0xbd7f,0x9043,0x0317,0x8d66, +0xbdad,0x0fd7,0x357e,0x7bf2, +0xbdc1,0x511d,0x0839,0x7425, +0x3daa,0x24fe,0xabe8,0x004f, +0x3e00,0xf9cc,0xc0f4,0x6f75, +0x3e2d,0x2c64,0xa922,0x5b87, +0x3e58,0x5692,0x80d6,0xd56d, +0x3e8b,0x8007,0xd9cd,0x616e, +0x3ec8,0x412b,0xc101,0xc586, +0x3f12,0x0fa3,0x7899,0x9e52, +0x3f6b,0x998c,0xa2e5,0x9049, +0x3fe9,0xbe62,0xaca8,0x09cb +}; +#endif + +double i0(double x) +{ +double y; + +if( x < 0 ) + x = -x; +if( x <= 8.0 ) + { + y = (x/2.0) - 2.0; + return( exp(x) * chbevl( y, A, 30 ) ); + } + +return( exp(x) * chbevl( 32.0/x - 2.0, B, 25 ) / sqrt(x) ); + +} + + + + +double i0e(double x ) +{ +double y; + +if( x < 0 ) + x = -x; +if( x <= 8.0 ) + { + y = (x/2.0) - 2.0; + return( chbevl( y, A, 30 ) ); + } + +return( chbevl( 32.0/x - 2.0, B, 25 ) / sqrt(x) ); + +} diff --git a/ao-tools/lib/mconf.h b/ao-tools/lib/mconf.h new file mode 100644 index 00000000..af1ebb51 --- /dev/null +++ b/ao-tools/lib/mconf.h @@ -0,0 +1,211 @@ +/* + * This file comes from the cephes math library, which was + * released under the GPLV2+ license as a part of the Debian labplot + * package (I've included the GPLV2 license reference here to make + * this clear) - Keith Packard + * + * Cephes Math Library Release 2.0: April, 1987 + * Copyright 1984, 1987 by Stephen L. Moshier + * Direct inquiries to 30 Frost Street, Cambridge, MA 02140 + * + * 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. + */ +/* mconf.h + * + * Common include file for math routines + * + * + * + * SYNOPSIS: + * + * #include "mconf.h" + * + * + * + * DESCRIPTION: + * + * This file contains definitions for error codes that are + * passed to the common error handling routine mtherr() + * (which see). + * + * The file also includes a conditional assembly definition + * for the type of computer arithmetic (IEEE, DEC, Motorola + * IEEE, or UNKnown). + * + * For Digital Equipment PDP-11 and VAX computers, certain + * IBM systems, and others that use numbers with a 56-bit + * significand, the symbol DEC should be defined. In this + * mode, most floating point constants are given as arrays + * of octal integers to eliminate decimal to binary conversion + * errors that might be introduced by the compiler. + * + * For little-endian computers, such as IBM PC, that follow the + * IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE + * Std 754-1985), the symbol IBMPC should be defined. These + * numbers have 53-bit significands. In this mode, constants + * are provided as arrays of hexadecimal 16 bit integers. + * + * Big-endian IEEE format is denoted MIEEE. On some RISC + * systems such as Sun SPARC, double precision constants + * must be stored on 8-byte address boundaries. Since integer + * arrays may be aligned differently, the MIEEE configuration + * may fail on such machines. + * + * To accommodate other types of computer arithmetic, all + * constants are also provided in a normal decimal radix + * which one can hope are correctly converted to a suitable + * format by the available C language compiler. To invoke + * this mode, define the symbol UNK. + * + * An important difference among these modes is a predefined + * set of machine arithmetic constants for each. The numbers + * MACHEP (the machine roundoff error), MAXNUM (largest number + * represented), and several other parameters are preset by + * the configuration symbol. Check the file const.c to + * ensure that these values are correct for your computer. + * + * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL + * may fail on many systems. Verify that they are supposed + * to work on your computer. + */ + +/* +Cephes Math Library Release 2.3: June, 1995 +Copyright 1984, 1987, 1989, 1995 by Stephen L. Moshier + +Adjusted for use with ACE/gr by Evgeny Stambulchik, October 1997 +*/ + +#define __GRACE_SOURCE_ + +#include "cmath.h" + +/* Type of computer arithmetic */ +/* In ACE/gr, defined as a compiler directive - no need to define here */ + +/* PDP-11, Pro350, VAX: + */ +#if defined(HAVE_DEC_FPU) +# define DEC 1 +#endif + +/* Intel IEEE, low order words come first: + */ +#if defined(HAVE_LIEEE_FPU) +# define IBMPC 1 +#endif + +/* Motorola IEEE, high order words come first + * (Sun 680x0 workstation): + */ +#if defined(HAVE_BIEEE_FPU) +# define MIEEE 1 +#endif + +/* UNKnown arithmetic, invokes coefficients given in + * normal decimal format. Beware of range boundary + * problems (MACHEP, MAXLOG, etc. in const.c) and + * roundoff problems in pow.c: + * (Sun SPARCstation) + */ + +#if (!defined (DEC) && !defined (IBMPC) && !defined (MIEEE)) +# define UNK 1 +#endif + +/* Define this `volatile' if your compiler thinks + * that floating point arithmetic obeys the associative + * and distributive laws. It will defeat some optimizations + * (but probably not enough of them). + * + * #define VOLATILE volatile + */ + +#ifndef VOLATILE +# define VOLATILE +#endif + +#ifdef PI +# undef PI +#endif + +#ifdef NAN +# undef NAN +#endif + +#ifdef INFINITY +# undef INFINITY +#endif + +/* Constant definitions for math error conditions + */ + +#if defined(DOMAIN) +# undef DOMAIN +#endif +#define DOMAIN 1 /* argument domain error */ + +#if defined(SING) +# undef SING +#endif +#define SING 2 /* argument singularity */ + +#if defined(OVERFLOW) +# undef OVERFLOW +#endif +#define OVERFLOW 3 /* overflow range error */ + +#if defined(UNDERFLOW) +# undef UNDERFLOW +#endif +#define UNDERFLOW 4 /* underflow range error */ + +#if defined(TLOSS) +# undef TLOSS +#endif +#define TLOSS 5 /* total loss of precision */ + +#if defined(PLOSS) +# undef PLOSS +#endif +#define PLOSS 6 /* partial loss of precision */ + +#if defined(EDOM) +# undef EDOM +#endif +#define EDOM 33 + +#if defined(ERANGE) +# undef ERANGE +#endif +#define ERANGE 34 + +#if !defined (UNK) + /* Define to support tiny denormal numbers, else undefine. */ +# define DENORMAL 1 + + /* Define to ask for infinity support, else undefine. */ +# define INFINITIES 1 + + /* Define to ask for support of numbers that are Not-a-Number, + else undefine. This may automatically define INFINITIES in some files. */ +# define NANS 1 + + /* Define to distinguish between -0.0 and +0.0. */ +# define MINUSZERO 1 +#endif + +/* Define 1 for ANSI C atan2() function + See atan.c and clog.c. */ +#define ANSIC 1 -- cgit v1.2.3 From e35e485ffe6b26034788ab295121bc2693b7eec1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Sep 2009 13:04:31 -0700 Subject: Initialize summary_name and detail_name so stuff appears on stdout. Uninitialized variables lead to mysterious results. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index c5814c93..6683c67c 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -205,7 +205,7 @@ main (int argc, char **argv) int c; int serial; char *s; - char *summary_name, *detail_name; + char *summary_name = NULL, *detail_name = NULL; while ((c = getopt_long(argc, argv, "S:D:", options, NULL)) != -1) { switch (c) { -- cgit v1.2.3 From 73f4a57239f770aff603b961169c0e2cfe2c276b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Sep 2009 13:08:54 -0700 Subject: Use pressure speed for drogue and beyond states. Fix differentiation time. Drogue state should always use pressure speeds. Differentiation code was using centi-seconds instead of seconds. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 2 +- ao-tools/lib/cc-integrate.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 6683c67c..0c632c34 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -128,7 +128,7 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file) } if (cooked) { - if (state_start < apogee) { + if (state < ao_flight_drogue) { speed_i = cc_perioddata_max(&cooked->accel_speed, state_start, state_stop); if (speed_i >= 0) speed = cooked->accel_speed.data[speed_i]; diff --git a/ao-tools/lib/cc-integrate.c b/ao-tools/lib/cc-integrate.c index 08ca295c..f9793dcd 100644 --- a/ao-tools/lib/cc-integrate.c +++ b/ao-tools/lib/cc-integrate.c @@ -72,7 +72,7 @@ cc_perioddata_differentiate(struct cc_perioddata *i) d->step = i->step; d->data = calloc (d->num, sizeof(double)); for (n = 1; n < d->num; n++) - d->data[n] = (i->data[n] - i->data[n-1]) / i->step; + d->data[n] = (i->data[n] - i->data[n-1]) / (i->step / 100.0); d->data[0] = d->data[1]; return d; } -- cgit v1.2.3 From d0eac989b1ffc8ae30ba12da403eb4bf1ad42d6b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Sep 2009 13:15:10 -0700 Subject: Don't look at NULL strings (summary_name) Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 0c632c34..c1e4d800 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -230,7 +230,7 @@ main (int argc, char **argv) } } if (detail_name) { - if (!strcmp (summary_name, detail_name)) + if (summary_name && !strcmp (summary_name, detail_name)) detail_file = summary_file; else { detail_file = fopen(detail_name, "w"); -- cgit v1.2.3 From 32d3536706324808df6cd02248a236302b831571 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Sep 2009 16:24:35 -0700 Subject: Add plots to ao-postflight using the plplot library It's not perfect, but it generates .svg plot output. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/Makefile.am | 4 +- ao-tools/ao-postflight/ao-postflight.c | 132 +++++++++++++++++++++---- ao-tools/lib/cc-analyse.c | 174 +++++++++++++++++++++++++++++---- ao-tools/lib/cc-process.c | 18 ++++ ao-tools/lib/cc.h | 29 ++++++ configure.ac | 2 + 6 files changed, 318 insertions(+), 41 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/Makefile.am b/ao-tools/ao-postflight/Makefile.am index 301ac454..589d164a 100644 --- a/ao-tools/ao-postflight/Makefile.am +++ b/ao-tools/ao-postflight/Makefile.am @@ -1,11 +1,11 @@ bin_PROGRAMS=ao-postflight -AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS) $(GNOME_CFLAGS) +AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS) $(GNOME_CFLAGS) $(PLPLOT_CFLAGS) AO_POSTFLIGHT_LIBS=$(top_builddir)/ao-tools/lib/libao-tools.a ao_postflight_DEPENDENCIES = $(AO_POSTFLIGHT_LIBS) -ao_postflight_LDADD=$(AO_POSTFLIGHT_LIBS) $(LIBUSB_LIBS) $(GNOME_LIBS) +ao_postflight_LDADD=$(AO_POSTFLIGHT_LIBS) $(LIBUSB_LIBS) $(GNOME_LIBS) $(PLPLOT_LIBS) ao_postflight_SOURCES = ao-postflight.c diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index c1e4d800..bc6638e9 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -24,8 +24,7 @@ #include #include "cc-usb.h" #include "cc.h" - -#define NUM_BLOCK 512 +#include static const char *state_names[] = { "startup", @@ -40,12 +39,75 @@ static const char *state_names[] = { "invalid" }; -void -analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file) +static void +plot_perioddata(struct cc_perioddata *d, char *axis_label, char *plot_label, + double min_time, double max_time) +{ + double *times; + double ymin, ymax; + int ymin_i, ymax_i; + int i; + int start, stop; + + if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop)) + return; + + times = calloc(stop - start + 1, sizeof (double)); + for (i = start; i <= stop; i++) + times[i-start] = i * d->step / 100.0; + + ymin_i = cc_perioddata_min(d, min_time, max_time); + ymax_i = cc_perioddata_max(d, min_time, max_time); + ymin = d->data[ymin_i]; + ymax = d->data[ymax_i]; + plenv(times[0], times[stop-start], + ymin, ymax, 0, 2); + plcol0(1); + pllab("Time", axis_label, plot_label); + plline(stop - start + 1, times, d->data + start); +} + +static struct cc_perioddata * +merge_data(struct cc_perioddata *first, struct cc_perioddata *last, double split_time) +{ + int i; + struct cc_perioddata *pd; + int num; + double start_time, stop_time; + double t; + + pd = calloc(1, sizeof (struct cc_perioddata)); + start_time = first->start; + stop_time = last->start + last->step * last->num; + num = (stop_time - start_time) / first->step; + pd->num = num; + pd->data = calloc(num, sizeof (double)); + pd->start = first->start; + pd->step = first->step; + for (i = 0; i < num; i++) { + t = pd->start + i * pd->step; + if (t <= split_time) { + pd->data[i] = first->data[i]; + } else { + int j; + + j = (t - last->start) / last->step; + if (j < 0 || j >= last->num) + pd->data[i] = 0; + else + pd->data[i] = last->data[j]; + } + } + return pd; +} + +static void +analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, char *plot_name) { double height; double accel; double speed; + double avg_speed; double boost_start, boost_stop; double min_pres; int i; @@ -129,18 +191,24 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file) if (cooked) { if (state < ao_flight_drogue) { - speed_i = cc_perioddata_max(&cooked->accel_speed, state_start, state_stop); + speed_i = cc_perioddata_max_mag(&cooked->accel_speed, state_start, state_stop); if (speed_i >= 0) speed = cooked->accel_speed.data[speed_i]; + avg_speed = cc_perioddata_average(&cooked->accel_speed, state_start, state_stop); } else { - speed_i = cc_perioddata_max(&cooked->pres_speed, state_start, state_stop); + speed_i = cc_perioddata_max_mag(&cooked->pres_speed, state_start, state_stop); if (speed_i >= 0) speed = cooked->pres_speed.data[speed_i]; + avg_speed = cc_perioddata_average(&cooked->pres_speed, state_start, state_stop); } if (speed_i >= 0) + { fprintf(summary_file, "\tMax speed: %9.2fm/s %9.2fft/s %9.2fs\n", speed, speed * 100 / 2.4 / 12.0, (cooked->accel_speed.start + speed_i * cooked->accel_speed.step - boost_start) / 100.0); + fprintf(summary_file, "\tAvg speed: %9.2fm/s %9.2fft/s\n", + avg_speed, avg_speed * 100 / 2.4 / 12.0); + } } pres_i = cc_timedata_min(&f->pres, state_start, state_stop); if (pres_i >= 0) @@ -154,16 +222,10 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file) } } if (cooked && detail_file) { - double apogee_time; double max_height = 0; int i; + double *times; - for (i = 0; i < cooked->pres_pos.num; i++) { - if (cooked->pres_pos.data[i] > max_height) { - max_height = cooked->pres_pos.data[i]; - apogee_time = cooked->pres_pos.start + cooked->pres_pos.step * i; - } - } fprintf(detail_file, "%9s %9s %9s %9s\n", "time", "height", "speed", "accel"); for (i = 0; i < cooked->pres_pos.num; i++) { @@ -171,7 +233,7 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file) double accel = cooked->accel_accel.data[i]; double pos = cooked->pres_pos.data[i]; double speed; - if (cooked->pres_pos.start + cooked->pres_pos.step * i < apogee_time) + if (cooked->pres_pos.start + cooked->pres_pos.step * i < apogee) speed = cooked->accel_speed.data[i]; else speed = cooked->pres_speed.data[i]; @@ -179,17 +241,41 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file) time, pos, speed, accel); } } + if (cooked && plot_name) { + struct cc_perioddata *speed; + plsdev("svgcairo"); + plsfnam(plot_name); +#define PLOT_DPI 96 + plspage(PLOT_DPI, PLOT_DPI, 8 * PLOT_DPI, 8 * PLOT_DPI, 0, 0); + plscolbg(0xff, 0xff, 0xff); + plscol0(1,0,0,0); + plstar(2, 3); + speed = merge_data(&cooked->accel_speed, &cooked->pres_speed, apogee); + + plot_perioddata(&cooked->pres_pos, "meters", "Height", -1e10, 1e10); + plot_perioddata(&cooked->pres_pos, "meters", "Height", boost_start, apogee); + plot_perioddata(speed, "meters/second", "Speed", -1e10, 1e10); + plot_perioddata(speed, "meters/second", "Speed", boost_start, apogee); + plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration", -1e10, 1e10); + plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration", boost_start, apogee); + free(speed->data); + free(speed); + plend(); + } + if (cooked) + cc_flightcooked_free(cooked); } static const struct option options[] = { - { .name = "summary", .has_arg = 1, .val = 'S' }, - { .name = "detail", .has_arg = 1, .val = 'D' }, + { .name = "summary", .has_arg = 1, .val = 's' }, + { .name = "detail", .has_arg = 1, .val = 'd' }, + { .name = "plot", .has_arg = 1, .val = 'p' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--summary=] [--detail=] [--detail=] {flight-log} ...\n", program); exit(1); } @@ -206,15 +292,19 @@ main (int argc, char **argv) int serial; char *s; char *summary_name = NULL, *detail_name = NULL; + char *plot_name = NULL; - while ((c = getopt_long(argc, argv, "S:D:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "s:d:p:", options, NULL)) != -1) { switch (c) { - case 'S': + case 's': summary_name = optarg; break; - case 'D': + case 'd': detail_name = optarg; break; + case 'p': + plot_name = optarg; + break; default: usage(argv[0]); break; @@ -260,7 +350,7 @@ main (int argc, char **argv) } if (!raw->serial) raw->serial = serial; - analyse_flight(raw, summary_file, detail_file); + analyse_flight(raw, summary_file, detail_file, plot_name); cc_flightraw_free(raw); } return ret; diff --git a/ao-tools/lib/cc-analyse.c b/ao-tools/lib/cc-analyse.c index 0e020115..cdb16f02 100644 --- a/ao-tools/lib/cc-analyse.c +++ b/ao-tools/lib/cc-analyse.c @@ -38,6 +38,26 @@ cc_timedata_min(struct cc_timedata *d, double min_time, double max_time) return min_i; } +int +cc_timedata_min_mag(struct cc_timedata *d, double min_time, double max_time) +{ + int i; + int set = 0; + int min_i = -1; + double min; + + if (d->num == 0) + return -1; + for (i = 0; i < d->num; i++) + if (min_time <= d->data[i].time && d->data[i].time <= max_time) + if (!set || fabs(d->data[i].value) < min) { + min_i = i; + min = fabs(d->data[i].value); + set = 1; + } + return min_i; +} + int cc_timedata_max(struct cc_timedata *d, double min_time, double max_time) { @@ -58,23 +78,81 @@ cc_timedata_max(struct cc_timedata *d, double min_time, double max_time) return max_i; } +int +cc_timedata_max_mag(struct cc_timedata *d, double min_time, double max_time) +{ + int i; + double max; + int max_i = -1; + int set = 0; + + if (d->num == 0) + return -1; + for (i = 0; i < d->num; i++) + if (min_time <= d->data[i].time && d->data[i].time <= max_time) + if (!set || fabs(d->data[i].value) > max) { + max_i = i; + max = fabs(d->data[i].value); + set = 1; + } + return max_i; +} + +double +cc_timedata_average(struct cc_timedata *td, double start_time, double stop_time) +{ + int i; + double prev_time; + double next_time; + double interval; + double sum = 0.0; + double period = 0.0; + + prev_time = start_time; + for (i = 0; i < td->num; i++) { + if (start_time <= td->data[i].time && td->data[i].time <= stop_time) { + if (i < td->num - 1 && td->data[i+1].time < stop_time) + next_time = (td->data[i].time + td->data[i+1].time) / 2.0; + else + next_time = stop_time; + interval = next_time - prev_time; + sum += td->data[i].value * interval; + period += interval; + prev_time = next_time; + } + } + return sum / period; +} + +int +cc_perioddata_limits(struct cc_perioddata *d, double min_time, double max_time, int *start, int *stop) +{ + double start_d, stop_d; + + if (d->num == 0) + return 0; + start_d = ceil((min_time - d->start) / d->step); + if (start_d < 0) + start_d = 0; + stop_d = floor((max_time - d->start) / d->step); + if (stop_d >= d->num) + stop_d = d->num - 1; + if (stop_d < start_d) + return 0; + *start = (int) start_d; + *stop = (int) stop_d; + return 1; +} + int cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time) { - int start, stop; int i; double min; int min_i; + int start, stop; - if (d->num == 0) - return -1; - start = (int) ceil((min_time - d->start) / d->step); - if (start < 0) - start = 0; - stop = (int) floor((max_time - d->start) / d->step); - if (stop >= d->num) - stop = d->num - 1; - if (stop < start) + if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop)) return -1; min = d->data[start]; min_i = start; @@ -86,6 +164,26 @@ cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time) return min_i; } +int +cc_perioddata_min_mag(struct cc_perioddata *d, double min_time, double max_time) +{ + int start, stop; + int i; + double min; + int min_i; + + if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop)) + return -1; + min = d->data[start]; + min_i = start; + for (i = start + 1; i <= stop; i++) + if (fabs(d->data[i]) < min) { + min = fabs(d->data[i]); + min_i = i; + } + return min_i; +} + int cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time) { @@ -94,15 +192,27 @@ cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time) double max; int max_i; - if (d->num == 0) + if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop)) return -1; - start = (int) ceil((min_time - d->start) / d->step); - if (start < 0) - start = 0; - stop = (int) floor((max_time - d->start) / d->step); - if (stop >= d->num) - stop = d->num - 1; - if (stop < start) + max = d->data[start]; + max_i = start; + for (i = start + 1; i <= stop; i++) + if (d->data[i] > max) { + max = d->data[i]; + max_i = i; + } + return max_i; +} + +int +cc_perioddata_max_mag(struct cc_perioddata *d, double min_time, double max_time) +{ + int start, stop; + int i; + double max; + int max_i; + + if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop)) return -1; max = d->data[start]; max_i = start; @@ -113,3 +223,31 @@ cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time) } return max_i; } + +double +cc_perioddata_average(struct cc_perioddata *d, double min_time, double max_time) +{ + int start, stop; + int i; + double sum = 0.0; + + if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop)) + return 0.0; + for (i = start; i <= stop; i++) + sum += d->data[i]; + return sum / (stop - start + 1); +} + +double +cc_perioddata_average_mag(struct cc_perioddata *d, double min_time, double max_time) +{ + int start, stop; + int i; + double sum = 0.0; + + if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop)) + return 0.0; + for (i = start; i <= stop; i++) + sum += fabs(d->data[i]); + return sum / (stop - start + 1); +} diff --git a/ao-tools/lib/cc-process.c b/ao-tools/lib/cc-process.c index e906b635..469ad2f2 100644 --- a/ao-tools/lib/cc-process.c +++ b/ao-tools/lib/cc-process.c @@ -138,3 +138,21 @@ cc_flight_cook(struct cc_flightraw *raw) cooked->state.time_offset = raw->state.time_offset; return cooked; } + +#define if_free(x) ((x) ? free(x) : (void) 0) + +void +cc_flightcooked_free(struct cc_flightcooked *cooked) +{ + if_free(cooked->accel_accel.data); + if_free(cooked->accel_speed.data); + if_free(cooked->accel_pos.data); + if_free(cooked->pres_pos.data); + if_free(cooked->pres_speed.data); + if_free(cooked->pres_accel.data); + if_free(cooked->gps_lat.data); + if_free(cooked->gps_lon.data); + if_free(cooked->gps_alt.data); + if_free(cooked->state.data); + free(cooked); +} diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 356794e0..4e9aadc4 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -265,15 +265,42 @@ cc_great_circle (double start_lat, double start_lon, int cc_timedata_min(struct cc_timedata *d, double min_time, double max_time); +int +cc_timedata_min_mag(struct cc_timedata *d, double min_time, double max_time); + int cc_timedata_max(struct cc_timedata *d, double min_time, double max_time); +int +cc_timedata_max_mag(struct cc_timedata *d, double min_time, double max_time); + +double +cc_timedata_average(struct cc_timedata *d, double min_time, double max_time); + +double +cc_timedata_average_mag(struct cc_timedata *d, double min_time, double max_time); + +int +cc_perioddata_limits(struct cc_perioddata *d, double min_time, double max_time, int *start, int *stop); + int cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time); +int +cc_perioddata_min_mag(struct cc_perioddata *d, double min_time, double max_time); + int cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time); +int +cc_perioddata_max_mag(struct cc_perioddata *d, double min_time, double max_time); + +double +cc_perioddata_average(struct cc_perioddata *d, double min_time, double max_time); + +double +cc_perioddata_average_mag(struct cc_perioddata *d, double min_time, double max_time); + double * cc_low_pass(double *data, int data_len, double omega_pass, double omega_stop, double error); @@ -295,5 +322,7 @@ cc_perioddata_differentiate(struct cc_perioddata *i); struct cc_flightcooked * cc_flight_cook(struct cc_flightraw *raw); +void +cc_flightcooked_free(struct cc_flightcooked *cooked); #endif /* _CC_H_ */ diff --git a/configure.ac b/configure.ac index c668df04..6265c34e 100644 --- a/configure.ac +++ b/configure.ac @@ -71,6 +71,8 @@ PKG_CHECK_MODULES([LIBUSB], [libusb-1.0]) PKG_CHECK_MODULES([ALSA], [alsa]) +PKG_CHECK_MODULES([PLPLOT], [plplotd-gnome2]) + AC_OUTPUT([ Makefile ao-tools/Makefile -- cgit v1.2.3 From 9177f5f4e9d832558ddd9ab227c4511f6201e7e5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Sep 2009 18:11:24 -0700 Subject: Update usage and man page for ao-postflight --- ao-tools/ao-postflight/ao-postflight.1 | 10 +++++++++- ao-tools/ao-postflight/ao-postflight.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.1 b/ao-tools/ao-postflight/ao-postflight.1 index fe02587f..ac1c18a4 100644 --- a/ao-tools/ao-postflight/ao-postflight.1 +++ b/ao-tools/ao-postflight/ao-postflight.1 @@ -21,9 +21,17 @@ ao-postflight \- Analyse a flight log (either telemetry or eeprom) .SH SYNOPSIS .B "ao-postflight" +[\-s ] +[\--summary=] +[\-d ] +[\-p ] +[\--plot=] {flight.eeprom|flight.telem} .SH DESCRIPTION .I ao-postflight -reads the specified flight log and produces a summary of the flight on stdout. +reads the specified flight log and produces a summary of the flight on +stdout or to the specified file along with an optional .svg format +plot and detailed table of time/height/speed/accel. .SH AUTHOR Keith Packard diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index bc6638e9..4ca39c24 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -275,7 +275,7 @@ static const struct option options[] = { static void usage(char *program) { - fprintf(stderr, "usage: %s [--summary=] [--detail=] {flight-log} ...\n", program); + fprintf(stderr, "usage: %s [--summary=] [-s ] [--detail=] [--plot= -p ] {flight-log} ...\n", program); exit(1); } -- cgit v1.2.3 From 932f1539b38567e565fd484171c13539b1467308 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Sep 2009 20:26:17 -0700 Subject: Color plots, integrate only flight portion of data. Telemetry files have piles of pad data which shouldn't be integrated into the velocity data as it tends to generate huge values from the noise of the sensor. Also make the data lines colored to keep them visually distinct from the rest of the plot image. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.1 | 22 ++++-- ao-tools/ao-postflight/ao-postflight.c | 118 ++++++++++++++++++++++++++++----- ao-tools/lib/cc-analyse.c | 14 ++++ ao-tools/lib/cc-integrate.c | 21 +++--- ao-tools/lib/cc-period.c | 26 +++----- ao-tools/lib/cc-process.c | 20 ++++-- ao-tools/lib/cc.h | 12 +++- 7 files changed, 180 insertions(+), 53 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.1 b/ao-tools/ao-postflight/ao-postflight.1 index ac1c18a4..eca4bb34 100644 --- a/ao-tools/ao-postflight/ao-postflight.1 +++ b/ao-tools/ao-postflight/ao-postflight.1 @@ -23,15 +23,29 @@ ao-postflight \- Analyse a flight log (either telemetry or eeprom) .B "ao-postflight" [\-s ] [\--summary=] -[\-d ] [\--detail=] +[\-r ] +[\--raw=] [\-p ] [\--plot=] {flight.eeprom|flight.telem} .SH DESCRIPTION .I ao-postflight -reads the specified flight log and produces a summary of the flight on -stdout or to the specified file along with an optional .svg format -plot and detailed table of time/height/speed/accel. +reads the specified flight log and produces several different kinds of +output. +.IP Summary +By default, summary information is shown on stdout. With the --summary +option, it can be redirected to a file. +.IP Detail +When requested with the --detail option, a filtered version of the +flight position, speed and acceleration are written to the specified +file. +.IP Raw +The --raw option writes the unfiltered, but converted acceleration +and height data to the specified file. +.IP Plot +The --plot option writes plots of height, speed and acceleration to +the specified file in .svg format .SH AUTHOR Keith Packard diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 4ca39c24..ded2f3c2 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -39,9 +39,19 @@ static const char *state_names[] = { "invalid" }; +static int plot_colors[3][3] = { + { 0, 0x90, 0 }, /* height */ + { 0xa0, 0, 0 }, /* speed */ + { 0, 0, 0xc0 }, /* accel */ +}; + +#define PLOT_HEIGHT 0 +#define PLOT_SPEED 1 +#define PLOT_ACCEL 2 + static void plot_perioddata(struct cc_perioddata *d, char *axis_label, char *plot_label, - double min_time, double max_time) + double min_time, double max_time, int plot_type) { double *times; double ymin, ymax; @@ -60,11 +70,58 @@ plot_perioddata(struct cc_perioddata *d, char *axis_label, char *plot_label, ymax_i = cc_perioddata_max(d, min_time, max_time); ymin = d->data[ymin_i]; ymax = d->data[ymax_i]; + plscol0(1, 0, 0, 0); + plscol0(2, plot_colors[plot_type][0], plot_colors[plot_type][1], plot_colors[plot_type][2]); + plcol0(1); plenv(times[0], times[stop-start], ymin, ymax, 0, 2); - plcol0(1); pllab("Time", axis_label, plot_label); + plcol0(2); plline(stop - start + 1, times, d->data + start); + free(times); +} + +static void +plot_timedata(struct cc_timedata *d, char *axis_label, char *plot_label, + double min_time, double max_time) +{ + double *times; + double *values; + double ymin, ymax; + int ymin_i, ymax_i; + int i; + int start = -1, stop = -1; + double start_time = 0, stop_time = 0; + int num; + + for (i = 0; i < d->num; i++) { + if (start < 0 && d->data[i].time >= min_time) { + start_time = d->data[i].time; + start = i; + } + if (d->data[i].time <= max_time) { + stop_time = d->data[i].time; + stop = i; + } + } + + times = calloc(stop - start + 1, sizeof (double)); + values = calloc(stop - start + 1, sizeof (double)); + + ymin_i = cc_timedata_min(d, min_time, max_time); + ymax_i = cc_timedata_max(d, min_time, max_time); + ymin = d->data[ymin_i].value; + ymax = d->data[ymax_i].value; + plcol0(1); + pllab("Time", axis_label, plot_label); + for (i = start; i <= stop; i++) { + times[i-start] = (d->data[i].time - start_time)/100.0; + values[i-start] = d->data[i].value; + } + plenv(times[0], times[stop-start], ymin, ymax, 0, 2); + plline(stop - start + 1, times, values); + free(times); + free(values); } static struct cc_perioddata * @@ -102,7 +159,7 @@ merge_data(struct cc_perioddata *first, struct cc_perioddata *last, double split } static void -analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, char *plot_name) +analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FILE *raw_file, char *plot_name) { double height; double accel; @@ -241,6 +298,17 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, ch time, pos, speed, accel); } } + if (raw_file) { + fprintf(raw_file, "%9s %9s %9s\n", + "time", "height", "accel"); + for (i = 0; i < cooked->pres.num; i++) { + double time = cooked->pres.data[i].time; + double pres = cooked->pres.data[i].value; + double accel = cooked->accel.data[i].value; + fprintf(raw_file, "%9.2f %9.2f %9.2f %9.2f\n", + time, pres, accel); + } + } if (cooked && plot_name) { struct cc_perioddata *speed; plsdev("svgcairo"); @@ -252,12 +320,12 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, ch plstar(2, 3); speed = merge_data(&cooked->accel_speed, &cooked->pres_speed, apogee); - plot_perioddata(&cooked->pres_pos, "meters", "Height", -1e10, 1e10); - plot_perioddata(&cooked->pres_pos, "meters", "Height", boost_start, apogee); - plot_perioddata(speed, "meters/second", "Speed", -1e10, 1e10); - plot_perioddata(speed, "meters/second", "Speed", boost_start, apogee); - plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration", -1e10, 1e10); - plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration", boost_start, apogee); + plot_perioddata(&cooked->pres_pos, "meters", "Height", -1e10, 1e10, PLOT_HEIGHT); + plot_perioddata(&cooked->pres_pos, "meters", "Height to Apogee", boost_start, apogee, PLOT_HEIGHT); + plot_perioddata(speed, "meters/second", "Speed", -1e10, 1e10, PLOT_SPEED); + plot_perioddata(speed, "meters/second", "Speed to Apogee", boost_start, apogee, PLOT_SPEED); + plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration", -1e10, 1e10, PLOT_ACCEL); + plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration to Apogee", boost_start, apogee, PLOT_ACCEL); free(speed->data); free(speed); plend(); @@ -270,12 +338,18 @@ static const struct option options[] = { { .name = "summary", .has_arg = 1, .val = 's' }, { .name = "detail", .has_arg = 1, .val = 'd' }, { .name = "plot", .has_arg = 1, .val = 'p' }, + { .name = "raw", .has_arg = 1, .val = 'r' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--summary=] [-s ] [--detail=] [--plot= -p ] {flight-log} ...\n", program); + fprintf(stderr, "usage: %s\n" + "\t[--summary=] [-s ]\n" + "\t[--detail=]\n" + "\t[--raw= -r -p ]\n" + "\t{flight-log} ...\n", program); exit(1); } @@ -283,18 +357,21 @@ int main (int argc, char **argv) { FILE *file; - FILE *summary_file; - FILE *detail_file; + FILE *summary_file = NULL; + FILE *detail_file = NULL; + FILE *raw_file = NULL; int i; int ret = 0; struct cc_flightraw *raw; int c; int serial; char *s; - char *summary_name = NULL, *detail_name = NULL; + char *summary_name = NULL; + char *detail_name = NULL; + char *raw_name = NULL; char *plot_name = NULL; - while ((c = getopt_long(argc, argv, "s:d:p:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "s:d:p:r:", options, NULL)) != -1) { switch (c) { case 's': summary_name = optarg; @@ -305,13 +382,15 @@ main (int argc, char **argv) case 'p': plot_name = optarg; break; + case 'r': + raw_name = optarg; + break; default: usage(argv[0]); break; } } summary_file = stdout; - detail_file = NULL; if (summary_name) { summary_file = fopen(summary_name, "w"); if (!summary_file) { @@ -330,6 +409,13 @@ main (int argc, char **argv) } } } + if (raw_name) { + raw_file = fopen (raw_name, "w"); + if (!raw_file) { + perror(raw_name); + exit(1); + } + } for (i = optind; i < argc; i++) { file = fopen(argv[i], "r"); if (!file) { @@ -350,7 +436,7 @@ main (int argc, char **argv) } if (!raw->serial) raw->serial = serial; - analyse_flight(raw, summary_file, detail_file, plot_name); + analyse_flight(raw, summary_file, detail_file, raw_file, plot_name); cc_flightraw_free(raw); } return ret; diff --git a/ao-tools/lib/cc-analyse.c b/ao-tools/lib/cc-analyse.c index cdb16f02..27c416a6 100644 --- a/ao-tools/lib/cc-analyse.c +++ b/ao-tools/lib/cc-analyse.c @@ -18,6 +18,20 @@ #include "cc.h" #include +void +cc_timedata_limits(struct cc_timedata *d, double min_time, double max_time, int *start, int *stop) +{ + int i; + + *start = -1; + for (i = 0; i < d->num; i++) { + if (*start < 0 && min_time <= d->data[i].time) + *start = i; + if (d->data[i].time <= max_time) + *stop = i; + } +} + int cc_timedata_min(struct cc_timedata *d, double min_time, double max_time) { diff --git a/ao-tools/lib/cc-integrate.c b/ao-tools/lib/cc-integrate.c index f9793dcd..ba50761b 100644 --- a/ao-tools/lib/cc-integrate.c +++ b/ao-tools/lib/cc-integrate.c @@ -37,24 +37,27 @@ cc_timedata_convert(struct cc_timedata *d, double (*f)(double v, double a), doub } struct cc_timedata * -cc_timedata_integrate(struct cc_timedata *d) +cc_timedata_integrate(struct cc_timedata *d, double min_time, double max_time) { struct cc_timedata *i; - int n; + int n, m; + int start, stop; + cc_timedata_limits(d, min_time, max_time, &start, &stop); i = calloc (1, sizeof (struct cc_timedata)); - i->num = d->num; - i->size = d->num; + i->num = stop - start + 1; + i->size = i->num; i->data = calloc (i->size, sizeof (struct cc_timedataelt)); - i->time_offset = d->time_offset; - for (n = 0; n < d->num; n++) { - i->data[n].time = d->data[n].time; + i->time_offset = d->data[start].time; + for (n = 0; n < i->num; n++) { + m = n + start; + i->data[n].time = d->data[m].time; if (n == 0) { i->data[n].value = 0; } else { i->data[n].value = i->data[n-1].value + - (d->data[n].value + d->data[n-1].value) / 2 * - ((d->data[n].time - d->data[n-1].time) / 100.0); + (d->data[m].value + d->data[m-1].value) / 2 * + ((d->data[m].time - d->data[m-1].time) / 100.0); } } return i; diff --git a/ao-tools/lib/cc-period.c b/ao-tools/lib/cc-period.c index c74cf9dc..2a4e5952 100644 --- a/ao-tools/lib/cc-period.c +++ b/ao-tools/lib/cc-period.c @@ -17,35 +17,27 @@ #include "cc.h" #include +#include struct cc_perioddata * cc_period_make(struct cc_timedata *td, double start_time, double stop_time) { int len = stop_time - start_time + 1; struct cc_perioddata *pd; - int i; - double prev_time; - double next_time; - double interval; + int i, j; + double t; pd = calloc(1, sizeof (struct cc_perioddata)); pd->start = start_time; pd->step = 1; pd->num = len; pd->data = calloc(len, sizeof(double)); - prev_time = start_time; - for (i = 0; i < td->num; i++) { - if (start_time <= td->data[i].time && td->data[i].time <= stop_time) { - int pos = td->data[i].time - start_time; - - if (i < td->num - 1 && td->data[i+1].time < stop_time) - next_time = (td->data[i].time + td->data[i+1].time) / 2.0; - else - next_time = stop_time; - interval = next_time - prev_time; - pd->data[pos] = td->data[i].value * interval; - prev_time = next_time; - } + j = 0; + for (i = 0; i < pd->num; i++) { + t = start_time + i * pd->step; + while (j < td->num - 1 && fabs(t - td->data[j].time) > fabs(t - td->data[j+1].time)) + j++; + pd->data[i] = td->data[j].value; } return pd; } diff --git a/ao-tools/lib/cc-process.c b/ao-tools/lib/cc-process.c index 469ad2f2..5c1acc6b 100644 --- a/ao-tools/lib/cc-process.c +++ b/ao-tools/lib/cc-process.c @@ -33,8 +33,6 @@ cook_timed(struct cc_timedata *td, struct cc_perioddata *pd, free (filtered); free (unfiltered->data); free (unfiltered); - free (td->data); - free (td); } static double @@ -93,11 +91,15 @@ cc_flight_cook(struct cc_flightraw *raw) } else { flight_stop = raw->accel.data[raw->accel.num-1].time; } + cooked->flight_start = flight_start; + cooked->flight_stop = flight_stop; /* Integrate the accelerometer data to get speed and position */ accel = cc_timedata_convert(&raw->accel, cc_accelerometer_to_acceleration, raw->ground_accel); - accel_speed = cc_timedata_integrate(accel); - accel_pos = cc_timedata_integrate(accel_speed); + cooked->accel = *accel; + free(accel); + accel_speed = cc_timedata_integrate(&cooked->accel, flight_start - 10, flight_stop); + accel_pos = cc_timedata_integrate(accel_speed, flight_start - 10, flight_stop); #define ACCEL_OMEGA_PASS (2 * M_PI * 5 / 100) #define ACCEL_OMEGA_STOP (2 * M_PI * 8 / 100) @@ -105,20 +107,24 @@ cc_flight_cook(struct cc_flightraw *raw) #define BARO_OMEGA_STOP (2 * M_PI * 1 / 100) #define FILTER_ERROR (1e-8) - cook_timed(accel, &cooked->accel_accel, + cook_timed(&cooked->accel, &cooked->accel_accel, flight_start, flight_stop, ACCEL_OMEGA_PASS, ACCEL_OMEGA_STOP, FILTER_ERROR); cook_timed(accel_speed, &cooked->accel_speed, flight_start, flight_stop, ACCEL_OMEGA_PASS, ACCEL_OMEGA_STOP, FILTER_ERROR); + free(accel_speed->data); free(accel_speed); cook_timed(accel_pos, &cooked->accel_pos, flight_start, flight_stop, ACCEL_OMEGA_PASS, ACCEL_OMEGA_STOP, FILTER_ERROR); + free(accel_pos->data); free(accel_pos); /* Filter the pressure data */ pres = cc_timedata_convert(&raw->pres, barometer_to_altitude, cc_barometer_to_altitude(raw->ground_pres)); - cook_timed(pres, &cooked->pres_pos, + cooked->pres = *pres; + free(pres); + cook_timed(&cooked->pres, &cooked->pres_pos, flight_start, flight_stop, BARO_OMEGA_PASS, BARO_OMEGA_STOP, FILTER_ERROR); /* differentiate twice to get to acceleration */ @@ -154,5 +160,7 @@ cc_flightcooked_free(struct cc_flightcooked *cooked) if_free(cooked->gps_lon.data); if_free(cooked->gps_alt.data); if_free(cooked->state.data); + if_free(cooked->accel.data); + if_free(cooked->pres.data); free(cooked); } diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 4e9aadc4..01226958 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -142,6 +142,9 @@ void cc_flightraw_free(struct cc_flightraw *raw); struct cc_flightcooked { + double flight_start; + double flight_stop; + struct cc_perioddata accel_accel; struct cc_perioddata accel_speed; struct cc_perioddata accel_pos; @@ -151,6 +154,10 @@ struct cc_flightcooked { struct cc_perioddata gps_lat; struct cc_perioddata gps_lon; struct cc_perioddata gps_alt; + + /* unfiltered, but converted */ + struct cc_timedata pres; + struct cc_timedata accel; struct cc_timedata state; }; @@ -262,6 +269,9 @@ cc_great_circle (double start_lat, double start_lon, double end_lat, double end_lon, double *dist, double *bearing); +void +cc_timedata_limits(struct cc_timedata *d, double min_time, double max_time, int *start, int *stop); + int cc_timedata_min(struct cc_timedata *d, double min_time, double max_time); @@ -314,7 +324,7 @@ struct cc_timedata * cc_timedata_convert(struct cc_timedata *d, double (*f)(double v, double a), double a); struct cc_timedata * -cc_timedata_integrate(struct cc_timedata *d); +cc_timedata_integrate(struct cc_timedata *d, double min_time, double max_time); struct cc_perioddata * cc_perioddata_differentiate(struct cc_perioddata *i); -- cgit v1.2.3 From 9e660315e1bd2bf71ab1c0574e895e1f7608a58f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Sep 2009 21:01:44 -0700 Subject: Fix cc_period_make to not get stuck on samples with matching time When two samples have matching times, step to the second one; otherwise, we'll get stuck forever. Signed-off-by: Keith Packard --- ao-tools/lib/cc-period.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/lib/cc-period.c b/ao-tools/lib/cc-period.c index 2a4e5952..844ac79e 100644 --- a/ao-tools/lib/cc-period.c +++ b/ao-tools/lib/cc-period.c @@ -35,7 +35,7 @@ cc_period_make(struct cc_timedata *td, double start_time, double stop_time) j = 0; for (i = 0; i < pd->num; i++) { t = start_time + i * pd->step; - while (j < td->num - 1 && fabs(t - td->data[j].time) > fabs(t - td->data[j+1].time)) + while (j < td->num - 1 && fabs(t - td->data[j].time) >= fabs(t - td->data[j+1].time)) j++; pd->data[i] = td->data[j].value; } -- cgit v1.2.3 From 8b485d937ff148848ebda7f9ca6be29bb1de1f16 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Sep 2009 21:02:48 -0700 Subject: Show acceleration only during boost phase. We're interested in motor performance; the rest of the flight is boring, after all. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index ded2f3c2..3a6f04b6 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -325,7 +325,7 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FI plot_perioddata(speed, "meters/second", "Speed", -1e10, 1e10, PLOT_SPEED); plot_perioddata(speed, "meters/second", "Speed to Apogee", boost_start, apogee, PLOT_SPEED); plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration", -1e10, 1e10, PLOT_ACCEL); - plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration to Apogee", boost_start, apogee, PLOT_ACCEL); + plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration during Boost", boost_start, boost_stop + (boost_stop - boost_start) / 2.0, PLOT_ACCEL); free(speed->data); free(speed); plend(); -- cgit v1.2.3 From 078e9cdbdb388b22c6151f76ff0660fc14b8ef55 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 10 Sep 2009 11:53:06 -0700 Subject: Plot raw accel data for the motor accel section. This shows a short sequence of accelerometer data without any filtering. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 3a6f04b6..1e6ac744 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -83,7 +83,7 @@ plot_perioddata(struct cc_perioddata *d, char *axis_label, char *plot_label, static void plot_timedata(struct cc_timedata *d, char *axis_label, char *plot_label, - double min_time, double max_time) + double min_time, double max_time, int plot_type) { double *times; double *values; @@ -112,13 +112,16 @@ plot_timedata(struct cc_timedata *d, char *axis_label, char *plot_label, ymax_i = cc_timedata_max(d, min_time, max_time); ymin = d->data[ymin_i].value; ymax = d->data[ymax_i].value; - plcol0(1); - pllab("Time", axis_label, plot_label); for (i = start; i <= stop; i++) { times[i-start] = (d->data[i].time - start_time)/100.0; values[i-start] = d->data[i].value; } + plscol0(1, 0, 0, 0); + plscol0(2, plot_colors[plot_type][0], plot_colors[plot_type][1], plot_colors[plot_type][2]); + plcol0(1); plenv(times[0], times[stop-start], ymin, ymax, 0, 2); + pllab("Time", axis_label, plot_label); + plcol0(2); plline(stop - start + 1, times, values); free(times); free(values); @@ -320,12 +323,20 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FI plstar(2, 3); speed = merge_data(&cooked->accel_speed, &cooked->pres_speed, apogee); - plot_perioddata(&cooked->pres_pos, "meters", "Height", -1e10, 1e10, PLOT_HEIGHT); - plot_perioddata(&cooked->pres_pos, "meters", "Height to Apogee", boost_start, apogee, PLOT_HEIGHT); - plot_perioddata(speed, "meters/second", "Speed", -1e10, 1e10, PLOT_SPEED); - plot_perioddata(speed, "meters/second", "Speed to Apogee", boost_start, apogee, PLOT_SPEED); - plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration", -1e10, 1e10, PLOT_ACCEL); - plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration during Boost", boost_start, boost_stop + (boost_stop - boost_start) / 2.0, PLOT_ACCEL); + plot_perioddata(&cooked->pres_pos, "meters", "Height", + -1e10, 1e10, PLOT_HEIGHT); + plot_perioddata(&cooked->pres_pos, "meters", "Height to Apogee", + boost_start, apogee + (apogee - boost_start) / 10.0, PLOT_HEIGHT); + plot_perioddata(speed, "meters/second", "Speed", + -1e10, 1e10, PLOT_SPEED); + plot_perioddata(speed, "meters/second", "Speed to Apogee", + boost_start, apogee + (apogee - boost_start) / 10.0, PLOT_SPEED); + plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration", + -1e10, 1e10, PLOT_ACCEL); +/* plot_perioddata(&cooked->accel_accel, "meters/second²", "Acceleration during Boost", + boost_start, boost_stop + (boost_stop - boost_start) / 2.0, PLOT_ACCEL); */ + plot_timedata(&cooked->accel, "meters/second²", "Acceleration during Boost", + boost_start, boost_stop + (boost_stop - boost_start) / 2.0, PLOT_ACCEL); free(speed->data); free(speed); plend(); -- cgit v1.2.3 From bc7ccb339e538a0e6120db0e5c0d9130c565e0dd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 20 Sep 2009 13:32:59 -0700 Subject: ao_rawload: Don't reset after we finish loading --- ao-tools/ao-rawload/ao-rawload.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-rawload/ao-rawload.c b/ao-tools/ao-rawload/ao-rawload.c index 255f63ec..d9ee5718 100644 --- a/ao-tools/ao-rawload/ao-rawload.c +++ b/ao-tools/ao-rawload/ao-rawload.c @@ -105,8 +105,6 @@ main (int argc, char **argv) ccdbg_close(dbg); exit(1); } - ccdbg_set_pc(dbg, image->address); - ccdbg_resume(dbg); ccdbg_close(dbg); exit (0); } -- cgit v1.2.3 From 7ea371a09385e2a93199f78685e8cb86793ed104 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 20 Sep 2009 13:33:26 -0700 Subject: Add --gps option to ao-postflight --- ao-tools/ao-postflight/ao-postflight.c | 31 ++++++++++++++-- ao-tools/lib/cc-logfile.c | 66 ++++++++++++++++++++++++++++++++-- ao-tools/lib/cc.h | 25 +++++++++++++ 3 files changed, 116 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 1e6ac744..6418521e 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -162,7 +162,7 @@ merge_data(struct cc_perioddata *first, struct cc_perioddata *last, double split } static void -analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FILE *raw_file, char *plot_name) +analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FILE *raw_file, char *plot_name, FILE *gps_file) { double height; double accel; @@ -312,6 +312,17 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FI time, pres, accel); } } + if (gps_file) { + fprintf(gps_file, "%9s %12s %12s %12s\n", + "time", "lat", "lon", "alt"); + for (i = 0; i < f->gps.num; i++) { + fprintf(gps_file, "%12.7f %12.7f %12.7f %12.7f\n", + (f->gps.data[i].time - boost_start) / 100.0, + f->gps.data[i].lat, + f->gps.data[i].lon, + f->gps.data[i].alt); + } + } if (cooked && plot_name) { struct cc_perioddata *speed; plsdev("svgcairo"); @@ -350,6 +361,7 @@ static const struct option options[] = { { .name = "detail", .has_arg = 1, .val = 'd' }, { .name = "plot", .has_arg = 1, .val = 'p' }, { .name = "raw", .has_arg = 1, .val = 'r' }, + { .name = "gps", .has_arg = 1, .val = 'g' }, { 0, 0, 0, 0}, }; @@ -360,6 +372,7 @@ static void usage(char *program) "\t[--detail=]\n" "\t[--raw= -r -p ]\n" + "\t[--gps= -g ]\n" "\t{flight-log} ...\n", program); exit(1); } @@ -371,6 +384,7 @@ main (int argc, char **argv) FILE *summary_file = NULL; FILE *detail_file = NULL; FILE *raw_file = NULL; + FILE *gps_file = NULL; int i; int ret = 0; struct cc_flightraw *raw; @@ -381,8 +395,9 @@ main (int argc, char **argv) char *detail_name = NULL; char *raw_name = NULL; char *plot_name = NULL; + char *gps_name = NULL; - while ((c = getopt_long(argc, argv, "s:d:p:r:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "s:d:p:r:g:", options, NULL)) != -1) { switch (c) { case 's': summary_name = optarg; @@ -396,6 +411,9 @@ main (int argc, char **argv) case 'r': raw_name = optarg; break; + case 'g': + gps_name = optarg; + break; default: usage(argv[0]); break; @@ -427,6 +445,13 @@ main (int argc, char **argv) exit(1); } } + if (gps_name) { + gps_file = fopen(gps_name, "w"); + if (!gps_file) { + perror(gps_name); + exit(1); + } + } for (i = optind; i < argc; i++) { file = fopen(argv[i], "r"); if (!file) { @@ -447,7 +472,7 @@ main (int argc, char **argv) } if (!raw->serial) raw->serial = serial; - analyse_flight(raw, summary_file, detail_file, raw_file, plot_name); + analyse_flight(raw, summary_file, detail_file, raw_file, plot_name, gps_file); cc_flightraw_free(raw); } return ret; diff --git a/ao-tools/lib/cc-logfile.c b/ao-tools/lib/cc-logfile.c index 4abf7eb6..2136eec4 100644 --- a/ao-tools/lib/cc-logfile.c +++ b/ao-tools/lib/cc-logfile.c @@ -80,6 +80,44 @@ gpsdata_add(struct cc_gpsdata *data, struct cc_gpselt *elt) return 1; } +static int +gpssat_add(struct cc_gpsdata *data, struct cc_gpssat *sat) +{ + int i, j; + int reuse = 0; + int newsizesats; + struct cc_gpssats *newsats; + + for (i = data->numsats; --i >= 0;) { + if (data->sats[i].sat[0].time == sat->time) { + reuse = 1; + break; + } + if (data->sats[i].sat[0].time < sat->time) + break; + } + if (!reuse) { + if (data->numsats == data->sizesats) { + if (data->sizesats == 0) + newsats = malloc((newsizesats = 256) * sizeof (struct cc_gpssats)); + else + newsats = realloc (data->data, (newsizesats = data->sizesats * 2) + * sizeof (struct cc_gpssats)); + if (!newsats) + return 0; + data->sats = newsats; + } + i = data->numsats++; + data->sats[i].nsat = 0; + } + j = data->sats[i].nsat; + if (j < 12) { + data->sats[i].sat[j] = *sat; + data->sats[i].nsat = j + 1; + } + return 1; +} + static void gpsdata_free(struct cc_gpsdata *data) { @@ -100,13 +138,20 @@ gpsdata_free(struct cc_gpsdata *data) #define AO_LOG_POS_NONE (~0UL) +#define GPS_TIME 1 +#define GPS_LAT 2 +#define GPS_LON 4 +#define GPS_ALT 8 + static int read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int *ground_pres_count) { char type; int tick; int a, b; - struct cc_gpselt gps; + static struct cc_gpselt gps; + static int gps_valid; + struct cc_gpssat sat; int serial; if (sscanf(line, "serial-number %u", &serial) == 1) { @@ -145,23 +190,38 @@ read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int * timedata_add(&f->state, tick, a); break; case AO_LOG_GPS_TIME: + /* the flight computer writes TIME first, so reset + * any stale data before adding this record + */ gps.time = tick; + gps_valid = GPS_TIME; break; case AO_LOG_GPS_LAT: gps.lat = ((int32_t) (a + (b << 16))) / 10000000.0; + gps_valid |= GPS_LAT; break; case AO_LOG_GPS_LON: gps.lon = ((int32_t) (a + (b << 16))) / 10000000.0; + gps_valid |= GPS_LON; break; case AO_LOG_GPS_ALT: - gps.alt = ((int32_t) (a + (b << 16))); - gpsdata_add(&f->gps, &gps); + gps.alt = (int16_t) a; + gps_valid |= GPS_ALT; break; case AO_LOG_GPS_SAT: + sat.time = tick; + sat.svid = a; + sat.state = (b & 0xff); + sat.c_n = (b >> 8) & 0xff; + gpssat_add(&f->gps, &sat); break; default: return 0; } + if (gps_valid == 0xf) { + gps_valid = 0; + gpsdata_add(&f->gps, &gps); + } return 1; } diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 01226958..b5f1132f 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -19,6 +19,7 @@ #define _CC_H_ #include +#include char * cc_fullname (char *dir, char *file); @@ -90,11 +91,35 @@ struct cc_gpselt { double alt; }; +#define SIRF_SAT_STATE_ACQUIRED (1 << 0) +#define SIRF_SAT_STATE_CARRIER_PHASE_VALID (1 << 1) +#define SIRF_SAT_BIT_SYNC_COMPLETE (1 << 2) +#define SIRF_SAT_SUBFRAME_SYNC_COMPLETE (1 << 3) +#define SIRF_SAT_CARRIER_PULLIN_COMPLETE (1 << 4) +#define SIRF_SAT_CODE_LOCKED (1 << 5) +#define SIRF_SAT_ACQUISITION_FAILED (1 << 6) +#define SIRF_SAT_EPHEMERIS_AVAILABLE (1 << 7) + +struct cc_gpssat { + double time; + uint16_t svid; + uint8_t state; + uint8_t c_n; +}; + +struct cc_gpssats { + int nsat; + struct cc_gpssat sat[12]; +}; + struct cc_gpsdata { int num; int size; struct cc_gpselt *data; double time_offset; + int numsats; + int sizesats; + struct cc_gpssats *sats; }; /* -- cgit v1.2.3 From 74f0fb4dd189abc1d5027c64fa5a648a6003285a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 20 Sep 2009 13:33:59 -0700 Subject: make bit-banging reset script actually reset --- ao-tools/tests/reset | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/tests/reset b/ao-tools/tests/reset index a32c8bec..65b72803 100644 --- a/ao-tools/tests/reset +++ b/ao-tools/tests/reset @@ -1,5 +1,7 @@ # reset C D R -C D R -C D R +C D . +C D . +C D . +C D . C D R -- cgit v1.2.3 From ac4b8a73848f434999a532eab4665253c267c597 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 6 Oct 2009 20:05:36 -0700 Subject: ao-postflight: dump out GPS signal data Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 6418521e..cc9f64b4 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -313,14 +313,30 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FI } } if (gps_file) { + int j = 0; fprintf(gps_file, "%9s %12s %12s %12s\n", "time", "lat", "lon", "alt"); for (i = 0; i < f->gps.num; i++) { - fprintf(gps_file, "%12.7f %12.7f %12.7f %12.7f\n", + int nsat = 0; + int k; + while (j < f->gps.numsats - 1) { + if (f->gps.sats[j].sat[0].time <= f->gps.data[i].time && + f->gps.data[i].time < f->gps.sats[j+1].sat[0].time) + break; + j++; + } + fprintf(gps_file, "%12.7f %12.7f %12.7f %12.7f", (f->gps.data[i].time - boost_start) / 100.0, f->gps.data[i].lat, f->gps.data[i].lon, f->gps.data[i].alt); + nsat = 0; + for (k = 0; k < f->gps.sats[j].nsat; k++) { + fprintf (gps_file, " %12.7f", (double) f->gps.sats[j].sat[k].c_n); + if (f->gps.sats[j].sat[k].state == 0xbf) + nsat++; + } + fprintf(gps_file, " %d\n", nsat); } } if (cooked && plot_name) { -- cgit v1.2.3 From a3771bfc5ce740f9d89193e9f8b1d7987aa57264 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 6 Oct 2009 20:06:00 -0700 Subject: ao-view: fix snd_pcm_open return checking I don't know how this code was supposed to work before... Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview_flite.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_flite.c b/ao-tools/ao-view/aoview_flite.c index e1b75898..bc702b0f 100644 --- a/ao-tools/ao-view/aoview_flite.c +++ b/ao-tools/ao-view/aoview_flite.c @@ -42,12 +42,10 @@ aoview_flite_task(gpointer data) err = snd_pcm_open(&alsa_handle, "default", SND_PCM_STREAM_PLAYBACK, 0); - if (err >= 0) - { - if (err < 0) { - snd_pcm_close(alsa_handle); - alsa_handle = 0; - } + if (err < 0) { + fprintf(stderr, "alsa open failed %s\n", + strerror(-err)); + alsa_handle = NULL; } rate = 0; channels = 0; -- cgit v1.2.3 From e29961fdb2a48874c895829880eadbf13e094c0c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 10 Oct 2009 11:43:31 -0700 Subject: Add channel menu to ao-view. Sets radio channel when TD is connected, saves selected channel in gconf database. Signed-off-by: Keith Packard --- ao-tools/ao-view/Makefile.am | 1 + ao-tools/ao-view/aoview.glade | 101 ++++++++++++++++++++++++++++++++++++++ ao-tools/ao-view/aoview.h | 11 +++++ ao-tools/ao-view/aoview_channel.c | 90 +++++++++++++++++++++++++++++++++ ao-tools/ao-view/aoview_main.c | 2 + ao-tools/ao-view/aoview_monitor.c | 12 +++++ 6 files changed, 217 insertions(+) create mode 100644 ao-tools/ao-view/aoview_channel.c (limited to 'ao-tools') diff --git a/ao-tools/ao-view/Makefile.am b/ao-tools/ao-view/Makefile.am index 7b274a40..7a288417 100644 --- a/ao-tools/ao-view/Makefile.am +++ b/ao-tools/ao-view/Makefile.am @@ -25,6 +25,7 @@ ao_view_SOURCES = \ aoview_replay.c \ aoview_label.c \ aoview_flite.c \ + aoview_channel.c \ aoview.h BUILT_SOURCES = aoview_glade.h diff --git a/ao-tools/ao-view/aoview.glade b/ao-tools/ao-view/aoview.glade index 9a746110..c302ad0d 100644 --- a/ao-tools/ao-view/aoview.glade +++ b/ao-tools/ao-view/aoview.glade @@ -257,6 +257,107 @@ + + + True + _Channel + True + + + True + + + True + Channel 0 (434.550MHz) + True + True + + + + + True + Channel 1 (434.650MHz) + True + True + channel_0 + + + + + True + Channel 2 (434.750MHz) + True + True + channel_0 + + + + + True + Channel 3 (434.850MHz) + True + True + channel_0 + + + + + True + Channel 4 (434.950MHz) + True + True + channel_0 + + + + + True + Channel 5 (435.050MHz) + True + True + channel_0 + + + + + True + Channel 6 (435.150MHz) + True + True + channel_0 + + + + + True + Channel 7 (435.250MHz) + True + True + channel_0 + + + + + True + Channel 8 (435.350MHz) + True + True + channel_0 + + + + + True + Channel 9 (435.450MHz) + True + True + channel_0 + + + + + + True diff --git a/ao-tools/ao-view/aoview.h b/ao-tools/ao-view/aoview.h index 6a4753ac..c582159c 100644 --- a/ao-tools/ao-view/aoview.h +++ b/ao-tools/ao-view/aoview.h @@ -168,6 +168,9 @@ aoview_monitor_connect(char *tty); gboolean aoview_monitor_parse(const char *line); +void +aoview_monitor_set_channel(int channel); + void aoview_monitor_reset(void); @@ -320,4 +323,12 @@ aoview_flite_stop(void); extern char *aoview_tty; +/* aoview_channel.c */ + +int +aoview_channel_current(void); + +void +aoview_channel_init(GladeXML *xml); + #endif /* _AOVIEW_H_ */ diff --git a/ao-tools/ao-view/aoview_channel.c b/ao-tools/ao-view/aoview_channel.c new file mode 100644 index 00000000..959173ca --- /dev/null +++ b/ao-tools/ao-view/aoview_channel.c @@ -0,0 +1,90 @@ +/* + * 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; 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 "aoview.h" + + +#define NUM_CHANNEL 10 + +static GtkRadioMenuItem *channel_item[NUM_CHANNEL]; + +int +aoview_channel_current(void) +{ + int c; + + for (c = 0; c < NUM_CHANNEL; c++) + if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(channel_item[c]))) + return c; + return -1; +} + +static void +aoview_channel_notify(int channel) +{ + if (0 <= channel && channel < NUM_CHANNEL) + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(channel_item[channel]), TRUE); +} + +#define ALTOS_CHANNEL_PATH "/apps/aoview/channel" + +static void +aoview_channel_change(GtkWidget *widget, gpointer data) +{ + gboolean enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); + int c = (int) data; + GConfClient *gconf_client; + GError *error; + + if (enabled) { + aoview_monitor_set_channel(c); + gconf_client = gconf_client_get_default(); + gconf_client_set_int(gconf_client, ALTOS_CHANNEL_PATH, c, &error); + } +} + +void +aoview_channel_init(GladeXML *xml) +{ + int c; + GConfClient *gconf_client; + + for (c = 0; c < NUM_CHANNEL; c++) { + char name[32]; + + sprintf(name, "channel_%d", c); + channel_item[c] = GTK_RADIO_MENU_ITEM(glade_xml_get_widget(xml, name)); + assert(channel_item[c]); + g_signal_connect(G_OBJECT(channel_item[c]), "toggled", + G_CALLBACK(aoview_channel_change), + (gpointer) c); + } + gconf_client = gconf_client_get_default(); + c = 0; + if (gconf_client) + { + GError *error; + + error = NULL; + c = gconf_client_get_int(gconf_client, + ALTOS_CHANNEL_PATH, + &error); + if (error) + c = 0; + } + aoview_channel_notify(c); +} diff --git a/ao-tools/ao-view/aoview_main.c b/ao-tools/ao-view/aoview_main.c index 64c1c027..714bee9a 100644 --- a/ao-tools/ao-view/aoview_main.c +++ b/ao-tools/ao-view/aoview_main.c @@ -86,6 +86,8 @@ int main(int argc, char **argv) aoview_voice_init(xml); + aoview_channel_init(xml); + aoview_dev_dialog_init(xml); aoview_state_init(xml); diff --git a/ao-tools/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c index 8564014b..48e20320 100644 --- a/ao-tools/ao-view/aoview_monitor.c +++ b/ao-tools/ao-view/aoview_monitor.c @@ -82,6 +82,7 @@ aoview_monitor_parse(const char *input_line) char line_buf[8192], *line; struct aodata data; int tracking_pos; + int channel; /* avoid smashing our input parameter */ strncpy (line_buf, input_line, sizeof (line_buf)-1); @@ -214,15 +215,26 @@ aoview_monitor_callback(gpointer user_data, } } +void +aoview_monitor_set_channel(int channel) +{ + if (monitor_serial) + aoview_serial_printf(monitor_serial, "c r %d\n", channel); +} + gboolean aoview_monitor_connect(char *tty) { + int channel; aoview_monitor_disconnect(); monitor_serial = aoview_serial_open(tty); if (!monitor_serial) return FALSE; aoview_table_clear(); aoview_state_reset(); + channel = aoview_channel_current(); + if (channel >= 0) + aoview_monitor_set_channel(channel); aoview_serial_set_callback(monitor_serial, aoview_monitor_callback); return TRUE; -- cgit v1.2.3 From 5f26ad663b3f60dddc9d967206e365f45dc4acd1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 10 Oct 2009 13:58:16 -0700 Subject: ao-dumplog: switch to 'e' command, display progress Using the 'e' command allows additional checking of the data, including end-to-end checksums and detection of missing data. Progress is displayed by showing the recorded flight state along with a '.' for each eeprom block read. Signed-off-by: Keith Packard --- ao-tools/ao-dumplog/ao-dumplog.c | 95 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 9 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c index b930f0e5..158a445b 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.c +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -37,6 +37,30 @@ static void usage(char *program) exit(1); } +static uint8_t +log_checksum(int d[8]) +{ + uint8_t sum = 0x5a; + int i; + + for (i = 0; i < 8; i++) + sum += (uint8_t) d[i]; + return -sum; +} + +static const char *state_names[] = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid" +}; + int main (int argc, char **argv) { @@ -50,6 +74,12 @@ main (int argc, char **argv) int serial_number; char cmd; int tick, a, b; + int block; + int addr; + int received_addr; + int data[8]; + int done; + int column; while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { switch (c) { @@ -74,12 +104,10 @@ main (int argc, char **argv) if (!cc) exit(1); /* send a 'version' command followed by a 'log' command */ - cc_usb_printf(cc, "v\nl\n"); + cc_usb_printf(cc, "v\n"); out = NULL; for (;;) { cc_usb_getline(cc, line, sizeof (line)); - if (!strcmp (line, "end")) - break; if (sscanf(line, "serial-number %u", &serial_number) == 1) { filename = cc_make_filename(serial_number, "eeprom"); out = fopen (filename, "w"); @@ -87,16 +115,65 @@ main (int argc, char **argv) perror(filename); } fprintf (out, "%s\n", line); - } else if (sscanf(line, "%c %x %x %x", &cmd, &tick, &a, &b) == 4) { - if (out) { - fprintf(out, "%s\n", line); - if (cmd == 'S' && a == 8) { - fclose(out); - out = NULL; + } + if (!strncmp(line, "software-version", 16)) + break; + } + if (!out) { + fprintf(stderr, "no serial number found\n"); + cc_usb_close(cc); + exit(1); + } + printf ("Serial number: %d\n", serial_number); + printf ("File name: %s\n", filename); + done = 0; + column = 0; + for (block = 0; !done && block < 511; block++) { + cc_usb_printf(cc, "e %x\n", block); + if (column == 64) { + putchar('\n'); + column = 0; + } + putchar('.'); fflush(stdout); column++; + for (addr = 0; addr < 0x100;) { + cc_usb_getline(cc, line, sizeof (line)); + if (sscanf(line, "00%x %x %x %x %x %x %x %x %x", + &received_addr, + &data[0], &data[1], &data[2], &data[3], + &data[4], &data[5], &data[6], &data[7]) == 9) + { + if (received_addr != addr) + fprintf(stderr, "data out of sync at 0x%x\n", + block * 256 + received_addr); + + if (log_checksum(data) != 0) + fprintf (stderr, "invalid checksum at 0x%x\n", + block * 256 + received_addr); + + cmd = data[0]; + tick = data[2] + (data[3] << 8); + a = data[4] + (data[5] << 8); + b = data[6] + (data[7] << 8); + if (cmd == 'S' && a <= 8) { + if (column) putchar('\n'); + printf("%s\n", state_names[a]); + column = 0; + } + if (out) { + fprintf(out, "%c %4x %4x %4x\n", + cmd, tick, a, b); + if (cmd == 'S' && a == 8) { + fclose(out); + out = NULL; + done = 1; + } } + addr += 8; } } } + if (column) + putchar('\n'); if (out) fclose (out); cc_usb_close(cc); -- cgit v1.2.3 From 690fc263516d8beb6b24e86fbcd6588f42ce4e5c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 21 Oct 2009 17:18:49 +0900 Subject: Add keyhole-markup generation for ao-postflight. This lets you see the flight path in googleearth. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 76 ++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index cc9f64b4..60d8c036 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -161,8 +161,33 @@ merge_data(struct cc_perioddata *first, struct cc_perioddata *last, double split return pd; } +static const char kml_header[] = + "\n" + "\n" + " \n" + " gps\n" + " \n" + " \n" + " \n" + " 1\n" + " absolute\n" + " \n"; + +static const char kml_footer[] = + "\n" + " \n" + " \n" + "\n" + "\n"; + static void -analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FILE *raw_file, char *plot_name, FILE *gps_file) +analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, + FILE *raw_file, char *plot_name, FILE *gps_file, FILE *kml_file) { double height; double accel; @@ -339,6 +364,37 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FI fprintf(gps_file, " %d\n", nsat); } } + if (kml_file) { + int j = 0; + + fprintf(kml_file, "%s", kml_header); + for (i = 0; i < f->gps.num; i++) { + int nsat = 0; + int k; + while (j < f->gps.numsats - 1) { + if (f->gps.sats[j].sat[0].time <= f->gps.data[i].time && + f->gps.data[i].time < f->gps.sats[j+1].sat[0].time) + break; + j++; + } + nsat = 0; + for (k = 0; k < f->gps.sats[j].nsat; k++) + if (f->gps.sats[j].sat[k].state == 0xbf) + nsat++; + + fprintf(kml_file, "%12.7f, %12.7f, %12.7f ", + f->gps.data[i].lon, + f->gps.data[i].lat, + f->gps.data[i].alt, + (f->gps.data[i].time - boost_start) / 100.0, + nsat); + if (i < f->gps.num - 1) + fprintf(kml_file, ",\n"); + else + fprintf(kml_file, "\n"); + } + fprintf(kml_file, "%s", kml_footer); + } if (cooked && plot_name) { struct cc_perioddata *speed; plsdev("svgcairo"); @@ -378,6 +434,7 @@ static const struct option options[] = { { .name = "plot", .has_arg = 1, .val = 'p' }, { .name = "raw", .has_arg = 1, .val = 'r' }, { .name = "gps", .has_arg = 1, .val = 'g' }, + { .name = "kml", .has_arg = 1, .val = 'k' }, { 0, 0, 0, 0}, }; @@ -389,6 +446,7 @@ static void usage(char *program) "\t[--raw= -r -p ]\n" "\t[--gps= -g ]\n" + "\t[--kml= -k ]\n" "\t{flight-log} ...\n", program); exit(1); } @@ -401,6 +459,7 @@ main (int argc, char **argv) FILE *detail_file = NULL; FILE *raw_file = NULL; FILE *gps_file = NULL; + FILE *kml_file = NULL; int i; int ret = 0; struct cc_flightraw *raw; @@ -412,8 +471,9 @@ main (int argc, char **argv) char *raw_name = NULL; char *plot_name = NULL; char *gps_name = NULL; + char *kml_name = NULL; - while ((c = getopt_long(argc, argv, "s:d:p:r:g:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "s:d:p:r:g:k:", options, NULL)) != -1) { switch (c) { case 's': summary_name = optarg; @@ -430,6 +490,9 @@ main (int argc, char **argv) case 'g': gps_name = optarg; break; + case 'k': + kml_name = optarg; + break; default: usage(argv[0]); break; @@ -468,6 +531,13 @@ main (int argc, char **argv) exit(1); } } + if (kml_name) { + kml_file = fopen(kml_name, "w"); + if (!kml_file) { + perror(kml_name); + exit(1); + } + } for (i = optind; i < argc; i++) { file = fopen(argv[i], "r"); if (!file) { @@ -488,7 +558,7 @@ main (int argc, char **argv) } if (!raw->serial) raw->serial = serial; - analyse_flight(raw, summary_file, detail_file, raw_file, plot_name, gps_file); + analyse_flight(raw, summary_file, detail_file, raw_file, plot_name, gps_file, kml_file); cc_flightraw_free(raw); } return ret; -- cgit v1.2.3 From 1de322b960005c9a16051afa1881fadb00f4bcd6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 3 Nov 2009 00:40:38 -0800 Subject: Pass accel calibration over telemetry stream. Telemetry data format change. This allows the ground station to convert the accelerometer sensor values into acceleration and speed data. This requires a new telemetry data structure, and so TeleMetrum and TeleDongle units must be updated synchronously. ao-view will parse either telemetry stream, and the serial format from TeleDongle now has a version number to allow for future changes. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview.h | 2 ++ ao-tools/ao-view/aoview_monitor.c | 23 ++++++++++++++++++++--- ao-tools/ao-view/aoview_state.c | 6 ++++-- src/ao.h | 3 +++ src/ao_monitor.c | 18 +++++++++++------- src/ao_telemetry.c | 2 ++ 6 files changed, 42 insertions(+), 12 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview.h b/ao-tools/ao-view/aoview.h index c582159c..b6d5bcdf 100644 --- a/ao-tools/ao-view/aoview.h +++ b/ao-tools/ao-view/aoview.h @@ -104,6 +104,8 @@ struct aodata { int flight_vel; int flight_pres; int ground_pres; + int accel_plus_g; + int accel_minus_g; struct aogps gps; struct aogps_tracking gps_tracking; }; diff --git a/ao-tools/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c index 48e20320..6d57f556 100644 --- a/ao-tools/ao-view/aoview_monitor.c +++ b/ao-tools/ao-view/aoview_monitor.c @@ -77,7 +77,9 @@ gboolean aoview_monitor_parse(const char *input_line) { char *saveptr; - char *words[PARSE_MAX_WORDS]; + char *raw_words[PARSE_MAX_WORDS]; + char **words; + int version = 0; int nword; char line_buf[8192], *line; struct aodata data; @@ -89,13 +91,19 @@ aoview_monitor_parse(const char *input_line) line_buf[sizeof(line_buf) - 1] = '\0'; line = line_buf; for (nword = 0; nword < PARSE_MAX_WORDS; nword++) { - words[nword] = strtok_r(line, " \t\n", &saveptr); + raw_words[nword] = strtok_r(line, " \t\n", &saveptr); line = NULL; - if (words[nword] == NULL) + if (raw_words[nword] == NULL) break; } if (nword < 36) return FALSE; + words = raw_words; + if (strcmp(words[0], "VERSION") == 0) { + aoview_parse_int(&version, words[1]); + words += 2; + nword -= 2; + } if (strcmp(words[0], "CALL") != 0) return FALSE; aoview_parse_string(data.callsign, sizeof (data.callsign), words[1]); @@ -115,6 +123,15 @@ aoview_monitor_parse(const char *input_line) aoview_parse_int(&data.flight_vel, words[28]); aoview_parse_int(&data.flight_pres, words[30]); aoview_parse_int(&data.ground_pres, words[32]); + if (version >= 1) { + aoview_parse_int(&data.accel_plus_g, words[34]); + aoview_parse_int(&data.accel_minus_g, words[36]); + words += 4; + nword -= 4; + } else { + data.accel_plus_g = data.ground_accel; + data.accel_minus_g = data.ground_accel + 530; + } aoview_parse_int(&data.gps.nsat, words[34]); if (strcmp (words[36], "unlocked") == 0) { data.gps.gps_connected = 1; diff --git a/ao-tools/ao-view/aoview_state.c b/ao-tools/ao-view/aoview_state.c index f75066dd..f8f01685 100644 --- a/ao-tools/ao-view/aoview_state.c +++ b/ao-tools/ao-view/aoview_state.c @@ -105,6 +105,7 @@ aoview_state_derive(struct aodata *data, struct aostate *state) double new_height; double height_change; double time_change; + double accel_counts_per_mss; int tick_count; state->report_time = aoview_time(); @@ -123,8 +124,9 @@ aoview_state_derive(struct aodata *data, struct aostate *state) state->height = new_height; if (time_change) state->baro_speed = (state->baro_speed * 3 + (height_change / time_change)) / 4.0; - state->acceleration = (data->ground_accel - data->flight_accel) / 27.0; - state->speed = data->flight_vel / 2700.0; + accel_counts_per_mss = ((data->accel_minus_g - data->accel_plus_g) / 2.0) / 9.80665; + state->acceleration = (data->ground_accel - data->flight_accel) / accel_counts_per_mss; + state->speed = data->flight_vel / (accel_counts_per_mss * 100.0); state->temperature = ((data->temp / 32767.0 * 3.3) - 0.5) / 0.01; state->drogue_sense = data->drogue / 32767.0 * 15.0; state->main_sense = data->main / 32767.0 * 15.0; diff --git a/src/ao.h b/src/ao.h index 22e8785f..bc9afcc3 100644 --- a/src/ao.h +++ b/src/ao.h @@ -784,6 +784,7 @@ ao_gps_report_init(void); */ #define AO_MAX_CALLSIGN 8 +#define AO_TELEMETRY_VERSION 1 struct ao_telemetry { uint8_t addr; @@ -793,6 +794,8 @@ struct ao_telemetry { int32_t flight_vel; int16_t flight_pres; int16_t ground_pres; + int16_t accel_plus_g; + int16_t accel_minus_g; struct ao_adc adc; struct ao_gps_data gps; char callsign[AO_MAX_CALLSIGN]; diff --git a/src/ao_monitor.c b/src/ao_monitor.c index d0c1da34..cd0d693e 100644 --- a/src/ao_monitor.c +++ b/src/ao_monitor.c @@ -37,12 +37,14 @@ ao_monitor(void) if (state > ao_flight_invalid) state = ao_flight_invalid; if (recv.status & PKT_APPEND_STATUS_1_CRC_OK) { - printf ("CALL %s SERIAL %3d RSSI %4d STATUS %02x STATE %7s ", - callsign, - recv.telemetry.addr, - (int) recv.rssi - 74, recv.status, - ao_state_names[state]); - printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d fa: %5d ga: %d fv: %7ld fp: %5d gp: %5d ", + printf("VERSION %d CALL %s SERIAL %3d RSSI %4d STATUS %02x STATE %7s ", + AO_TELEMETRY_VERSION, + callsign, + recv.telemetry.addr, + (int) recv.rssi - 74, recv.status, + ao_state_names[state]); + printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d " + "fa: %5d ga: %d fv: %7ld fp: %5d gp: %5d a+: %5d a-: %5d ", recv.telemetry.adc.tick, recv.telemetry.adc.accel, recv.telemetry.adc.pres, @@ -54,7 +56,9 @@ ao_monitor(void) recv.telemetry.ground_accel, recv.telemetry.flight_vel, recv.telemetry.flight_pres, - recv.telemetry.ground_pres); + recv.telemetry.ground_pres, + recv.telemetry.accel_plus_g, + recv.telemetry.accel_minus_g); ao_gps_print(&recv.telemetry.gps); putchar(' '); ao_gps_tracking_print(&recv.telemetry.gps_tracking); diff --git a/src/ao_telemetry.c b/src/ao_telemetry.c index d52e589c..9c923984 100644 --- a/src/ao_telemetry.c +++ b/src/ao_telemetry.c @@ -32,6 +32,8 @@ ao_telemetry(void) ao_config_get(); memcpy(telemetry.callsign, ao_config.callsign, AO_MAX_CALLSIGN); telemetry.addr = ao_serial_number; + telemetry.accel_plus_g = ao_config.accel_plus_g; + telemetry.accel_minus_g = ao_config.accel_minus_g; ao_rdf_time = ao_time(); for (;;) { while (ao_telemetry_interval == 0) -- cgit v1.2.3 From 27ebaf8e13aed06bb1ea6e770f767495a02be6c5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 3 Nov 2009 01:27:37 -0800 Subject: Add ability to dump eeprom data over radio link. This adds a '-R' option to ao-dumplog to redirect the connection through a USB attached TeleDongle over the radio link to a remote TeleMetrum device. Signed-off-by: Keith Packard --- ao-tools/ao-dumplog/ao-dumplog.c | 19 +++++++++++++++---- ao-tools/lib/cc-usb.c | 26 ++++++++++++++++++++++++++ ao-tools/lib/cc-usb.h | 6 ++++++ 3 files changed, 47 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c index 158a445b..4bfb7e51 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.c +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -28,12 +28,13 @@ static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, + { .name = "remote", .has_arg = 1, .val = 'R' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty ] [--device \n", program); + fprintf(stderr, "usage: %s [--tty ] [--device ] [-R]\n", program); exit(1); } @@ -80,8 +81,9 @@ main (int argc, char **argv) int data[8]; int done; int column; + int remote = 0; - while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:R", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; @@ -89,13 +91,20 @@ main (int argc, char **argv) case 'D': device = optarg; break; + case 'R': + remote = 1; + break; default: usage(argv[0]); break; } } - if (!tty) - tty = cc_usbdevs_find_by_arg(device, "TeleMetrum"); + if (!tty) { + if (remote) + tty = cc_usbdevs_find_by_arg(device, "TeleDongle"); + else + tty = cc_usbdevs_find_by_arg(device, "TeleMetrum"); + } if (!tty) tty = getenv("ALTOS_TTY"); if (!tty) @@ -103,6 +112,8 @@ main (int argc, char **argv) cc = cc_usb_open(tty); if (!cc) exit(1); + if (remote) + cc_usb_open_remote(cc); /* send a 'version' command followed by a 'log' command */ cc_usb_printf(cc, "v\n"); out = NULL; diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index 80d9c04f..9b3b831f 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -53,6 +53,8 @@ struct cc_usb { struct cc_hex_read hex_buf[CC_NUM_HEX_READ]; int hex_count; + + int remote; }; #define NOT_HEX 0xff @@ -372,6 +374,28 @@ cc_usb_reset(struct cc_usb *cc) return 1; } +void +cc_usb_open_remote(struct cc_usb *cc) +{ + if (!cc->remote) { + cc_usb_printf(cc, "p\nE 0\n"); + do { + cc->in_count = cc->in_pos = 0; + _cc_usb_sync(cc, 100); + } while (cc->in_count > 0); + cc->remote = 1; + } +} + +void +cc_usb_close_remote(struct cc_usb *cc) +{ + if (cc->remote) { + cc_usb_printf(cc, "~"); + cc->remote = 0; + } +} + static struct termios save_termios; struct cc_usb * @@ -406,6 +430,8 @@ cc_usb_open(char *tty) void cc_usb_close(struct cc_usb *cc) { + cc_usb_close_remote(cc); + cc_usb_sync(cc); tcsetattr(cc->fd, TCSAFLUSH, &save_termios); close (cc->fd); free (cc); diff --git a/ao-tools/lib/cc-usb.h b/ao-tools/lib/cc-usb.h index 7b6be350..627f1b5d 100644 --- a/ao-tools/lib/cc-usb.h +++ b/ao-tools/lib/cc-usb.h @@ -62,4 +62,10 @@ cc_usb_getline(struct cc_usb *cc, char *line, int max); void cc_usb_printf(struct cc_usb *cc, char *format, ...); +void +cc_usb_open_remote(struct cc_usb *cc); + +void +cc_usb_close_remote(struct cc_usb *cc); + #endif /* _CC_USB_H_ */ -- cgit v1.2.3 From 843ee489aac34ad6d81f55f1c85fb9eecc42d86b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 4 Nov 2009 21:59:12 -0800 Subject: Flush pending input when switching to remote packet mode Any pending input would just confuse the application, so pull it off the link and dump it. Signed-off-by: Keith Packard --- ao-tools/lib/cc-usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index 9b3b831f..53a50741 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -378,7 +378,7 @@ void cc_usb_open_remote(struct cc_usb *cc) { if (!cc->remote) { - cc_usb_printf(cc, "p\nE 0\n"); + cc_usb_printf(cc, "\np\nE 0\n"); do { cc->in_count = cc->in_pos = 0; _cc_usb_sync(cc, 100); @@ -419,7 +419,7 @@ cc_usb_open(char *tty) save_termios = termios; cfmakeraw(&termios); tcsetattr(cc->fd, TCSAFLUSH, &termios); - cc_usb_printf(cc, "E 0\nm 0\n"); + cc_usb_printf(cc, "\nE 0\nm 0\n"); do { cc->in_count = cc->in_pos = 0; _cc_usb_sync(cc, 100); -- cgit v1.2.3 From 5a79a04ddb0b3ee64de34e366f71a0f6db509c01 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 4 Nov 2009 21:59:51 -0800 Subject: Stop recording in ao-dumplog after receiving an invalid block If no samples in a block are valid, assume the flight log is over. Signed-off-by: Keith Packard --- ao-tools/ao-dumplog/ao-dumplog.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c index 4bfb7e51..b3a0a25a 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.c +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -82,6 +82,8 @@ main (int argc, char **argv) int done; int column; int remote = 0; + int any_valid; + int invalid; while ((c = getopt_long(argc, argv, "T:D:R", options, NULL)) != -1) { switch (c) { @@ -146,6 +148,7 @@ main (int argc, char **argv) column = 0; } putchar('.'); fflush(stdout); column++; + any_valid = 0; for (addr = 0; addr < 0x100;) { cc_usb_getline(cc, line, sizeof (line)); if (sscanf(line, "00%x %x %x %x %x %x %x %x %x", @@ -160,6 +163,8 @@ main (int argc, char **argv) if (log_checksum(data) != 0) fprintf (stderr, "invalid checksum at 0x%x\n", block * 256 + received_addr); + else + any_valid = 1; cmd = data[0]; tick = data[2] + (data[3] << 8); @@ -182,6 +187,11 @@ main (int argc, char **argv) addr += 8; } } + if (!any_valid) { + fclose(out); + out = NULL; + done = 1; + } } if (column) putchar('\n'); -- cgit v1.2.3 From 03092d1a72a9651711e22c58dca6d6aba5705c5e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 14 Nov 2009 16:35:12 -0800 Subject: ao-postflight: fix sloppy gps sat data realloc code (was crashing). Realloc'ing the wrong data, and failing to set the realloc'ed size was causing ao-postflight to crash while reading long logs. Signed-off-by: Keith Packard --- ao-tools/lib/cc-logfile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/lib/cc-logfile.c b/ao-tools/lib/cc-logfile.c index 2136eec4..3d346bcc 100644 --- a/ao-tools/lib/cc-logfile.c +++ b/ao-tools/lib/cc-logfile.c @@ -101,11 +101,12 @@ gpssat_add(struct cc_gpsdata *data, struct cc_gpssat *sat) if (data->sizesats == 0) newsats = malloc((newsizesats = 256) * sizeof (struct cc_gpssats)); else - newsats = realloc (data->data, (newsizesats = data->sizesats * 2) + newsats = realloc (data->sats, (newsizesats = data->sizesats * 2) * sizeof (struct cc_gpssats)); if (!newsats) return 0; data->sats = newsats; + data->sizesats = newsizesats; } i = data->numsats++; data->sats[i].nsat = 0; -- cgit v1.2.3 From 4cffc9c4b079e39c8196ddbaf91129cda6df7f8b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 14 Nov 2009 22:24:37 -0800 Subject: Share telemetry parsing code in cc library. ao-view had a private copy of the telemetry parsing code which included the ability to parse the newer version of that file. Those changes have been moved to the library version and the private copy removed. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview.h | 77 ++---------------- ao-tools/ao-view/aoview_monitor.c | 159 +------------------------------------- ao-tools/ao-view/aoview_state.c | 4 +- ao-tools/lib/cc-telem.c | 24 +++++- ao-tools/lib/cc.h | 2 + 5 files changed, 33 insertions(+), 233 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview.h b/ao-tools/ao-view/aoview.h index b6d5bcdf..b937df7c 100644 --- a/ao-tools/ao-view/aoview.h +++ b/ao-tools/ao-view/aoview.h @@ -43,79 +43,12 @@ #include #include -struct aogps_time { - int hour; - int minute; - int second; -}; - -struct aogps { - int nsat; - int gps_locked; - int gps_connected; - struct aogps_time gps_time; - double lat; /* degrees (+N -S) */ - double lon; /* degrees (+E -W) */ - int alt; /* m */ - - int gps_extended; /* has extra data */ - double ground_speed; /* m/s */ - int course; /* degrees */ - double climb_rate; /* m/s */ - double hdop; /* unitless? */ - int h_error; /* m */ - int v_error; /* m */ -}; - -#define SIRF_SAT_STATE_ACQUIRED (1 << 0) -#define SIRF_SAT_STATE_CARRIER_PHASE_VALID (1 << 1) -#define SIRF_SAT_BIT_SYNC_COMPLETE (1 << 2) -#define SIRF_SAT_SUBFRAME_SYNC_COMPLETE (1 << 3) -#define SIRF_SAT_CARRIER_PULLIN_COMPLETE (1 << 4) -#define SIRF_SAT_CODE_LOCKED (1 << 5) -#define SIRF_SAT_ACQUISITION_FAILED (1 << 6) -#define SIRF_SAT_EPHEMERIS_AVAILABLE (1 << 7) - -struct aogps_sat { - int svid; - int state; - int c_n0; -}; - -struct aogps_tracking { - int channels; - struct aogps_sat sats[12]; -}; - -struct aodata { - char callsign[16]; - int serial; - int rssi; - char state[16]; - int tick; - int accel; - int pres; - int temp; - int batt; - int drogue; - int main; - int flight_accel; - int ground_accel; - int flight_vel; - int flight_pres; - int ground_pres; - int accel_plus_g; - int accel_minus_g; - struct aogps gps; - struct aogps_tracking gps_tracking; -}; - struct aostate { - struct aodata data; + struct cc_telem data; /* derived data */ - struct aodata prev_data; + struct cc_telem prev_data; double report_time; @@ -135,8 +68,8 @@ struct aostate { double max_acceleration; double max_speed; - struct aogps gps; - struct aogps_tracking gps_tracking; + struct cc_gps gps; + struct cc_gps_tracking gps_tracking; int gps_valid; double pad_lat; @@ -201,7 +134,7 @@ void aoview_dev_dialog_init(GladeXML *xml); void -aoview_state_notify(struct aodata *data); +aoview_state_notify(struct cc_telem *data); void aoview_state_new(void); diff --git a/ao-tools/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c index 6d57f556..0f4afb0f 100644 --- a/ao-tools/ao-view/aoview_monitor.c +++ b/ao-tools/ao-view/aoview_monitor.c @@ -34,167 +34,14 @@ aoview_monitor_disconnect(void) aoview_log_new(); } -static void -aoview_parse_string(char *target, int len, char *source) -{ - strncpy(target, source, len-1); - target[len-1] = '\0'; -} - -static void -aoview_parse_int(int *target, char *source) -{ - *target = strtol(source, NULL, 0); -} - -static void -aoview_parse_hex(int *target, char *source) -{ - *target = strtol(source, NULL, 16); -} - -static void -aoview_parse_pos(double *target, char *source) -{ - int deg; - double min; - char dir; - double r; - - if (sscanf(source, "%d°%lf'%c", °, &min, &dir) != 3) { - *target = 0; - return; - } - r = deg + min / 60.0; - if (dir == 'S' || dir == 'W') - r = -r; - *target = r; -} - -#define PARSE_MAX_WORDS 256 - gboolean aoview_monitor_parse(const char *input_line) { - char *saveptr; - char *raw_words[PARSE_MAX_WORDS]; - char **words; - int version = 0; - int nword; - char line_buf[8192], *line; - struct aodata data; - int tracking_pos; - int channel; + struct cc_telem telem; - /* avoid smashing our input parameter */ - strncpy (line_buf, input_line, sizeof (line_buf)-1); - line_buf[sizeof(line_buf) - 1] = '\0'; - line = line_buf; - for (nword = 0; nword < PARSE_MAX_WORDS; nword++) { - raw_words[nword] = strtok_r(line, " \t\n", &saveptr); - line = NULL; - if (raw_words[nword] == NULL) - break; - } - if (nword < 36) - return FALSE; - words = raw_words; - if (strcmp(words[0], "VERSION") == 0) { - aoview_parse_int(&version, words[1]); - words += 2; - nword -= 2; - } - if (strcmp(words[0], "CALL") != 0) + if (!cc_telem_parse(input_line, &telem)) return FALSE; - aoview_parse_string(data.callsign, sizeof (data.callsign), words[1]); - aoview_parse_int(&data.serial, words[3]); - - aoview_parse_int(&data.rssi, words[5]); - aoview_parse_string(data.state, sizeof (data.state), words[9]); - aoview_parse_int(&data.tick, words[10]); - aoview_parse_int(&data.accel, words[12]); - aoview_parse_int(&data.pres, words[14]); - aoview_parse_int(&data.temp, words[16]); - aoview_parse_int(&data.batt, words[18]); - aoview_parse_int(&data.drogue, words[20]); - aoview_parse_int(&data.main, words[22]); - aoview_parse_int(&data.flight_accel, words[24]); - aoview_parse_int(&data.ground_accel, words[26]); - aoview_parse_int(&data.flight_vel, words[28]); - aoview_parse_int(&data.flight_pres, words[30]); - aoview_parse_int(&data.ground_pres, words[32]); - if (version >= 1) { - aoview_parse_int(&data.accel_plus_g, words[34]); - aoview_parse_int(&data.accel_minus_g, words[36]); - words += 4; - nword -= 4; - } else { - data.accel_plus_g = data.ground_accel; - data.accel_minus_g = data.ground_accel + 530; - } - aoview_parse_int(&data.gps.nsat, words[34]); - if (strcmp (words[36], "unlocked") == 0) { - data.gps.gps_connected = 1; - data.gps.gps_locked = 0; - data.gps.gps_time.hour = data.gps.gps_time.minute = data.gps.gps_time.second = 0; - data.gps.lat = data.gps.lon = 0; - data.gps.alt = 0; - tracking_pos = 37; - } else if (nword >= 40) { - data.gps.gps_locked = 1; - data.gps.gps_connected = 1; - sscanf(words[36], "%d:%d:%d", &data.gps.gps_time.hour, &data.gps.gps_time.minute, &data.gps.gps_time.second); - aoview_parse_pos(&data.gps.lat, words[37]); - aoview_parse_pos(&data.gps.lon, words[38]); - sscanf(words[39], "%dm", &data.gps.alt); - tracking_pos = 46; - } else { - data.gps.gps_connected = 0; - data.gps.gps_locked = 0; - data.gps.gps_time.hour = data.gps.gps_time.minute = data.gps.gps_time.second = 0; - data.gps.lat = data.gps.lon = 0; - data.gps.alt = 0; - tracking_pos = -1; - } - if (nword >= 46) { - data.gps.gps_extended = 1; - sscanf(words[40], "%lfm/s", &data.gps.ground_speed); - sscanf(words[41], "%d", &data.gps.course); - sscanf(words[42], "%lfm/s", &data.gps.climb_rate); - sscanf(words[43], "%lf", &data.gps.hdop); - sscanf(words[44], "%d", &data.gps.h_error); - sscanf(words[45], "%d", &data.gps.v_error); - } else { - data.gps.gps_extended = 0; - data.gps.ground_speed = 0; - data.gps.course = 0; - data.gps.climb_rate = 0; - data.gps.hdop = 0; - data.gps.h_error = 0; - data.gps.v_error = 0; - } - if (tracking_pos >= 0 && nword >= tracking_pos + 2 && strcmp(words[tracking_pos], "SAT") == 0) { - int c, n, pos; - aoview_parse_int(&n, words[tracking_pos + 1]); - pos = tracking_pos + 2; - if (nword >= pos + n * 3) { - data.gps_tracking.channels = n; - for (c = 0; c < n; c++) { - aoview_parse_int(&data.gps_tracking.sats[c].svid, - words[pos + 0]); - aoview_parse_hex(&data.gps_tracking.sats[c].state, - words[pos + 1]); - aoview_parse_int(&data.gps_tracking.sats[c].c_n0, - words[pos + 2]); - pos += 3; - } - } else { - data.gps_tracking.channels = 0; - } - } else { - data.gps_tracking.channels = 0; - } - aoview_state_notify(&data); + aoview_state_notify(&telem); return TRUE; } diff --git a/ao-tools/ao-view/aoview_state.c b/ao-tools/ao-view/aoview_state.c index f8f01685..a7545c51 100644 --- a/ao-tools/ao-view/aoview_state.c +++ b/ao-tools/ao-view/aoview_state.c @@ -99,7 +99,7 @@ aoview_time(void) * Fill out the derived data fields */ static void -aoview_state_derive(struct aodata *data, struct aostate *state) +aoview_state_derive(struct cc_telem *data, struct aostate *state) { int i; double new_height; @@ -274,7 +274,7 @@ aoview_state_reset(void) } void -aoview_state_notify(struct aodata *data) +aoview_state_notify(struct cc_telem *data) { struct aostate *state = &aostate; aoview_state_derive(data, state); diff --git a/ao-tools/lib/cc-telem.c b/ao-tools/lib/cc-telem.c index a6ac0313..f82ab961 100644 --- a/ao-tools/lib/cc-telem.c +++ b/ao-tools/lib/cc-telem.c @@ -62,7 +62,9 @@ int cc_telem_parse(const char *input_line, struct cc_telem *telem) { char *saveptr; - char *words[PARSE_MAX_WORDS]; + char *raw_words[PARSE_MAX_WORDS]; + char **words; + int version = 0; int nword; char line_buf[8192], *line; int tracking_pos; @@ -72,13 +74,20 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem) line_buf[sizeof(line_buf) - 1] = '\0'; line = line_buf; for (nword = 0; nword < PARSE_MAX_WORDS; nword++) { - words[nword] = strtok_r(line, " \t\n", &saveptr); + raw_words[nword] = strtok_r(line, " \t\n", &saveptr); line = NULL; - if (words[nword] == NULL) + if (raw_words[nword] == NULL) break; } if (nword < 36) return FALSE; + words = raw_words; + if (strcmp(words[0], "VERSION") == 0) { + cc_parse_int(&version, words[1]); + words += 2; + nword -= 2; + } + if (strcmp(words[0], "CALL") != 0) return FALSE; cc_parse_string(telem->callsign, sizeof (telem->callsign), words[1]); @@ -98,6 +107,15 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem) cc_parse_int(&telem->flight_vel, words[28]); cc_parse_int(&telem->flight_pres, words[30]); cc_parse_int(&telem->ground_pres, words[32]); + if (version >= 1) { + cc_parse_int(&telem->accel_plus_g, words[34]); + cc_parse_int(&telem->accel_minus_g, words[36]); + words += 4; + nword -= 4; + } else { + telem->accel_plus_g = telem->ground_accel; + telem->accel_minus_g = telem->ground_accel + 530; + } cc_parse_int(&telem->gps.nsat, words[34]); if (strcmp (words[36], "unlocked") == 0) { telem->gps.gps_connected = 1; diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index b5f1132f..fd461e5c 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -252,6 +252,8 @@ struct cc_telem { int flight_vel; int flight_pres; int ground_pres; + int accel_plus_g; + int accel_minus_g; struct cc_gps gps; struct cc_gps_tracking gps_tracking; }; -- cgit v1.2.3 From 9b06e294e2777f69bcf5e98789c3f5477097d53b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 15 Nov 2009 15:51:58 -0800 Subject: Enable telemetry receive in ao_view --- ao-tools/ao-view/aoview_monitor.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c index 0f4afb0f..3d235e44 100644 --- a/ao-tools/ao-view/aoview_monitor.c +++ b/ao-tools/ao-view/aoview_monitor.c @@ -99,6 +99,7 @@ aoview_monitor_connect(char *tty) channel = aoview_channel_current(); if (channel >= 0) aoview_monitor_set_channel(channel); + aoview_serial_printf(monitor_serial, "m 1\n"); aoview_serial_set_callback(monitor_serial, aoview_monitor_callback); return TRUE; -- cgit v1.2.3 From 6391c89bd5b89f5f46255b8365c658a873e5959a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 15 Nov 2009 15:53:01 -0800 Subject: Switch order of serial/flight in ao-postflight summary --- ao-tools/ao-postflight/ao-postflight.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 60d8c036..733eb38c 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -204,8 +204,10 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, struct cc_flightcooked *cooked; double apogee; - fprintf(summary_file, "Flight: %9d\nSerial: %9d\n", - f->flight, f->serial); + fprintf(summary_file, + "Serial: %9d\n" + "Flight: %9d\n", + f->serial, f->flight); boost_start = f->accel.data[0].time; boost_stop = f->accel.data[f->accel.num-1].time; for (i = 0; i < f->state.num; i++) { -- cgit v1.2.3 From 3ee279ba76c2a79d142c466f19ef758cf4c01d70 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 15 Nov 2009 15:59:01 -0800 Subject: Add flight number to telemetry stream. This makes it easier to tie the telemetry and eeprom files together as they're now both labeled with serial and flight numbers, which should be unique. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview_state.c | 1 + ao-tools/lib/cc-telem.c | 7 ++++++ ao-tools/lib/cc.h | 1 + src/ao.h | 11 +++++---- src/ao_log.c | 51 +++++++++++------------------------------ src/ao_monitor.c | 3 ++- src/ao_telemetry.c | 3 +++ 7 files changed, 34 insertions(+), 43 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_state.c b/ao-tools/ao-view/aoview_state.c index a7545c51..2f613d44 100644 --- a/ao-tools/ao-view/aoview_state.c +++ b/ao-tools/ao-view/aoview_state.c @@ -288,6 +288,7 @@ aoview_state_notify(struct cc_telem *data) aoview_table_add_row(0, "Rocket state", "%s", state->data.state); aoview_table_add_row(0, "Callsign", "%s", state->data.callsign); aoview_table_add_row(0, "Rocket serial", "%d", state->data.serial); + aoview_table_add_row(0, "Rocket flight", "%d", state->data.flight); aoview_table_add_row(0, "RSSI", "%6ddBm", state->data.rssi); aoview_table_add_row(0, "Height", "%6dm", state->height); diff --git a/ao-tools/lib/cc-telem.c b/ao-tools/lib/cc-telem.c index f82ab961..0e1483f7 100644 --- a/ao-tools/lib/cc-telem.c +++ b/ao-tools/lib/cc-telem.c @@ -93,6 +93,13 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem) cc_parse_string(telem->callsign, sizeof (telem->callsign), words[1]); cc_parse_int(&telem->serial, words[3]); + if (version >= 2) { + cc_parse_int(&telem->flight, words[5]); + words += 2; + nword -= 2; + } else + telem->flight = 0; + cc_parse_int(&telem->rssi, words[5]); cc_parse_string(telem->state, sizeof (telem->state), words[9]); cc_parse_int(&telem->tick, words[10]); diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index fd461e5c..b8e3c061 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -238,6 +238,7 @@ struct cc_gps_tracking { struct cc_telem { char callsign[16]; int serial; + int flight; int rssi; char state[16]; int tick; diff --git a/src/ao.h b/src/ao.h index 2df81d2a..f266ac64 100644 --- a/src/ao.h +++ b/src/ao.h @@ -553,11 +553,11 @@ ao_log_data(struct ao_log_record *log); void ao_log_flush(void); -/* Log dumping API: - * ao_log_dump_first() - get first log record - * ao_log_dump_next() - get next log record +/* We record flight numbers in the first record of + * the log. Tasks may wait for this to be initialized + * by sleeping on this variable. */ -extern __xdata struct ao_log_record ao_log_dump; +extern __xdata uint16_t ao_flight_number; /* Retrieve first log record for the current flight */ uint8_t @@ -788,10 +788,11 @@ ao_gps_report_init(void); */ #define AO_MAX_CALLSIGN 8 -#define AO_TELEMETRY_VERSION 1 +#define AO_TELEMETRY_VERSION 2 struct ao_telemetry { uint8_t addr; + uint16_t flight; uint8_t flight_state; int16_t flight_accel; int16_t ground_accel; diff --git a/src/ao_log.c b/src/ao_log.c index 50778f55..44ce90e0 100644 --- a/src/ao_log.c +++ b/src/ao_log.c @@ -59,51 +59,30 @@ ao_log_flush(void) ao_ee_flush(); } -__xdata struct ao_log_record ao_log_dump; -static __xdata uint16_t ao_log_dump_flight; -static __xdata uint32_t ao_log_dump_pos; +__xdata struct ao_log_record log; +__xdata uint16_t ao_flight_number; static uint8_t ao_log_dump_check_data(void) { - if (ao_log_csum((uint8_t *) &ao_log_dump) != 0) + if (ao_log_csum((uint8_t *) &log) != 0) return 0; return 1; } -static uint8_t -ao_log_dump_scan(void) +static void +ao_log_scan(void) { - if (!ao_ee_read(0, (uint8_t *) &ao_log_dump, sizeof (struct ao_log_record))) + if (!ao_ee_read(0, (uint8_t *) &log, sizeof (struct ao_log_record))) ao_panic(AO_PANIC_LOG); - if (ao_log_dump_check_data() && ao_log_dump.type == AO_LOG_FLIGHT) { - ao_log_dump_flight = ao_log_dump.u.flight.flight; - return 1; + if (ao_log_dump_check_data() && log.type == AO_LOG_FLIGHT) { + ao_flight_number = log.u.flight.flight + 1; + if (ao_flight_number == 0) + ao_flight_number = 1; } else { - ao_log_dump_flight = 0; - return 0; + ao_flight_number = 1; } -} - -uint8_t -ao_log_dump_first(void) -{ - ao_log_dump_pos = 0; - if (!ao_log_dump_scan()) - return 0; - return 1; -} - -uint8_t -ao_log_dump_next(void) -{ - ao_log_dump_pos += sizeof (struct ao_log_record); - if (ao_log_dump_pos >= AO_EE_DEVICE_SIZE) - return 0; - if (!ao_ee_read(ao_log_dump_pos, (uint8_t *) &ao_log_dump, - sizeof (struct ao_log_record))) - return 0; - return ao_log_dump_check_data(); + ao_wakeup(&ao_flight_number); } __xdata uint8_t ao_log_adc_pos; @@ -115,9 +94,7 @@ typedef uint8_t check_log_size[1-(256 % sizeof(struct ao_log_record))] ; void ao_log(void) { - static __xdata struct ao_log_record log; - - ao_log_dump_scan(); + ao_log_scan(); while (!ao_log_running) ao_sleep(&ao_log_running); @@ -125,7 +102,7 @@ ao_log(void) log.type = AO_LOG_FLIGHT; log.tick = ao_flight_tick; log.u.flight.ground_accel = ao_ground_accel; - log.u.flight.flight = ao_log_dump_flight + 1; + log.u.flight.flight = ao_flight_number; ao_log_data(&log); /* Write the whole contents of the ring to the log diff --git a/src/ao_monitor.c b/src/ao_monitor.c index cd0d693e..628b6e67 100644 --- a/src/ao_monitor.c +++ b/src/ao_monitor.c @@ -37,10 +37,11 @@ ao_monitor(void) if (state > ao_flight_invalid) state = ao_flight_invalid; if (recv.status & PKT_APPEND_STATUS_1_CRC_OK) { - printf("VERSION %d CALL %s SERIAL %3d RSSI %4d STATUS %02x STATE %7s ", + printf("VERSION %d CALL %s SERIAL %3d FLIGHT %5u RSSI %4d STATUS %02x STATE %7s ", AO_TELEMETRY_VERSION, callsign, recv.telemetry.addr, + recv.telemetry.flight, (int) recv.rssi - 74, recv.status, ao_state_names[state]); printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d " diff --git a/src/ao_telemetry.c b/src/ao_telemetry.c index 9c923984..88ac142c 100644 --- a/src/ao_telemetry.c +++ b/src/ao_telemetry.c @@ -30,8 +30,11 @@ ao_telemetry(void) static __xdata struct ao_telemetry telemetry; ao_config_get(); + while (!ao_flight_number) + ao_sleep(&ao_flight_number); memcpy(telemetry.callsign, ao_config.callsign, AO_MAX_CALLSIGN); telemetry.addr = ao_serial_number; + telemetry.flight = ao_flight_number; telemetry.accel_plus_g = ao_config.accel_plus_g; telemetry.accel_minus_g = ao_config.accel_minus_g; ao_rdf_time = ao_time(); -- cgit v1.2.3 From 524665fc221b0d483453c67b7211e282cebc8980 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 15 Nov 2009 16:04:41 -0800 Subject: Add date to GPS data, captured from GPRMC packet. Pull the date out of the GPS stream and send it over the telemetry link and write it to the eeprom. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview_state.c | 4 +++ ao-tools/lib/cc-telem.c | 12 ++++++++ ao-tools/lib/cc.h | 3 ++ src/ao.h | 10 ++++++ src/ao_gps_print.c | 4 +++ src/ao_gps_report.c | 12 ++++++-- src/ao_gps_skytraq.c | 67 ++++++++++++++++++++++++++++++++++++----- src/ao_gps_test.c | 4 +++ src/ao_gps_test_skytraq.c | 4 +++ 9 files changed, 111 insertions(+), 9 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_state.c b/ao-tools/ao-view/aoview_state.c index 2f613d44..21cea99a 100644 --- a/ao-tools/ao-view/aoview_state.c +++ b/ao-tools/ao-view/aoview_state.c @@ -315,6 +315,10 @@ aoview_state_notify(struct cc_telem *data) aoview_state_add_deg(1, "Longitude", state->gps.lon, 'E', 'W'); aoview_table_add_row(1, "GPS altitude", "%d", state->gps.alt); aoview_table_add_row(1, "GPS height", "%d", state->gps_height); + aoview_table_add_row(1, "GPS date", "%04d-%02d-%02d", + state->gps.gps_time.year, + state->gps.gps_time.month, + state->gps.gps_time.day); aoview_table_add_row(1, "GPS time", "%02d:%02d:%02d", state->gps.gps_time.hour, state->gps.gps_time.minute, diff --git a/ao-tools/lib/cc-telem.c b/ao-tools/lib/cc-telem.c index 0e1483f7..9a2f6155 100644 --- a/ao-tools/lib/cc-telem.c +++ b/ao-tools/lib/cc-telem.c @@ -127,6 +127,7 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem) if (strcmp (words[36], "unlocked") == 0) { telem->gps.gps_connected = 1; telem->gps.gps_locked = 0; + telem->gps.gps_time.year = telem->gps.gps_time.month = telem->gps.gps_time.day = 0; telem->gps.gps_time.hour = telem->gps.gps_time.minute = telem->gps.gps_time.second = 0; telem->gps.lat = telem->gps.lon = 0; telem->gps.alt = 0; @@ -134,6 +135,16 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem) } else if (nword >= 40) { telem->gps.gps_locked = 1; telem->gps.gps_connected = 1; + if (version >= 2) { + sscanf(words[36], "%d-%d-%d", + &telem->gps.gps_time.year, + &telem->gps.gps_time.month, + &telem->gps.gps_time.day); + words += 1; + nword -= 1; + } else { + telem->gps.gps_time.year = telem->gps.gps_time.month = telem->gps.gps_time.day = 0; + } sscanf(words[36], "%d:%d:%d", &telem->gps.gps_time.hour, &telem->gps.gps_time.minute, &telem->gps.gps_time.second); cc_parse_pos(&telem->gps.lat, words[37]); cc_parse_pos(&telem->gps.lon, words[38]); @@ -142,6 +153,7 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem) } else { telem->gps.gps_connected = 0; telem->gps.gps_locked = 0; + telem->gps.gps_time.year = telem->gps.gps_time.month = telem->gps.gps_time.day = 0; telem->gps.gps_time.hour = telem->gps.gps_time.minute = telem->gps.gps_time.second = 0; telem->gps.lat = telem->gps.lon = 0; telem->gps.alt = 0; diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index b8e3c061..ebc0db7d 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -192,6 +192,9 @@ struct cc_flightcooked { struct cc_gps_time { + int year; + int month; + int day; int hour; int minute; int second; diff --git a/src/ao.h b/src/ao.h index f266ac64..c1a0f6e3 100644 --- a/src/ao.h +++ b/src/ao.h @@ -493,6 +493,7 @@ ao_ee_init(void); #define AO_LOG_GPS_LON 'W' #define AO_LOG_GPS_ALT 'H' #define AO_LOG_GPS_SAT 'V' +#define AO_LOG_GPS_DATE 'Y' #define AO_LOG_POS_NONE (~0UL) @@ -538,6 +539,11 @@ struct ao_log_record { uint8_t state; uint8_t c_n; } gps_sat; + struct { + uint8_t year; + uint8_t month; + uint8_t day; + } gps_date; struct { uint16_t d0; uint16_t d1; @@ -720,8 +726,12 @@ ao_serial_init(void); #define AO_GPS_VALID (1 << 4) #define AO_GPS_RUNNING (1 << 5) +#define AO_GPS_DATE_VALID (1 << 6) struct ao_gps_data { + uint8_t year; + uint8_t month; + uint8_t day; uint8_t hour; uint8_t minute; uint8_t second; diff --git a/src/ao_gps_print.c b/src/ao_gps_print.c index cc751337..95439ec7 100644 --- a/src/ao_gps_print.c +++ b/src/ao_gps_print.c @@ -53,6 +53,10 @@ ao_gps_print(__xdata struct ao_gps_data *gps_data) __reentrant ao_gps_split(gps_data->latitude, &lat); ao_gps_split(gps_data->longitude, &lon); + printf(" 20%02d-%02d-%02d", + gps_data->year, + gps_data->month, + gps_data->day); printf(" %2d:%02d:%02d", gps_data->hour, gps_data->minute, diff --git a/src/ao_gps_report.c b/src/ao_gps_report.c index 75c944f5..e3e27523 100644 --- a/src/ao_gps_report.c +++ b/src/ao_gps_report.c @@ -22,6 +22,7 @@ ao_gps_report(void) { static __xdata struct ao_log_record gps_log; static __xdata struct ao_gps_data gps_data; + uint8_t date_reported = 0; for (;;) { ao_sleep(&ao_gps_data); @@ -49,6 +50,14 @@ ao_gps_report(void) gps_log.u.gps_altitude.altitude = gps_data.altitude; gps_log.u.gps_altitude.unused = 0xffff; ao_log_data(&gps_log); + if (!date_reported && (gps_data.flags & AO_GPS_DATE_VALID)) { + date_reported = 1; + gps_log.type = AO_LOG_GPS_DATE; + gps_log.u.gps_date.year = gps_data.year; + gps_log.u.gps_date.month = gps_data.month; + gps_log.u.gps_date.day = gps_data.day; + ao_log_data(&gps_log); + } } } @@ -71,8 +80,7 @@ ao_gps_tracking_report(void) gps_log.tick = ao_time(); gps_log.type = AO_LOG_GPS_SAT; for (c = 0; c < n; c++) - if ((gps_log.u.gps_sat.svid = gps_tracking_data.sats[c].svid) && - (gps_log.u.gps_sat.state = gps_tracking_data.sats[c].state)) + if ((gps_log.u.gps_sat.svid = gps_tracking_data.sats[c].svid)) { gps_log.u.gps_sat.c_n = gps_tracking_data.sats[c].c_n_1; ao_log_data(&gps_log); diff --git a/src/ao_gps_skytraq.c b/src/ao_gps_skytraq.c index cd5f78b9..b2eef04b 100644 --- a/src/ao_gps_skytraq.c +++ b/src/ao_gps_skytraq.c @@ -19,9 +19,9 @@ #include "ao.h" #endif -#define AO_GPS_LEADER 3 +#define AO_GPS_LEADER 2 -static const char ao_gps_header[] = "GPG"; +static const char ao_gps_header[] = "GP"; __xdata uint8_t ao_gps_mutex; static __xdata char ao_gps_char; @@ -32,6 +32,7 @@ __xdata struct ao_gps_data ao_gps_data; __xdata struct ao_gps_tracking_data ao_gps_tracking_data; static __xdata struct ao_gps_data ao_gps_next; +static __xdata uint8_t ao_gps_date_flags; static __xdata struct ao_gps_tracking_data ao_gps_tracking_next; static const char ao_gps_config[] = { @@ -181,7 +182,7 @@ ao_gps_parse_flag(char no_c, char yes_c) __reentrant void ao_gps(void) __reentrant { - char c; + char a, c; uint8_t i; ao_serial_set_speed(AO_SERIAL_SPEED_9600); @@ -198,7 +199,7 @@ ao_gps(void) __reentrant ao_gps_cksum = 0; ao_gps_error = 0; - /* Skip anything other than GPG */ + /* Skip anything other than GP */ for (i = 0; i < AO_GPS_LEADER; i++) { ao_gps_lexchar(); if (ao_gps_char != ao_gps_header[i]) @@ -209,6 +210,8 @@ ao_gps(void) __reentrant /* pull the record identifier characters off the link */ ao_gps_lexchar(); + a = ao_gps_char; + ao_gps_lexchar(); c = ao_gps_char; ao_gps_lexchar(); i = ao_gps_char; @@ -216,7 +219,7 @@ ao_gps(void) __reentrant if (ao_gps_char != ',') continue; - if (c == (uint8_t) 'G' && i == (uint8_t) 'A') { + if (a == (uint8_t) 'G' && c == (uint8_t) 'G' && i == (uint8_t) 'A') { /* Now read the data into the gps data record * * $GPGGA,025149.000,4528.1723,N,12244.2480,W,1,05,2.0,103.5,M,-19.5,M,,0000*66 @@ -245,7 +248,7 @@ ao_gps(void) __reentrant * *66 checksum */ - ao_gps_next.flags = AO_GPS_RUNNING; + ao_gps_next.flags = AO_GPS_RUNNING | ao_gps_date_flags; ao_gps_next.hour = ao_gps_decimal(2); ao_gps_next.minute = ao_gps_decimal(2); ao_gps_next.second = ao_gps_decimal(2); @@ -290,7 +293,7 @@ ao_gps(void) __reentrant ao_mutex_put(&ao_gps_mutex); ao_wakeup(&ao_gps_data); } - } else if (c == (uint8_t) 'S' && i == (uint8_t) 'V') { + } else if (a == (uint8_t) 'G' && c == (uint8_t) 'S' && i == (uint8_t) 'V') { uint8_t done; /* Now read the data into the GPS tracking data record * @@ -345,6 +348,56 @@ ao_gps(void) __reentrant ao_mutex_put(&ao_gps_mutex); ao_wakeup(&ao_gps_tracking_data); } + } else if (a == (uint8_t) 'R' && c == (uint8_t) 'M' && i == (uint8_t) 'C') { + /* Parse the RMC record to read out the current date */ + + /* $GPRMC,111636.932,A,2447.0949,N,12100.5223,E,000.0,000.0,030407,,,A*61 + * + * Recommended Minimum Specific GNSS Data + * + * 111636.932 UTC time 11:16:36.932 + * A Data Valid (V = receiver warning) + * 2447.0949 Latitude + * N North/south indicator + * 12100.5223 Longitude + * E East/west indicator + * 000.0 Speed over ground + * 000.0 Course over ground + * 030407 UTC date (ddmmyy format) + * A Mode indicator: + * N = data not valid + * A = autonomous mode + * D = differential mode + * E = estimated (dead reckoning) mode + * M = manual input mode + * S = simulator mode + * 61 checksum + */ + ao_gps_skip_field(); + for (i = 0; i < 8; i++) { + ao_gps_lexchar(); + ao_gps_skip_field(); + } + a = ao_gps_decimal(2); + c = ao_gps_decimal(2); + i = ao_gps_decimal(2); + /* Skip remaining fields */ + while (ao_gps_char != '*' && ao_gps_char != '\n' && ao_gps_char != '\r') { + ao_gps_lexchar(); + ao_gps_skip_field(); + } + if (ao_gps_char == '*') { + uint8_t cksum = ao_gps_cksum ^ '*'; + if (cksum != ao_gps_hex(2)) + ao_gps_error = 1; + } else + ao_gps_error = 1; + if (!ao_gps_error) { + ao_gps_next.year = i; + ao_gps_next.month = c; + ao_gps_next.day = a; + ao_gps_date_flags = AO_GPS_DATE_VALID; + } } } } diff --git a/src/ao_gps_test.c b/src/ao_gps_test.c index 366bca71..3692f0e5 100644 --- a/src/ao_gps_test.c +++ b/src/ao_gps_test.c @@ -27,8 +27,12 @@ #define AO_GPS_VALID (1 << 4) #define AO_GPS_RUNNING (1 << 5) +#define AO_GPS_DATE_VALID (1 << 6) struct ao_gps_data { + uint8_t year; + uint8_t month; + uint8_t day; uint8_t hour; uint8_t minute; uint8_t second; diff --git a/src/ao_gps_test_skytraq.c b/src/ao_gps_test_skytraq.c index 510bc419..ccf96378 100644 --- a/src/ao_gps_test_skytraq.c +++ b/src/ao_gps_test_skytraq.c @@ -27,8 +27,12 @@ #define AO_GPS_VALID (1 << 4) #define AO_GPS_RUNNING (1 << 5) +#define AO_GPS_DATE_VALID (1 << 6) struct ao_gps_data { + uint8_t year; + uint8_t month; + uint8_t day; uint8_t hour; uint8_t minute; uint8_t second; -- cgit v1.2.3 From b0d7e3f9c9322542e9b649bb6ad7f7e5bb99dffa Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 15 Nov 2009 16:20:18 -0800 Subject: Stop using SiRF state info. With the switch to the skytraq GPS unit, we don't have the same level of detail in the GPS stream, so stop reporting that in the telemetry stream, in the UI and writing it to eeprom. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 4 ++-- ao-tools/lib/cc-logfile.c | 1 - ao-tools/lib/cc-telem.c | 17 ++++++++++++----- ao-tools/lib/cc.h | 1 - src/ao.h | 12 +----------- src/ao_gps_print.c | 7 +++---- src/ao_gps_sirf.c | 5 +---- src/ao_gps_skytraq.c | 6 ++---- src/ao_gps_test.c | 5 ++--- 9 files changed, 23 insertions(+), 35 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 733eb38c..c12939aa 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -360,7 +360,7 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, nsat = 0; for (k = 0; k < f->gps.sats[j].nsat; k++) { fprintf (gps_file, " %12.7f", (double) f->gps.sats[j].sat[k].c_n); - if (f->gps.sats[j].sat[k].state == 0xbf) + if (f->gps.sats[j].sat[k].svid != 0) nsat++; } fprintf(gps_file, " %d\n", nsat); @@ -381,7 +381,7 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, } nsat = 0; for (k = 0; k < f->gps.sats[j].nsat; k++) - if (f->gps.sats[j].sat[k].state == 0xbf) + if (f->gps.sats[j].sat[k].svid != 0) nsat++; fprintf(kml_file, "%12.7f, %12.7f, %12.7f ", diff --git a/ao-tools/lib/cc-logfile.c b/ao-tools/lib/cc-logfile.c index 3d346bcc..9d086c82 100644 --- a/ao-tools/lib/cc-logfile.c +++ b/ao-tools/lib/cc-logfile.c @@ -212,7 +212,6 @@ read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int * case AO_LOG_GPS_SAT: sat.time = tick; sat.svid = a; - sat.state = (b & 0xff); sat.c_n = (b >> 8) & 0xff; gpssat_add(&f->gps, &sat); break; diff --git a/ao-tools/lib/cc-telem.c b/ao-tools/lib/cc-telem.c index 9a2f6155..ccd40ac2 100644 --- a/ao-tools/lib/cc-telem.c +++ b/ao-tools/lib/cc-telem.c @@ -178,18 +178,25 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem) } if (tracking_pos >= 0 && nword >= tracking_pos + 2 && strcmp(words[tracking_pos], "SAT") == 0) { int c, n, pos; + int per_sat; + int state; + + if (version >= 2) + per_sat = 2; + else + per_sat = 3; cc_parse_int(&n, words[tracking_pos + 1]); pos = tracking_pos + 2; - if (nword >= pos + n * 3) { + if (nword >= pos + n * per_sat) { telem->gps_tracking.channels = n; for (c = 0; c < n; c++) { cc_parse_int(&telem->gps_tracking.sats[c].svid, words[pos + 0]); - cc_parse_hex(&telem->gps_tracking.sats[c].state, - words[pos + 1]); + if (version < 2) + cc_parse_hex(&state, words[pos + 1]); cc_parse_int(&telem->gps_tracking.sats[c].c_n0, - words[pos + 2]); - pos += 3; + words[pos + per_sat - 1]); + pos += per_sat; } } else { telem->gps_tracking.channels = 0; diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index ebc0db7d..0e8ced8a 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -103,7 +103,6 @@ struct cc_gpselt { struct cc_gpssat { double time; uint16_t svid; - uint8_t state; uint8_t c_n; }; diff --git a/src/ao.h b/src/ao.h index c1a0f6e3..b72cac5c 100644 --- a/src/ao.h +++ b/src/ao.h @@ -536,7 +536,7 @@ struct ao_log_record { } gps_altitude; struct { uint16_t svid; - uint8_t state; + uint8_t unused; uint8_t c_n; } gps_sat; struct { @@ -747,18 +747,8 @@ struct ao_gps_data { uint16_t v_error; /* m */ }; -#define SIRF_SAT_STATE_ACQUIRED (1 << 0) -#define SIRF_SAT_STATE_CARRIER_PHASE_VALID (1 << 1) -#define SIRF_SAT_BIT_SYNC_COMPLETE (1 << 2) -#define SIRF_SAT_SUBFRAME_SYNC_COMPLETE (1 << 3) -#define SIRF_SAT_CARRIER_PULLIN_COMPLETE (1 << 4) -#define SIRF_SAT_CODE_LOCKED (1 << 5) -#define SIRF_SAT_ACQUISITION_FAILED (1 << 6) -#define SIRF_SAT_EPHEMERIS_AVAILABLE (1 << 7) - struct ao_gps_sat_data { uint8_t svid; - uint8_t state; uint8_t c_n_1; }; diff --git a/src/ao_gps_print.c b/src/ao_gps_print.c index 95439ec7..b8b73cd2 100644 --- a/src/ao_gps_print.c +++ b/src/ao_gps_print.c @@ -112,17 +112,16 @@ ao_gps_tracking_print(__xdata struct ao_gps_tracking_data *gps_tracking_data) __ sat = gps_tracking_data->sats; v = 0; for (c = 0; c < n; c++) { - if (sat->svid && sat->state) + if (sat->svid) v++; sat++; } printf("%d ", v); sat = gps_tracking_data->sats; for (c = 0; c < n; c++) { - if (sat->svid && sat->state) - printf (" %3d %02x %3d", + if (sat->svid) + printf (" %3d %3d", sat->svid, - sat->state, sat->c_n_1); sat++; } diff --git a/src/ao_gps_sirf.c b/src/ao_gps_sirf.c index 58438760..eb00224c 100644 --- a/src/ao_gps_sirf.c +++ b/src/ao_gps_sirf.c @@ -108,7 +108,6 @@ static __xdata struct sirf_geodetic_nav_data ao_sirf_data; struct sirf_measured_sat_data { uint8_t svid; - uint16_t state; uint8_t c_n_1; }; @@ -264,8 +263,7 @@ static const struct sirf_packet_parse measured_tracker_data_packet[] = { static const struct sirf_packet_parse measured_sat_data_packet[] = { { SIRF_U8, offsetof (struct sirf_measured_sat_data, svid) }, /* 0 SV id */ - { SIRF_DISCARD, 2 }, /* 1 azimuth, 2 elevation */ - { SIRF_U16, offsetof (struct sirf_measured_sat_data, state) }, /* 2 state */ + { SIRF_DISCARD, 4 }, /* 1 azimuth, 2 elevation, 3 state */ { SIRF_U8, offsetof (struct sirf_measured_sat_data, c_n_1) }, /* C/N0 1 */ { SIRF_DISCARD, 9 }, /* C/N0 2-10 */ { SIRF_END, 0 }, @@ -421,7 +419,6 @@ ao_gps(void) __reentrant ao_gps_tracking_data.channels = ao_sirf_tracker_data.channels; for (i = 0; i < 12; i++) { ao_gps_tracking_data.sats[i].svid = ao_sirf_tracker_data.sats[i].svid; - ao_gps_tracking_data.sats[i].state = (uint8_t) ao_sirf_tracker_data.sats[i].state; ao_gps_tracking_data.sats[i].c_n_1 = ao_sirf_tracker_data.sats[i].c_n_1; } ao_mutex_put(&ao_gps_mutex); diff --git a/src/ao_gps_skytraq.c b/src/ao_gps_skytraq.c index b2eef04b..bf192f28 100644 --- a/src/ao_gps_skytraq.c +++ b/src/ao_gps_skytraq.c @@ -326,10 +326,8 @@ ao_gps(void) __reentrant ao_gps_skip_field(); /* elevation */ ao_gps_lexchar(); ao_gps_skip_field(); /* azimuth */ - if (ao_gps_tracking_next.sats[i].c_n_1 = ao_gps_decimal(2)) /* C/N0 */ - ao_gps_tracking_next.sats[i].state = 0xbf; - else - ao_gps_tracking_next.sats[i].state = 0; + if (!(ao_gps_tracking_next.sats[i].c_n_1 = ao_gps_decimal(2))) /* C/N0 */ + ao_gps_tracking_next.sats[i].svid = 0; ao_gps_tracking_next.channels = i + 1; } if (ao_gps_char == '*') { diff --git a/src/ao_gps_test.c b/src/ao_gps_test.c index 3692f0e5..fddfedfd 100644 --- a/src/ao_gps_test.c +++ b/src/ao_gps_test.c @@ -59,7 +59,6 @@ struct ao_gps_data { struct ao_gps_sat_data { uint8_t svid; - uint8_t state; uint8_t c_n_1; }; @@ -435,9 +434,9 @@ ao_dump_state(void *wchan) printf("\n"); printf ("\t"); for (i = 0; i < 12; i++) - printf (" %2d(%02x)", + printf (" %2d(%02d)", ao_gps_tracking_data.sats[i].svid, - ao_gps_tracking_data.sats[i].state); + ao_gps_tracking_data.sats[i].c_n_1); printf ("\n"); } -- cgit v1.2.3 From 8065b8146a31438e66f83c13b99281ec47439a73 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 20 Nov 2009 11:56:48 -0800 Subject: Add GPS date/time output to ao-postflight. GPS date/time information was already being stored in the log, it just wasn't getting displayed by ao-postflight. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 12 ++++++++++++ ao-tools/lib/cc-logfile.c | 16 ++++++++++++++++ ao-tools/lib/cc.h | 5 +++++ 3 files changed, 33 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index c12939aa..a19b7ebb 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -208,6 +208,18 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, "Serial: %9d\n" "Flight: %9d\n", f->serial, f->flight); + if (f->year) { + fprintf(summary_file, + "Date: %04d-%02d-%02d\n", + f->year, f->month, f->day); + } + if (f->gps.num) { + fprintf(summary_file, + "Time: %2d:%02d:%02d\n", + f->gps.data[0].hour, + f->gps.data[0].minute, + f->gps.data[0].second); + } boost_start = f->accel.data[0].time; boost_stop = f->accel.data[f->accel.num-1].time; for (i = 0; i < f->state.num; i++) { diff --git a/ao-tools/lib/cc-logfile.c b/ao-tools/lib/cc-logfile.c index 9d086c82..b0fff9f8 100644 --- a/ao-tools/lib/cc-logfile.c +++ b/ao-tools/lib/cc-logfile.c @@ -136,6 +136,7 @@ gpsdata_free(struct cc_gpsdata *data) #define AO_LOG_GPS_LON 'W' #define AO_LOG_GPS_ALT 'H' #define AO_LOG_GPS_SAT 'V' +#define AO_LOG_GPS_DATE 'Y' #define AO_LOG_POS_NONE (~0UL) @@ -195,6 +196,10 @@ read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int * * any stale data before adding this record */ gps.time = tick; + gps.hour = (a & 0xff); + gps.minute = (a >> 8) & 0xff; + gps.second = (b & 0xff); + gps.flags = (b >> 8) & 0xff; gps_valid = GPS_TIME; break; case AO_LOG_GPS_LAT: @@ -215,6 +220,11 @@ read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int * sat.c_n = (b >> 8) & 0xff; gpssat_add(&f->gps, &sat); break; + case AO_LOG_GPS_DATE: + f->year = 2000 + (a & 0xff); + f->month = (a >> 8) & 0xff; + f->day = (b & 0xff); + break; default: return 0; } @@ -266,10 +276,16 @@ read_telem(const char *line, struct cc_flightraw *f) timedata_add(&f->main, telem.tick, telem.main); timedata_add(&f->state, telem.tick, state_name_to_state(telem.state)); if (telem.gps.gps_locked) { + f->year = telem.gps.gps_time.year; + f->month = telem.gps.gps_time.month; + f->day = telem.gps.gps_time.day; gps.time = telem.tick; gps.lat = telem.gps.lat; gps.lon = telem.gps.lon; gps.alt = telem.gps.alt; + gps.hour = telem.gps.gps_time.hour; + gps.minute = telem.gps.gps_time.minute; + gps.second = telem.gps.gps_time.second; gpsdata_add(&f->gps, &gps); } return 1; diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 0e8ced8a..bdeeaaf5 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -86,6 +86,10 @@ struct cc_timedata { struct cc_gpselt { double time; + int hour; + int minute; + int second; + int flags; double lat; double lon; double alt; @@ -149,6 +153,7 @@ struct cc_flightraw { int serial; double ground_accel; double ground_pres; + int year, month, day; struct cc_timedata accel; struct cc_timedata pres; struct cc_timedata temp; -- cgit v1.2.3 From 87e6f3e5c1688503ab8595912d8d6eb7139830b7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 20 Nov 2009 12:16:37 -0800 Subject: Eliminate SiRF state values from ao-view. With Skytraq not having any visible GPS state information, just remove this from the display. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview_state.c | 15 +++------------ ao-tools/lib/cc.h | 1 - 2 files changed, 3 insertions(+), 13 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_state.c b/ao-tools/ao-view/aoview_state.c index 21cea99a..838899a7 100644 --- a/ao-tools/ao-view/aoview_state.c +++ b/ao-tools/ao-view/aoview_state.c @@ -342,23 +342,14 @@ aoview_state_notify(struct cc_telem *data) } if (state->gps.gps_connected) { int nsat_vis = 0; - int nsat_locked = 0; int c; - for (c = 0; c < state->gps_tracking.channels; c++) { - if ((state->gps_tracking.sats[c].state & 0xff) == 0xbf) - nsat_locked++; - } aoview_table_add_row(2, "Satellites Visible", "%d", state->gps_tracking.channels); - aoview_table_add_row(2, "Satellites Locked", "%d", nsat_locked); for (c = 0; c < state->gps_tracking.channels; c++) { - aoview_table_add_row(2, "Satellite id,state,C/N0", - "%3d,%02x,%2d%s", + aoview_table_add_row(2, "Satellite id,C/N0", + "%3d,%2d", state->gps_tracking.sats[c].svid, - state->gps_tracking.sats[c].state, - state->gps_tracking.sats[c].c_n0, - (state->gps_tracking.sats[c].state & 0xff) == 0xbf ? - " LOCKED" : ""); + state->gps_tracking.sats[c].c_n0); } } aoview_table_finish(); diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index bdeeaaf5..46b16a8e 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -233,7 +233,6 @@ struct cc_gps { struct cc_gps_sat { int svid; - int state; int c_n0; }; -- cgit v1.2.3 From 1a3b4c02a01187f8b7b9a9c97712476d0007ab35 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 21 Nov 2009 19:52:26 -0800 Subject: Document ao-postflight --gps and --kml options. These were missing from the man page, but included in the --help output. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.1 | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.1 b/ao-tools/ao-postflight/ao-postflight.1 index eca4bb34..7bafb6e1 100644 --- a/ao-tools/ao-postflight/ao-postflight.1 +++ b/ao-tools/ao-postflight/ao-postflight.1 @@ -29,6 +29,10 @@ ao-postflight \- Analyse a flight log (either telemetry or eeprom) [\--raw=] [\-p ] [\--plot=] +[\-g Date: Sat, 21 Nov 2009 20:35:22 -0800 Subject: Make ao-postflight create filenames using input filenames. Instead of requiring the user to provide names for the various output options, just create them from the input name by replacing the extension. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 139 +++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 49 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index a19b7ebb..7cedaa5b 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -392,9 +392,11 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, j++; } nsat = 0; - for (k = 0; k < f->gps.sats[j].nsat; k++) - if (f->gps.sats[j].sat[k].svid != 0) - nsat++; + if (j < f->gps.numsats) { + for (k = 0; k < f->gps.sats[j].nsat; k++) + if (f->gps.sats[j].sat[k].svid != 0) + nsat++; + } fprintf(kml_file, "%12.7f, %12.7f, %12.7f ", f->gps.data[i].lon, @@ -443,12 +445,12 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, } static const struct option options[] = { - { .name = "summary", .has_arg = 1, .val = 's' }, - { .name = "detail", .has_arg = 1, .val = 'd' }, - { .name = "plot", .has_arg = 1, .val = 'p' }, - { .name = "raw", .has_arg = 1, .val = 'r' }, - { .name = "gps", .has_arg = 1, .val = 'g' }, - { .name = "kml", .has_arg = 1, .val = 'k' }, + { .name = "summary", .has_arg = 2, .val = 's' }, + { .name = "detail", .has_arg = 2, .val = 'd' }, + { .name = "plot", .has_arg = 2, .val = 'p' }, + { .name = "raw", .has_arg = 2, .val = 'r' }, + { .name = "gps", .has_arg = 2, .val = 'g' }, + { .name = "kml", .has_arg = 2, .val = 'k' }, { 0, 0, 0, 0}, }; @@ -465,6 +467,46 @@ static void usage(char *program) exit(1); } +char * +replace_extension(char *file, char *extension) +{ + char *slash; + char *dot; + char *new; + int newlen; + + slash = strrchr(file, '/'); + dot = strrchr(file, '.'); + if (!dot || (slash && dot < slash)) + dot = file + strlen(file); + newlen = (dot - file) + strlen (extension) + 1; + new = malloc (newlen); + strncpy (new, file, dot - file); + new[dot-file] = '\0'; + strcat (new, extension); + return new; +} + +FILE * +open_output(char *outname, char *inname, char *extension) +{ + char *o; + FILE *out; + + if (outname) + o = outname; + else + o = replace_extension(inname, extension); + out = fopen(o, "w"); + if (!out) { + perror (o); + exit(1); + } + if (o != outname) + free(o); + return out; +} + int main (int argc, char **argv) { @@ -486,72 +528,46 @@ main (int argc, char **argv) char *plot_name = NULL; char *gps_name = NULL; char *kml_name = NULL; + int has_summary = 0; + int has_detail = 0; + int has_plot = 0; + int has_raw = 0; + int has_gps = 0; + int has_kml = 0; while ((c = getopt_long(argc, argv, "s:d:p:r:g:k:", options, NULL)) != -1) { switch (c) { case 's': summary_name = optarg; + has_summary = 1; break; case 'd': detail_name = optarg; + has_detail = 1; break; case 'p': plot_name = optarg; + has_plot = 1; break; case 'r': raw_name = optarg; + has_raw = 1; break; case 'g': gps_name = optarg; + has_gps = 1; break; case 'k': kml_name = optarg; + has_kml = 1; break; default: usage(argv[0]); break; } } - summary_file = stdout; - if (summary_name) { - summary_file = fopen(summary_name, "w"); - if (!summary_file) { - perror (summary_name); - exit(1); - } - } - if (detail_name) { - if (summary_name && !strcmp (summary_name, detail_name)) - detail_file = summary_file; - else { - detail_file = fopen(detail_name, "w"); - if (!detail_file) { - perror(detail_name); - exit(1); - } - } - } - if (raw_name) { - raw_file = fopen (raw_name, "w"); - if (!raw_file) { - perror(raw_name); - exit(1); - } - } - if (gps_name) { - gps_file = fopen(gps_name, "w"); - if (!gps_file) { - perror(gps_name); - exit(1); - } - } - if (kml_name) { - kml_file = fopen(kml_name, "w"); - if (!kml_file) { - perror(kml_name); - exit(1); - } - } + if (!has_summary) + summary_file = stdout; for (i = optind; i < argc; i++) { file = fopen(argv[i], "r"); if (!file) { @@ -559,6 +575,16 @@ main (int argc, char **argv) ret++; continue; } + if (has_summary && !summary_file) + summary_file = open_output(summary_name, argv[i], ".summary"); + if (has_detail && !detail_file) + detail_file = open_output(detail_name, argv[i], ".detail"); + if (has_raw && !raw_file) + raw_file = open_output(raw_name, argv[i], ".raw"); + if (has_gps && !gps_file) + gps_file = open_output(gps_name, argv[i], ".gps"); + if (has_kml && !kml_file) + kml_file = open_output(gps_name, argv[i], ".kml"); s = strstr(argv[i], "-serial-"); if (s) serial = atoi(s + 8); @@ -574,6 +600,21 @@ main (int argc, char **argv) raw->serial = serial; analyse_flight(raw, summary_file, detail_file, raw_file, plot_name, gps_file, kml_file); cc_flightraw_free(raw); + if (has_summary && !summary_name) { + fclose(summary_file); summary_file = NULL; + } + if (has_detail && !detail_name) { + fclose(detail_file); detail_file = NULL; + } + if (has_summary && !raw_name) { + fclose(raw_file); raw_file = NULL; + } + if (has_gps && !gps_name) { + fclose(gps_file); gps_file = NULL; + } + if (has_kml && !kml_name) { + fclose(kml_file); kml_file = NULL; + } } return ret; } -- cgit v1.2.3 From 1e7fb61700f1f6f2ed5fdbc4380d7187b0cd187b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 21 Nov 2009 21:09:03 -0800 Subject: Fix --plot arg handling. Add -all option. The --plot file name handing is special as the library wants a filename instead of a stdio file pointer. Add a --all option that just creates all of the possible outputs. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 7cedaa5b..ed91be15 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -451,12 +451,14 @@ static const struct option options[] = { { .name = "raw", .has_arg = 2, .val = 'r' }, { .name = "gps", .has_arg = 2, .val = 'g' }, { .name = "kml", .has_arg = 2, .val = 'k' }, + { .name = "all", .has_arg = 0, .val = 'a' }, { 0, 0, 0, 0}, }; static void usage(char *program) { fprintf(stderr, "usage: %s\n" + "\t[--all] [-a]\n" "\t[--summary=] [-s ]\n" "\t[--detail=]\n" "\t[--raw= -r serial) raw->serial = serial; - analyse_flight(raw, summary_file, detail_file, raw_file, plot_name, gps_file, kml_file); + analyse_flight(raw, summary_file, detail_file, raw_file, this_plot_name, gps_file, kml_file); cc_flightraw_free(raw); if (has_summary && !summary_name) { fclose(summary_file); summary_file = NULL; @@ -606,7 +618,10 @@ main (int argc, char **argv) if (has_detail && !detail_name) { fclose(detail_file); detail_file = NULL; } - if (has_summary && !raw_name) { + if (this_plot_name && this_plot_name != plot_name) { + free (this_plot_name); this_plot_name = NULL; + } + if (has_raw && !raw_name) { fclose(raw_file); raw_file = NULL; } if (has_gps && !gps_name) { -- cgit v1.2.3 From 2d77c18b15834046b7b79d49d87211828f2409e9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 21 Nov 2009 21:10:09 -0800 Subject: Convert telemetry file GPS satellite information in cc_log_read The satellite info wasn't being correctly converted from telemetry files to the data log structure, so ao-postflight was not seeing it. Signed-off-by: Keith Packard --- ao-tools/lib/cc-logfile.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/lib/cc-logfile.c b/ao-tools/lib/cc-logfile.c index b0fff9f8..842e5c7c 100644 --- a/ao-tools/lib/cc-logfile.c +++ b/ao-tools/lib/cc-logfile.c @@ -263,6 +263,9 @@ read_telem(const char *line, struct cc_flightraw *f) { struct cc_telem telem; struct cc_gpselt gps; + struct cc_gpssat sat; + int s; + if (!cc_telem_parse(line, &telem)) return 0; f->ground_accel = telem.ground_accel; @@ -288,6 +291,12 @@ read_telem(const char *line, struct cc_flightraw *f) gps.second = telem.gps.gps_time.second; gpsdata_add(&f->gps, &gps); } + for (s = 0; s < telem.gps_tracking.channels; s++) { + sat.time = telem.tick; + sat.svid = telem.gps_tracking.sats[s].svid; + sat.c_n = telem.gps_tracking.sats[s].c_n0; + gpssat_add(&f->gps, &sat); + } return 1; } -- cgit v1.2.3 From b84b634d9ae8ce6ab1c02833a3ed8514404e1ca3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 21 Nov 2009 22:11:45 -0800 Subject: Don't crash if --plot isn't passed on ao-postflight command line Crashing is not nice. Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index ed91be15..caa7fb74 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -536,7 +536,7 @@ main (int argc, char **argv) int has_raw = 0; int has_gps = 0; int has_kml = 0; - char *this_plot_name; + char *this_plot_name = NULL;; while ((c = getopt_long(argc, argv, "s:d:p:r:g:k:a", options, NULL)) != -1) { switch (c) { -- cgit v1.2.3 From a9ada1b538af3308e1b22bd024d9204521184173 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 21 Nov 2009 22:12:21 -0800 Subject: ao-postflight: compute barometric alt for each GPS position Print that to the --gps file, and use that in the --kml file for the altitude. Gives a very different picture of our flight tracks, presumably far more accurate (at least in altitude). Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 101 +++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 43 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index caa7fb74..51bcd6e3 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -351,10 +351,21 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, time, pres, accel); } } - if (gps_file) { - int j = 0; - fprintf(gps_file, "%9s %12s %12s %12s\n", - "time", "lat", "lon", "alt"); + if (gps_file || kml_file) { + int j = 0, baro_pos; + double baro_offset; + double baro = 0.0; + + if (gps_file) + fprintf(gps_file, "%9s %12s %12s %9s %8s %5s\n", + "time", "lat", "lon", "alt", "baro", "nsat"); + if (kml_file) + fprintf(kml_file, "%s", kml_header); + if (f->gps.num) + baro_offset = f->gps.data[0].alt; + else + baro_offset = 0; + baro_pos = 0; for (i = 0; i < f->gps.num; i++) { int nsat = 0; int k; @@ -364,52 +375,56 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, break; j++; } - fprintf(gps_file, "%12.7f %12.7f %12.7f %12.7f", - (f->gps.data[i].time - boost_start) / 100.0, - f->gps.data[i].lat, - f->gps.data[i].lon, - f->gps.data[i].alt); + if (cooked) { + while (baro_pos < cooked->pres_pos.num) { + double baro_time = cooked->accel_accel.start + baro_pos * cooked->accel_accel.step; + if (baro_time >= f->gps.data[i].time) + break; + baro_pos++; + } + if (baro_pos < cooked->pres_pos.num) + baro = cooked->pres_pos.data[baro_pos]; + } + if (gps_file) + fprintf(gps_file, "%12.7f %12.7f %12.7f %7.1f %7.1f", + (f->gps.data[i].time - boost_start) / 100.0, + f->gps.data[i].lat, + f->gps.data[i].lon, + f->gps.data[i].alt, + baro + baro_offset); + if (kml_file) { + fprintf(kml_file, "%12.7f, %12.7f, %12.7f ", + f->gps.data[i].lon, + f->gps.data[i].lat, + baro + baro_offset, + f->gps.data[i].alt, + (f->gps.data[i].time - boost_start) / 100.0, + nsat); + if (i < f->gps.num - 1) + fprintf(kml_file, ",\n"); + else + fprintf(kml_file, "\n"); + } + nsat = 0; for (k = 0; k < f->gps.sats[j].nsat; k++) { - fprintf (gps_file, " %12.7f", (double) f->gps.sats[j].sat[k].c_n); if (f->gps.sats[j].sat[k].svid != 0) nsat++; } - fprintf(gps_file, " %d\n", nsat); - } - } - if (kml_file) { - int j = 0; - - fprintf(kml_file, "%s", kml_header); - for (i = 0; i < f->gps.num; i++) { - int nsat = 0; - int k; - while (j < f->gps.numsats - 1) { - if (f->gps.sats[j].sat[0].time <= f->gps.data[i].time && - f->gps.data[i].time < f->gps.sats[j+1].sat[0].time) - break; - j++; + if (gps_file) { + fprintf(gps_file, " %4d", nsat); + for (k = 0; k < f->gps.sats[j].nsat; k++) { + if (f->gps.sats[j].sat[k].svid != 0) { + fprintf (gps_file, " %3d(%4.1f)", + f->gps.sats[j].sat[k].svid, + (double) f->gps.sats[j].sat[k].c_n); + } + } + fprintf(gps_file, "\n"); } - nsat = 0; - if (j < f->gps.numsats) { - for (k = 0; k < f->gps.sats[j].nsat; k++) - if (f->gps.sats[j].sat[k].svid != 0) - nsat++; - } - - fprintf(kml_file, "%12.7f, %12.7f, %12.7f ", - f->gps.data[i].lon, - f->gps.data[i].lat, - f->gps.data[i].alt, - (f->gps.data[i].time - boost_start) / 100.0, - nsat); - if (i < f->gps.num - 1) - fprintf(kml_file, ",\n"); - else - fprintf(kml_file, "\n"); } - fprintf(kml_file, "%s", kml_footer); + if (kml_file) + fprintf(kml_file, "%s", kml_footer); } if (cooked && plot_name) { struct cc_perioddata *speed; -- cgit v1.2.3 From 06cebd1026dc1bd6ee51526fa2d02905df3b3b37 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 22 Nov 2009 00:52:58 -0800 Subject: ao-postflight: don't try to use missing gps sat data Signed-off-by: Keith Packard --- ao-tools/ao-postflight/ao-postflight.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 51bcd6e3..48752d07 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -407,20 +407,22 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, } nsat = 0; - for (k = 0; k < f->gps.sats[j].nsat; k++) { - if (f->gps.sats[j].sat[k].svid != 0) - nsat++; - } - if (gps_file) { - fprintf(gps_file, " %4d", nsat); + if (f->gps.sats) { for (k = 0; k < f->gps.sats[j].nsat; k++) { - if (f->gps.sats[j].sat[k].svid != 0) { - fprintf (gps_file, " %3d(%4.1f)", - f->gps.sats[j].sat[k].svid, - (double) f->gps.sats[j].sat[k].c_n); + if (f->gps.sats[j].sat[k].svid != 0) + nsat++; + } + if (gps_file) { + fprintf(gps_file, " %4d", nsat); + for (k = 0; k < f->gps.sats[j].nsat; k++) { + if (f->gps.sats[j].sat[k].svid != 0) { + fprintf (gps_file, " %3d(%4.1f)", + f->gps.sats[j].sat[k].svid, + (double) f->gps.sats[j].sat[k].c_n); + } } + fprintf(gps_file, "\n"); } - fprintf(gps_file, "\n"); } } if (kml_file) -- cgit v1.2.3 From d6ba07e885bdc62ba64719c9d8cc42fcecbcb09d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 22 Nov 2009 01:10:44 -0800 Subject: Automatically extract flight number for eeprom and telem filenames. Extract flight number from either telemetry or eeprom files and use that in the resulting filenames. To ensure that files remain unique, add a new field, -seq-%03d. This is appended only when the sequence number is non-zero as it shouldn't occur in normal usage. This also eliminates some duplicate filename creation code in the library and aoview sources. Signed-off-by: Keith Packard --- ao-tools/ao-dumplog/ao-dumplog.c | 32 +++++++++++++++-------- ao-tools/ao-view/aoview_eeprom.c | 2 ++ ao-tools/ao-view/aoview_file.c | 53 +++++++++++++++++++-------------------- ao-tools/ao-view/aoview_log.c | 12 +++++++++ ao-tools/ao-view/aoview_monitor.c | 1 + ao-tools/lib/cc-log.c | 23 +++++++++++------ ao-tools/lib/cc.h | 2 +- 7 files changed, 78 insertions(+), 47 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c index b3a0a25a..440a02b5 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.c +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "cc-usb.h" #include "cc.h" @@ -62,6 +63,7 @@ static const char *state_names[] = { "invalid" }; + int main (int argc, char **argv) { @@ -72,7 +74,8 @@ main (int argc, char **argv) char line[8192]; FILE *out; char *filename; - int serial_number; + int serial_number = 0; + int flight = 0; char cmd; int tick, a, b; int block; @@ -84,6 +87,7 @@ main (int argc, char **argv) int remote = 0; int any_valid; int invalid; + char serial_line[8192]; while ((c = getopt_long(argc, argv, "T:D:R", options, NULL)) != -1) { switch (c) { @@ -121,24 +125,17 @@ main (int argc, char **argv) out = NULL; for (;;) { cc_usb_getline(cc, line, sizeof (line)); - if (sscanf(line, "serial-number %u", &serial_number) == 1) { - filename = cc_make_filename(serial_number, "eeprom"); - out = fopen (filename, "w"); - if (!out) { - perror(filename); - } - fprintf (out, "%s\n", line); - } + if (sscanf(line, "serial-number %u", &serial_number) == 1) + strcpy(serial_line, line); if (!strncmp(line, "software-version", 16)) break; } - if (!out) { + if (!serial_number) { fprintf(stderr, "no serial number found\n"); cc_usb_close(cc); exit(1); } printf ("Serial number: %d\n", serial_number); - printf ("File name: %s\n", filename); done = 0; column = 0; for (block = 0; !done && block < 511; block++) { @@ -170,6 +167,19 @@ main (int argc, char **argv) tick = data[2] + (data[3] << 8); a = data[4] + (data[5] << 8); b = data[6] + (data[7] << 8); + if (cmd == 'F') { + flight = b; + filename = cc_make_filename(serial_number, flight, "eeprom"); + printf ("Flight: %d\n", flight); + printf ("File name: %s\n", filename); + out = fopen (filename, "w"); + if (!out) { + perror(filename); + exit(1); + } + fprintf(out, "%s\n", serial_line); + } + if (cmd == 'S' && a <= 8) { if (column) putchar('\n'); printf("%s\n", state_names[a]); diff --git a/ao-tools/ao-view/aoview_eeprom.c b/ao-tools/ao-view/aoview_eeprom.c index 34e2deed..447b83a4 100644 --- a/ao-tools/ao-view/aoview_eeprom.c +++ b/ao-tools/ao-view/aoview_eeprom.c @@ -66,6 +66,8 @@ aoview_eeprom_parse(struct aoview_serial *serial, if (sscanf(line, "serial-number %u", &serial_number) == 1) { aoview_file_set_serial(eeprom_file, serial_number); } else if (sscanf(line, "%c %x %x %x", &cmd, &tick, &a, &b) == 4) { + if (cmd == 'F') + aoview_file_set_flight(eeprom_file, b); aoview_file_printf(eeprom_file, "%s\n", line); if (cmd == 'S' && a == 8) { aoview_eeprom_done(serial); diff --git a/ao-tools/ao-view/aoview_file.c b/ao-tools/ao-view/aoview_file.c index 5288c2f7..292887a0 100644 --- a/ao-tools/ao-view/aoview_file.c +++ b/ao-tools/ao-view/aoview_file.c @@ -28,6 +28,7 @@ struct aoview_file { char *name; int failed; int serial; + int flight; int sequence; }; @@ -94,6 +95,7 @@ gboolean aoview_file_start(struct aoview_file *file) { char base[50]; + char seq[20]; struct tm tm; time_t now; char *full; @@ -105,34 +107,17 @@ aoview_file_start(struct aoview_file *file) if (file->failed) return FALSE; - now = time(NULL); - (void) localtime_r(&now, &tm); - aoview_mkdir(aoview_file_dir); - for (;;) { - snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", - tm.tm_year + 1900, - tm.tm_mon + 1, - tm.tm_mday, - file->serial, - file->sequence, - file->ext); - full = aoview_fullname(aoview_file_dir, base); - r = access(full, F_OK); - if (r < 0) { - file->file = fopen(full, "w"); - if (!file->file) { - aoview_file_open_failed(full); - free(full); - file->failed = 1; - return FALSE; - } else { - setlinebuf(file->file); - file->name = full; - return TRUE; - } - } + full = cc_make_filename(file->serial, file->flight, file->ext); + file->file = fopen(full, "w"); + if (!file->file) { + aoview_file_open_failed(full); free(full); - file->sequence++; + file->failed = 1; + return FALSE; + } else { + setlinebuf(file->file); + file->name = full; + return TRUE; } } @@ -195,6 +180,20 @@ aoview_file_get_serial(struct aoview_file *file) return file->serial; } +void +aoview_file_set_flight(struct aoview_file *file, int flight) +{ + if (flight != file->flight) + aoview_file_finish(file); + file->flight = flight; +} + +int +aoview_file_get_flight(struct aoview_file *file) +{ + return file->flight; +} + void aoview_file_init(GladeXML *xml) { diff --git a/ao-tools/ao-view/aoview_log.c b/ao-tools/ao-view/aoview_log.c index 1b89c28c..2880ecb1 100644 --- a/ao-tools/ao-view/aoview_log.c +++ b/ao-tools/ao-view/aoview_log.c @@ -38,6 +38,18 @@ aoview_log_get_serial(void) return aoview_file_get_serial(aoview_log); } +void +aoview_log_set_flight(int flight) +{ + aoview_file_set_flight(aoview_log, flight); +} + +int +aoview_log_get_flight(void) +{ + return aoview_file_get_flight(aoview_log); +} + void aoview_log_printf(char *format, ...) { diff --git a/ao-tools/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c index 3d235e44..4d7e7a9f 100644 --- a/ao-tools/ao-view/aoview_monitor.c +++ b/ao-tools/ao-view/aoview_monitor.c @@ -68,6 +68,7 @@ aoview_monitor_callback(gpointer user_data, if (monitor_pos) { if (aoview_monitor_parse(monitor_line)) { aoview_log_set_serial(aostate.data.serial); + aoview_log_set_flight(aostate.data.flight); if (aoview_log_get_serial()) aoview_log_printf ("%s\n", monitor_line); } diff --git a/ao-tools/lib/cc-log.c b/ao-tools/lib/cc-log.c index dd8177f4..ed51f87e 100644 --- a/ao-tools/lib/cc-log.c +++ b/ao-tools/lib/cc-log.c @@ -82,9 +82,10 @@ cc_get_log_dir(void) } char * -cc_make_filename(int serial, char *ext) +cc_make_filename(int serial, int flight, char *ext) { char base[50]; + char seq[20]; struct tm tm; time_t now; char *full; @@ -96,13 +97,19 @@ cc_make_filename(int serial, char *ext) cc_mkdir(cc_get_log_dir()); sequence = 0; for (;;) { - snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", - tm.tm_year + 1900, - tm.tm_mon + 1, - tm.tm_mday, - serial, - sequence, - ext); + if (sequence) + snprintf(seq, sizeof(seq), "-seq-%03d", sequence); + else + seq[0] = '\0'; + + snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d%s.%s", + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + serial, + flight, + seq, + ext); full = cc_fullname(cc_get_log_dir(), base); r = access(full, F_OK); if (r < 0) diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 46b16a8e..ede46aa0 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -61,7 +61,7 @@ char * cc_get_log_dir(void); char * -cc_make_filename(int serial, char *ext); +cc_make_filename(int serial, int flight, char *ext); /* * For sequential data which are not evenly spaced -- cgit v1.2.3 From 5481082b18226a0de6b377215b3b330bdbc4a6c6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 5 Dec 2009 19:50:38 -0800 Subject: Allow radio calibration to be set from ao-load This moves the initial radio calibration value into const memory where it will be used if no eeprom configuration value is available, either on an unprogrammed board with eeprom or a device without an eeprom. Signed-off-by: Keith Packard --- ao-tools/ao-load/ao-load.c | 46 ++++++++++++++++++++++++++++++++++++---------- src/ao_config.c | 10 +++++++--- 2 files changed, 43 insertions(+), 13 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-load/ao-load.c b/ao-tools/ao-load/ao-load.c index f5466612..4aa91b29 100644 --- a/ao-tools/ao-load/ao-load.c +++ b/ao-tools/ao-load/ao-load.c @@ -29,14 +29,17 @@ struct sym { unsigned addr; char *name; -} serial_symbols[] = { +} ao_symbols[] = { { 0, "_ao_serial_number" }, -#define AO_SERIAL_NUMBER (serial_symbols[0].addr) +#define AO_SERIAL_NUMBER (ao_symbols[0].addr) { 0, "_ao_usb_descriptors" }, -#define AO_USB_DESCRIPTORS (serial_symbols[1].addr) +#define AO_USB_DESCRIPTORS (ao_symbols[1].addr) + { 0, "_ao_radio_cal" }, +#define AO_RADIO_CAL (ao_symbols[2].addr) }; -#define NUM_SERIAL_SYMBOLS (sizeof(serial_symbols)/sizeof(serial_symbols[0])) +#define NUM_SERIAL_SYMBOLS 2 +#define NUM_SYMBOLS 3 static int find_symbols(FILE *map) @@ -64,14 +67,14 @@ find_symbols(FILE *map) a = strtoul(colon+1, &addr_end, 16); if (a == ULONG_MAX || addr_end == addr) continue; - for (s = 0; s < NUM_SERIAL_SYMBOLS; s++) - if (!strcmp(serial_symbols[s].name, name)) { - serial_symbols[s].addr = (unsigned) a; + for (s = 0; s < NUM_SYMBOLS; s++) + if (!strcmp(ao_symbols[s].name, name)) { + ao_symbols[s].addr = (unsigned) a; ++found; break; } } - return found == NUM_SERIAL_SYMBOLS; + return found >= NUM_SERIAL_SYMBOLS; } static int @@ -93,12 +96,13 @@ rewrite(struct hex_image *image, unsigned addr, char *data, int len) static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, + { .name = "cal", .has_arg = 1, .val = 'c' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty ] [--device ] file.ihx serial-number\n", program); + fprintf(stderr, "usage: %s [--tty ] [--device ] [--cal ] file.ihx serial-number\n", program); exit(1); } @@ -125,9 +129,12 @@ main (int argc, char **argv) int string_num; char *tty = NULL; char *device = NULL; + uint32_t cal = 0; + char cal_int[4]; + char *cal_end; int c; - while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:c:", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; @@ -135,6 +142,11 @@ main (int argc, char **argv) case 'D': device = optarg; break; + case 'c': + cal = strtoul(optarg, &cal_end, 10); + if (cal_end == optarg || *cal_end != '\0') + usage(argv[0]); + break; default: usage(argv[0]); break; @@ -225,6 +237,20 @@ main (int argc, char **argv) if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len)) usage(argv[0]); + if (cal) { + cal_int[0] = cal & 0xff; + cal_int[1] = (cal >> 8) & 0xff; + cal_int[2] = (cal >> 16) & 0xff; + cal_int[3] = (cal >> 24) & 0xff; + if (!AO_RADIO_CAL) { + fprintf(stderr, "Cannot find radio calibration location in image\n"); + exit(1); + } + if (!rewrite(image, AO_RADIO_CAL, cal_int, sizeof (cal_int))) { + fprintf(stderr, "Cannot rewrite radio calibration at %04x\n", AO_RADIO_CAL); + exit(1); + } + } if (!tty) tty = cc_usbdevs_find_by_arg(device, "TIDongle"); dbg = ccdbg_open(tty); diff --git a/src/ao_config.c b/src/ao_config.c index 3609ec06..4349bca8 100644 --- a/src/ao_config.c +++ b/src/ao_config.c @@ -31,8 +31,12 @@ __xdata uint8_t ao_config_mutex; * For 434.550MHz, the frequency value is: * * 434.550e6 / (24e6 / 2**16) = 1186611.2 + * + * This value is stored in a const variable so that + * ao-load can change it during programming for + * devices that have no eeprom for config data. */ -#define AO_CONFIG_DEFAULT_RADIO_CAL 1186611 +const uint32_t ao_radio_cal = 1186611; static void _ao_config_put(void) @@ -57,7 +61,7 @@ _ao_config_get(void) memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN, sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1); ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY; - ao_config.radio_cal = AO_CONFIG_DEFAULT_RADIO_CAL; + ao_config.radio_cal = ao_radio_cal; ao_config_dirty = 1; } if (ao_config.minor < AO_CONFIG_MINOR) { @@ -71,7 +75,7 @@ _ao_config_get(void) } /* Fixups for minor version 3 */ if (ao_config.minor < 3) - ao_config.radio_cal = AO_CONFIG_DEFAULT_RADIO_CAL; + ao_config.radio_cal = ao_radio_cal; ao_config.minor = AO_CONFIG_MINOR; ao_config_dirty = 1; } -- cgit v1.2.3 From 7ac8efea5d60b81adccdc1e38ac4c13facfae7c9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 15 Dec 2009 23:58:29 -0800 Subject: Add --cal to man page --- ao-tools/ao-load/ao-load.1 | 11 +++++++++++ ao-tools/ao-rawload/ao-rawload.c | 12 +++++++++++- src/Makefile | 3 ++- src/ao_gps_sirf.c | 17 ----------------- src/ao_gps_skytraq.c | 17 ----------------- 5 files changed, 24 insertions(+), 36 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-load/ao-load.1 b/ao-tools/ao-load/ao-load.1 index eb2bc0d8..79b76a79 100644 --- a/ao-tools/ao-load/ao-load.1 +++ b/ao-tools/ao-load/ao-load.1 @@ -25,6 +25,7 @@ ao-load \- flash a program to a AltOS device [\--tty \fItty-device\fP] [\-D \fIaltos-device\fP] [\--device \fIaltos-device\fP] +[\--cal \fIradio-calibration\fP] \fIfile.ihx\fP \fIdevice serial number\fP .SH DESCRIPTION @@ -52,6 +53,16 @@ TeleMetrum 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. +.TP +\-c radio-calibration | --cal radio-calibration +This programs the radio calibration value into the image for hardware +which doesn't have any eeprom storage for this value. The value here +can be computed given the current radio calibration value, the +measured frequency and the desired frequency: +.IP + cal' = cal * (desired/measured) +.IP +The default calibration value is 1186611. .SH USAGE .I ao-load reads the specified .ihx file into memory, locates the matching .map diff --git a/ao-tools/ao-rawload/ao-rawload.c b/ao-tools/ao-rawload/ao-rawload.c index d9ee5718..0098b658 100644 --- a/ao-tools/ao-rawload/ao-rawload.c +++ b/ao-tools/ao-rawload/ao-rawload.c @@ -19,16 +19,18 @@ #include #include #include "ccdbg.h" +#include "cc.h" static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, + { .name = "run", .has_arg = 0, .val = 'r' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty ] [--device ] file.ihx\n", program); + fprintf(stderr, "usage: %s [--tty ] [--device ] [--run] file.ihx\n", program); exit(1); } @@ -45,6 +47,7 @@ main (int argc, char **argv) char *tty = NULL; char *device = NULL; int c; + int run = 0; while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { switch (c) { @@ -54,6 +57,9 @@ main (int argc, char **argv) case 'D': device = optarg; break; + case 'r': + run = 1; + break; default: usage(argv[0]); break; @@ -105,6 +111,10 @@ main (int argc, char **argv) ccdbg_close(dbg); exit(1); } + if (run) { + ccdbg_set_pc(dbg, image->address); + ccdbg_resume(dbg); + } ccdbg_close(dbg); exit (0); } diff --git a/src/Makefile b/src/Makefile index 8c24e6f4..8074d42d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -43,7 +43,7 @@ ALTOS_DRIVER_SRC = \ ao_usb.c TELE_COMMON_SRC = \ - ao_gps_print.c \ + ao_dbg.c \ ao_packet.c \ ao_packet_slave.c \ ao_state.c @@ -53,6 +53,7 @@ TELE_COMMON_SRC = \ # TELE_RECEIVER_SRC =\ ao_monitor.c \ + ao_gps_print.c \ ao_packet_master.c \ ao_rssi.c diff --git a/src/ao_gps_sirf.c b/src/ao_gps_sirf.c index eb00224c..64b66c95 100644 --- a/src/ao_gps_sirf.c +++ b/src/ao_gps_sirf.c @@ -430,25 +430,8 @@ ao_gps(void) __reentrant __xdata struct ao_task ao_gps_task; -static void -gps_dump(void) __reentrant -{ - ao_mutex_get(&ao_gps_mutex); - ao_gps_print(&ao_gps_data); - putchar('\n'); - ao_gps_tracking_print(&ao_gps_tracking_data); - putchar('\n'); - ao_mutex_put(&ao_gps_mutex); -} - -__code struct ao_cmds ao_gps_cmds[] = { - { 'g', gps_dump, "g Display current GPS values" }, - { 0, gps_dump, NULL }, -}; - void ao_gps_init(void) { ao_add_task(&ao_gps_task, ao_gps, "gps"); - ao_cmd_register(&ao_gps_cmds[0]); } diff --git a/src/ao_gps_skytraq.c b/src/ao_gps_skytraq.c index ef581349..361c77ce 100644 --- a/src/ao_gps_skytraq.c +++ b/src/ao_gps_skytraq.c @@ -410,25 +410,8 @@ ao_gps(void) __reentrant __xdata struct ao_task ao_gps_task; -static void -gps_dump(void) __reentrant -{ - ao_mutex_get(&ao_gps_mutex); - ao_gps_print(&ao_gps_data); - putchar('\n'); - ao_gps_tracking_print(&ao_gps_tracking_data); - putchar('\n'); - ao_mutex_put(&ao_gps_mutex); -} - -__code struct ao_cmds ao_gps_cmds[] = { - { 'g', gps_dump, "g Display current GPS values" }, - { 0, gps_dump, NULL }, -}; - void ao_gps_init(void) { ao_add_task(&ao_gps_task, ao_gps, "gps"); - ao_cmd_register(&ao_gps_cmds[0]); } -- cgit v1.2.3 From 9856b7c4397afcecc8f541af9a83824e817b3612 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 10 Jan 2010 16:31:50 -0800 Subject: Switch to using internal cc1111 temperature sensor v0.2 has no temperature sensor, and several of the v0.1 boards didn't get a temperature sensor loaded. Use the internal temperature sensor on the cc1111 in all cases instead. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview_state.c | 8 ++++---- ao-tools/lib/cc-convert.c | 11 ++++++++++- src/ao_adc.c | 12 +++++++----- src/ao_convert.c | 10 +++++++++- 4 files changed, 30 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_state.c b/ao-tools/ao-view/aoview_state.c index 838899a7..505bcddc 100644 --- a/ao-tools/ao-view/aoview_state.c +++ b/ao-tools/ao-view/aoview_state.c @@ -127,10 +127,10 @@ aoview_state_derive(struct cc_telem *data, struct aostate *state) accel_counts_per_mss = ((data->accel_minus_g - data->accel_plus_g) / 2.0) / 9.80665; state->acceleration = (data->ground_accel - data->flight_accel) / accel_counts_per_mss; state->speed = data->flight_vel / (accel_counts_per_mss * 100.0); - state->temperature = ((data->temp / 32767.0 * 3.3) - 0.5) / 0.01; - state->drogue_sense = data->drogue / 32767.0 * 15.0; - state->main_sense = data->main / 32767.0 * 15.0; - state->battery = data->batt / 32767.0 * 5.0; + state->temperature = cc_thermometer_to_temperature(data->temp); + state->drogue_sense = cc_ignitor_to_voltage(data->drogue); + state->main_sense = cc_ignitor_to_voltage(data->main); + state->battery = cc_battery_to_voltage(data->batt); if (!strcmp(data->state, "pad")) { if (data->gps.gps_locked && data->gps.nsat >= 4) { state->npad++; diff --git a/ao-tools/lib/cc-convert.c b/ao-tools/lib/cc-convert.c index ac6962ba..8d6876a0 100644 --- a/ao-tools/lib/cc-convert.c +++ b/ao-tools/lib/cc-convert.c @@ -213,10 +213,19 @@ cc_accelerometer_to_acceleration(double accel, double ground_accel) return (ground_accel - accel) / count_per_mss; } +/* 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 + */ + double cc_thermometer_to_temperature(double thermo) { - return ((thermo / 32767 * 3.3) - 0.5) / 0.01; + return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; } double diff --git a/src/ao_adc.c b/src/ao_adc.c index b0bfceb1..2b972e6c 100644 --- a/src/ao_adc.c +++ b/src/ao_adc.c @@ -46,16 +46,18 @@ ao_adc_isr(void) interrupt 1 uint8_t __xdata *a; sequence = (ADCCON2 & ADCCON2_SCH_MASK) >> ADCCON2_SCH_SHIFT; + if (sequence == ADCCON3_ECH_TEMP) + sequence = 2; a = (uint8_t __xdata *) (&ao_adc_ring[ao_adc_head].accel + sequence); a[0] = ADCL; a[1] = ADCH; if (sequence < 5) { /* start next channel conversion */ - sequence++; - /* skip channel 2, we don't have a temp sensor on v0.2 */ - if (sequence == 2) - sequence++; - ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | sequence; + /* v0.2 replaces external temp sensor with internal one */ + if (sequence == 1) + ADCCON3 = ADCCON3_EREF_1_25 | ADCCON3_EDIV_512 | ADCCON3_ECH_TEMP; + else + ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | (sequence + 1); } else { /* record this conversion series */ ao_adc_ring[ao_adc_head].tick = ao_time(); diff --git a/src/ao_convert.c b/src/ao_convert.c index 57ed7370..f29ce9e9 100644 --- a/src/ao_convert.c +++ b/src/ao_convert.c @@ -49,7 +49,15 @@ ao_temp_to_dC(int16_t temp) __reentrant int16_t ret; ao_mutex_get(&ao_temp_mutex); - ret = (int16_t) ((temp >> 4) * 3300L / 2047L) - 500; + /* 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 + * ≃ (value - 19791) * 1012 / 65536 + */ + ret = ((temp - 19791) * 1012L) >> 16; ao_mutex_put(&ao_temp_mutex); return ret; } -- cgit v1.2.3 From f8967607b3dda0c0ce7afe8bb077da2da5ed3dcd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 7 Feb 2010 00:24:56 -0800 Subject: Compute daytime using GPS as time base --- ao-tools/ao-postflight/ao-postflight.c | 114 +++++++++++++++++++++++++++++---- 1 file changed, 103 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index 48752d07..cbf9c047 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -185,6 +185,75 @@ static const char kml_footer[] = "\n" "\n"; +static unsigned +gps_daytime(struct cc_gpselt *gps) +{ + return ((gps->hour * 60 + + gps->minute) * 60 + + gps->second) * 1000; +} + +int +daytime_hour(unsigned daytime) +{ + return daytime / 1000 / 60 / 60; +} + +int +daytime_minute(unsigned daytime) +{ + return (daytime / 1000 / 60) % 60; +} + +int +daytime_second(unsigned daytime) +{ + return (daytime / 1000) % 60; +} + +int +daytime_millisecond(unsigned daytime) +{ + return daytime % 1000; +} + +static unsigned +compute_daytime_ms(double time, struct cc_gpsdata *gps) +{ + int i; + unsigned gps_start_daytime, gps_stop_daytime; + + if (time <= gps->data[0].time) { + gps_stop_daytime = gps_daytime(&gps->data[0]); + return gps_stop_daytime - (gps->data[0].time - time) * 10; + } + for (i = 0; i < gps->num - 1; i++) + if (time > gps->data[i].time) + break; + gps_start_daytime = gps_daytime(&gps->data[i]); + if (i == gps->num - 1) { + return gps_start_daytime + (time - gps->data[i].time) * 10; + } else { + unsigned gps_period_daytime; + double gps_period_time; + double time_since_start; + + gps_stop_daytime = gps_daytime(&gps->data[i + 1]); + + /* range of gps daytime values */ + gps_period_daytime = gps_stop_daytime - gps_start_daytime; + + /* range of gps time values */ + gps_period_time = gps->data[i+1].time - gps->data[i].time; + + /* sample time after first gps time */ + time_since_start = time - gps->data[i].time; + + return gps_start_daytime + + gps_period_daytime * time_since_start / gps_period_time; + } +} + static void analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, FILE *raw_file, char *plot_name, FILE *gps_file, FILE *kml_file) @@ -325,30 +394,49 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, int i; double *times; - fprintf(detail_file, "%9s %9s %9s %9s\n", - "time", "height", "speed", "accel"); + fprintf(detail_file, "%9s %9s %9s %9s %9s\n", + "time", "height", "speed", "accel", "daytime"); for (i = 0; i < cooked->pres_pos.num; i++) { - double time = (cooked->accel_accel.start + i * cooked->accel_accel.step - boost_start) / 100.0; + double clock_time = cooked->accel_accel.start + i * cooked->accel_accel.step; + double time = (clock_time - boost_start) / 100.0; double accel = cooked->accel_accel.data[i]; double pos = cooked->pres_pos.data[i]; double speed; + unsigned daytime; if (cooked->pres_pos.start + cooked->pres_pos.step * i < apogee) speed = cooked->accel_speed.data[i]; else speed = cooked->pres_speed.data[i]; - fprintf(detail_file, "%9.2f %9.2f %9.2f %9.2f\n", - time, pos, speed, accel); + if (f->gps.num) + daytime = compute_daytime_ms(clock_time, &f->gps); + else + daytime = 0; + fprintf(detail_file, "%9.2f %9.2f %9.2f %9.2f %02d:%02d:%02d.%03d\n", + time, pos, speed, accel, + daytime_hour(daytime), + daytime_minute(daytime), + daytime_second(daytime), + daytime_millisecond(daytime)); } } if (raw_file) { - fprintf(raw_file, "%9s %9s %9s\n", - "time", "height", "accel"); + fprintf(raw_file, "%9s %9s %9s %9s\n", + "time", "height", "accel", "daytime"); for (i = 0; i < cooked->pres.num; i++) { double time = cooked->pres.data[i].time; double pres = cooked->pres.data[i].value; double accel = cooked->accel.data[i].value; - fprintf(raw_file, "%9.2f %9.2f %9.2f %9.2f\n", - time, pres, accel); + unsigned daytime; + if (f->gps.num) + daytime = compute_daytime_ms(time, &f->gps); + else + daytime = 0; + fprintf(raw_file, "%9.2f %9.2f %9.2f %9.2f %02d:%02d:%02d.%03d\n", + time, pres, accel, + daytime_hour(daytime), + daytime_minute(daytime), + daytime_second(daytime), + daytime_millisecond(daytime)); } } if (gps_file || kml_file) { @@ -357,7 +445,8 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, double baro = 0.0; if (gps_file) - fprintf(gps_file, "%9s %12s %12s %9s %8s %5s\n", + fprintf(gps_file, "%2s %2s %2s %9s %12s %12s %9s %8s %5s\n", + "hr", "mn", "sc", "time", "lat", "lon", "alt", "baro", "nsat"); if (kml_file) fprintf(kml_file, "%s", kml_header); @@ -386,7 +475,10 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, baro = cooked->pres_pos.data[baro_pos]; } if (gps_file) - fprintf(gps_file, "%12.7f %12.7f %12.7f %7.1f %7.1f", + fprintf(gps_file, "%2d %2d %2d %12.7f %12.7f %12.7f %7.1f %7.1f", + f->gps.data[i].hour, + f->gps.data[i].minute, + f->gps.data[i].second, (f->gps.data[i].time - boost_start) / 100.0, f->gps.data[i].lat, f->gps.data[i].lon, -- cgit v1.2.3 From c83615567b4567f3dc45a7f7b894943b45fbb65c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 7 Feb 2010 00:25:22 -0800 Subject: Pull in a bit more data for filtering the start of the boost --- ao-tools/lib/cc-process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/lib/cc-process.c b/ao-tools/lib/cc-process.c index 5c1acc6b..c756b570 100644 --- a/ao-tools/lib/cc-process.c +++ b/ao-tools/lib/cc-process.c @@ -70,7 +70,7 @@ cc_flight_cook(struct cc_flightraw *raw) */ for (i = 0; i < raw->state.num; i++) { if (!start_set && raw->state.data[i].value > ao_flight_pad) { - flight_start = raw->state.data[i].time; + flight_start = raw->state.data[i].time - 10; start_set = 1; } if (!stop_set && raw->state.data[i].value > ao_flight_main) { @@ -79,7 +79,7 @@ cc_flight_cook(struct cc_flightraw *raw) } } - if (!start_set) + if (!start_set || flight_start < raw->accel.data[0].time) flight_start = raw->accel.data[0].time; if (stop_set) { for (i = 0; i < raw->accel.num - 1; i++) { @@ -101,8 +101,8 @@ cc_flight_cook(struct cc_flightraw *raw) accel_speed = cc_timedata_integrate(&cooked->accel, flight_start - 10, flight_stop); accel_pos = cc_timedata_integrate(accel_speed, flight_start - 10, flight_stop); -#define ACCEL_OMEGA_PASS (2 * M_PI * 5 / 100) -#define ACCEL_OMEGA_STOP (2 * M_PI * 8 / 100) +#define ACCEL_OMEGA_PASS (2 * M_PI * 20 / 100) +#define ACCEL_OMEGA_STOP (2 * M_PI * 30 / 100) #define BARO_OMEGA_PASS (2 * M_PI * .5 / 100) #define BARO_OMEGA_STOP (2 * M_PI * 1 / 100) #define FILTER_ERROR (1e-8) -- cgit v1.2.3 From 1e60deca147c85a064719dfad14ccabd1049bbbd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 25 Feb 2010 16:33:34 -0800 Subject: Allow product names to have suffixes (like board revisions) When looking for a board by product name, just look at the prefix of the name instead of requiring an exact match. This will allow products to have board version suffixes. Signed-off-by: Keith Packard --- ao-tools/lib/cc-usbdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/lib/cc-usbdev.c b/ao-tools/lib/cc-usbdev.c index ed39c062..afa91d49 100644 --- a/ao-tools/lib/cc-usbdev.c +++ b/ao-tools/lib/cc-usbdev.c @@ -258,7 +258,7 @@ match_dev(char *product, int serial) return NULL; for (i = 0; i < devs->ndev; i++) { dev = devs->dev[i]; - if (product && strcmp (product, dev->product) != 0) + if (product && strncmp (product, dev->product, strlen(product)) != 0) continue; if (serial && serial != dev->serial) continue; -- cgit v1.2.3 From 5d7a3a5fbc0af4621c67a6fd51a9c9d5ae688fa5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 25 Feb 2010 16:40:13 -0800 Subject: Fix and document the ao-rawload --run flag This allows ram-based programs to be loaded and executed easily. Signed-off-by: Keith Packard --- ao-tools/ao-rawload/ao-rawload.1 | 9 +++++++-- ao-tools/ao-rawload/ao-rawload.c | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-rawload/ao-rawload.1 b/ao-tools/ao-rawload/ao-rawload.1 index 6b6a6e2c..30d0467d 100644 --- a/ao-tools/ao-rawload/ao-rawload.1 +++ b/ao-tools/ao-rawload/ao-rawload.1 @@ -29,7 +29,7 @@ ao-rawload \- flash a program to a AltOS device .SH DESCRIPTION .I ao-rawload loads the specified .ihx file, without modification, into the target -device flash memory. +device flash or ram (depending on the base address of the .ihx file). .SH OPTIONS .TP \-T tty-device | --tty tty-device @@ -51,10 +51,15 @@ TeleMetrum 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. +.TP +\-r | --run +After the file has been loaded, set the PC to the base address of the +image and resume execution there. +the .ihx file. .SH USAGE .I ao-rawload reads the specified .ihx file into memory. It then connects to the specified target device and writes the program to the target device -flash memory. +memory and, optionally, starts the program executing. .SH AUTHOR Keith Packard diff --git a/ao-tools/ao-rawload/ao-rawload.c b/ao-tools/ao-rawload/ao-rawload.c index 0098b658..a4746b19 100644 --- a/ao-tools/ao-rawload/ao-rawload.c +++ b/ao-tools/ao-rawload/ao-rawload.c @@ -49,7 +49,7 @@ main (int argc, char **argv) int c; int run = 0; - while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "rT:D:", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; @@ -67,7 +67,7 @@ main (int argc, char **argv) } filename = argv[optind]; if (filename == NULL) { - fprintf(stderr, "usage: %s \n", argv[0]); + usage(argv[0]); exit(1); } file = fopen(filename, "r"); -- cgit v1.2.3 From 6e61170d42936c18cd6efba6f4c14af616a30745 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 28 Feb 2010 18:24:46 -0800 Subject: Need to duplicate new altitude conversion code in aoview. Altitude conversion is now done with a smaller table and interpolation instead of a giant table. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview_convert.c | 44 ++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_convert.c b/ao-tools/ao-view/aoview_convert.c index 02416647..8ee05e1d 100644 --- a/ao-tools/ao-view/aoview_convert.c +++ b/ao-tools/ao-view/aoview_convert.c @@ -17,26 +17,50 @@ #include "aoview.h" -static int16_t altitude_table[2048] = { +static int16_t altitude_table[] = { #include "altitude.h" }; +#define ALT_FRAC_SCALE (1 << ALT_FRAC_BITS) +#define ALT_FRAC_MASK (ALT_FRAC_SCALE - 1) + int16_t aoview_pres_to_altitude(int16_t pres) { - pres = pres >> 4; - if (pres < 0) pres = 0; - if (pres > 2047) pres = 2047; - return altitude_table[pres]; + uint8_t o; + int16_t part; + + if (pres < 0) + pres = 0; + o = pres >> ALT_FRAC_BITS; + part = pres & ALT_FRAC_MASK; + + return ((int32_t) altitude_table[o] * (ALT_FRAC_SCALE - part) + + (int32_t) altitude_table[o+1] * part + (ALT_FRAC_SCALE >> 1)) >> ALT_FRAC_BITS; } int16_t aoview_altitude_to_pres(int16_t alt) { - int16_t pres; + int16_t span, sub_span; + uint8_t l, h, m; + int32_t pres; - for (pres = 0; pres < 2047; pres++) - if (altitude_table[pres] <= alt) - break; - return pres << 4; + l = 0; + h = NALT - 1; + while ((h - l) != 1) { + m = (l + h) >> 1; + if (altitude_table[m] < alt) + h = m; + else + l = m; + } + span = altitude_table[l] - altitude_table[h]; + sub_span = altitude_table[l] - alt; + pres = ((((int32_t) l * (span - sub_span) + (int32_t) h * sub_span) << ALT_FRAC_BITS) + (span >> 1)) / span; + if (pres > 32767) + pres = 32767; + if (pres < 0) + pres = 0; + return (int16_t) pres; } -- cgit v1.2.3 From 23da4f3bcdd1d780c9e1f6b68ad2fb309fcae6ba Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 12 Mar 2010 10:37:32 -0800 Subject: Document the ao-dumplog '--remote' flag for radio-link downloads The --remote (or -R) flag uses TeleDongle to fetch data over the radio command link from TeleMetrum. It's been there for a while, but the man page failed to mention it. Signed-off-by: Keith Packard --- ao-tools/ao-dumplog/ao-dumplog.1 | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/ao-dumplog/ao-dumplog.1 b/ao-tools/ao-dumplog/ao-dumplog.1 index 8c2df7c6..d381e335 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.1 +++ b/ao-tools/ao-dumplog/ao-dumplog.1 @@ -25,6 +25,8 @@ ao-dumplog \- Store flight log from TeleMetrum device [\--tty \fItty-device\fP] [\-D \fIaltos-device\fP] [\--device \fIaltos-device\fP] +[\--R\fP] +[\--remote\fP] .SH OPTIONS .TP \-T tty-device | --tty tty-device @@ -44,6 +46,10 @@ TeleMetrum 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. +.TP +\-R | --remote +This uses the command radio link to download the log from TeleMetrum +through a TeleDongle. .SH DESCRIPTION .I ao-dumplog downloads the flight log from a connected TeleMetrum device and stores -- cgit v1.2.3 From 7f233369e32c3254165ee251df0a3dbc21ea5a29 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 31 Mar 2010 13:49:54 -0700 Subject: Start adding java-based UI --- ao-tools/altosui/AltosSerial.java | 149 ++++++++++++++++++++++ ao-tools/altosui/AltosSerialMonitor.java | 22 ++++ ao-tools/altosui/AltosUI.java | 209 +++++++++++++++++++++++++++++++ ao-tools/altosui/Makefile | 13 ++ 4 files changed, 393 insertions(+) create mode 100644 ao-tools/altosui/AltosSerial.java create mode 100644 ao-tools/altosui/AltosSerialMonitor.java create mode 100644 ao-tools/altosui/AltosUI.java create mode 100644 ao-tools/altosui/Makefile (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java new file mode 100644 index 00000000..82663eab --- /dev/null +++ b/ao-tools/altosui/AltosSerial.java @@ -0,0 +1,149 @@ +/* + * Copyright © 2010 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. + */ + +/* + * Deal with TeleDongle on a serial port + */ + +package altosui; + +import java.lang.String; +import java.lang.System; +import java.lang.Character; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.util.concurrent.LinkedBlockingQueue; +import java.lang.InterruptedException; +import java.util.LinkedList; +import altosui.AltosSerialMonitor; +import java.util.Iterator; + +/* + * This class reads from the serial port and places each received + * line in a queue. Dealing with that queue is left up to other + * threads. + */ +class AltosSerialReader implements Runnable { + FileInputStream serial_in; + LinkedBlockingQueue monitor_queue; + LinkedBlockingQueue reply_queue; + String line; + + public void run () { + int c; + + try { + while ((c = serial_in.read()) != -1) { + if (c == '\r') + continue; + synchronized(this) { + if (c == '\n') { + if (line != "") { + if (line.startsWith("VERSION")) + monitor_queue.put(line); + else + reply_queue.put(line); + line = ""; + } + } else { + line = line + (char) c; + } + } + } + } catch (IOException e) { + } catch (InterruptedException e) { + } + } + + public String get_telem() { + try { + return monitor_queue.take(); + } catch (InterruptedException e) { + return ""; + } + } + + public String get_reply() { + try { + return reply_queue.take(); + } catch (InterruptedException e) { + return ""; + } + } + + public void flush () { + synchronized(this) { + if (!"VERSION".startsWith(line) && !line.startsWith("VERSION")) + line = ""; + reply_queue.clear(); + } + } + public AltosSerialReader (FileInputStream in) { + serial_in = in; + monitor_queue = new LinkedBlockingQueue (); + reply_queue = new LinkedBlockingQueue (); + line = ""; + } + +} + +public class AltosSerial implements Runnable { + FileInputStream serial_in = null; + FileOutputStream serial_out = null; + AltosSerialReader reader; + LinkedList callbacks; + + public void run() { + for (;;) { + String s = reader.get_reply(); + synchronized(callbacks) { + Iterator i = callbacks.iterator(); + while (i.hasNext()) { + i.next().data(s); + } + } + } + } + + public void start () { + try { + serial_out.write('?'); + serial_out.write('\r'); + } catch (IOException e) { + } + (new Thread(reader)).start(); + (new Thread(this)).start(); + } + + public void monitor(AltosSerialMonitor monitor) { + synchronized(callbacks) { + callbacks.add(monitor); + } + } + + public AltosSerial(String serial_name) { + try { + serial_in = new FileInputStream(serial_name); + serial_out = new FileOutputStream(serial_name); + reader = new AltosSerialReader(serial_in); + callbacks = new LinkedList(); + } catch (FileNotFoundException e) { + } + } +} diff --git a/ao-tools/altosui/AltosSerialMonitor.java b/ao-tools/altosui/AltosSerialMonitor.java new file mode 100644 index 00000000..ad0e9295 --- /dev/null +++ b/ao-tools/altosui/AltosSerialMonitor.java @@ -0,0 +1,22 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +public interface AltosSerialMonitor { + void data(String data); +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java new file mode 100644 index 00000000..b731725c --- /dev/null +++ b/ao-tools/altosui/AltosUI.java @@ -0,0 +1,209 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JSplitPane; +import javax.swing.JTable; +import javax.swing.KeyStroke; +import javax.swing.table.TableCellEditor; +import javax.swing.table.DefaultTableCellRenderer; +import altosui.AltosSerial; +import altosui.AltosSerialMonitor; + +class AltosUIMonitor implements AltosSerialMonitor { + public void data(String data) { + System.out.println(data); + } +} + +public class AltosUI extends JFrame { + private int channel = -1; + + private JTable flightStatus; + private JTable flightInfo; + private AltosSerial serialLine; + + public AltosUI() { + + String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; + Object[][] statusData = { { "0", "pad", "-50", "0" } }; + + flightStatus = new JTable(statusData, statusNames); + + flightStatus.setShowGrid(false); + + this.add(flightStatus); + + setTitle("AltOS"); + + createMenu(); + + serialLine = new AltosSerial("/dev/ttyACM0"); + serialLine.monitor(new AltosUIMonitor()); + serialLine.start(); + Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); + size.width = size.width*9/10; + size.height = size.height*9/10; + this.setSize(size); + this.validate(); + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + } + + private void createMenu() { + JMenuBar menubar = new JMenuBar(); + JMenu menu; + JMenuItem item; + JRadioButtonMenuItem radioitem; + + // File menu + { + menu = new JMenu("File"); + menu.setMnemonic(KeyEvent.VK_F); + menubar.add(menu); + + item = new JMenuItem("Quit",KeyEvent.VK_Q); + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, + ActionEvent.CTRL_MASK)); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + menu.add(item); + } + + // Device menu + { + menu = new JMenu("Device"); + menu.setMnemonic(KeyEvent.VK_D); + menubar.add(menu); + + item = new JMenuItem("Connect to Device",KeyEvent.VK_C); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); + menu.add(item); + + item = new JMenuItem("Disconnect from Device",KeyEvent.VK_D); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); + menu.add(item); + + menu.addSeparator(); + + item = new JMenuItem("Save Flight Data",KeyEvent.VK_S); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); + menu.add(item); + + item = new JMenuItem("Replay",KeyEvent.VK_R); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); + menu.add(item); + } + // Log menu + { + menu = new JMenu("Log"); + menu.setMnemonic(KeyEvent.VK_L); + menubar.add(menu); + + item = new JMenuItem("New Log",KeyEvent.VK_N); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); + menu.add(item); + + item = new JMenuItem("Configure Log",KeyEvent.VK_C); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); + menu.add(item); + } + // Voice menu + { + menu = new JMenu("Voice", true); + menu.setMnemonic(KeyEvent.VK_V); + menubar.add(menu); + + radioitem = new JRadioButtonMenuItem("Enable Voice"); + radioitem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); + menu.add(radioitem); + } + + // Channel menu + { + menu = new JMenu("Channel", true); + menu.setMnemonic(KeyEvent.VK_C); + menubar.add(menu); + + for (int c = 0; c <= 9; c++) { + radioitem = new JRadioButtonMenuItem("Channel " + c + " (" + + (434.550 + c * .1) + ")", + c == 0); + radioitem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); + menu.add(radioitem); + } + } + + this.setJMenuBar(menubar); + + } + public static void main(final String[] args) { + AltosUI altosui = new AltosUI(); + altosui.setVisible(true); + } +} \ No newline at end of file diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile new file mode 100644 index 00000000..cb422df8 --- /dev/null +++ b/ao-tools/altosui/Makefile @@ -0,0 +1,13 @@ +.SUFFIXES: .java .class + +CLASSPATH=.. +CLASSFILES=AltosSerialMonitor.class AltosSerial.class AltosUI.class +JAVAFLAGS=-Xlint:unchecked + +all: $(CLASSFILES) + +.java.class: + javac -cp $(CLASSPATH) $(JAVAFLAGS) $*.java + +clean: + rm -f *.class \ No newline at end of file -- cgit v1.2.3 From a06bee96e648d9ded8776f3d6cba9505e7be1a60 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 31 Mar 2010 23:05:03 -0700 Subject: Add telemetry data parsing code --- ao-tools/altosui/.gitignore | 2 + ao-tools/altosui/AltosTelemetry.java | 287 +++++++++++++++++++++++++++++++++++ 2 files changed, 289 insertions(+) create mode 100644 ao-tools/altosui/.gitignore create mode 100644 ao-tools/altosui/AltosTelemetry.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/.gitignore b/ao-tools/altosui/.gitignore new file mode 100644 index 00000000..59913193 --- /dev/null +++ b/ao-tools/altosui/.gitignore @@ -0,0 +1,2 @@ +*.class +altosui diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java new file mode 100644 index 00000000..e072bb34 --- /dev/null +++ b/ao-tools/altosui/AltosTelemetry.java @@ -0,0 +1,287 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; + +/* + * Telemetry data contents + */ + +class AltosGPSTime { + int year; + int month; + int day; + int hour; + int minute; + int second; + + int parse_int(String v) throws ParseException { + try { + return Integer.parseInt(v); + } catch (NumberFormatException e) { + throw new ParseException(v, 0); + } + } + + public AltosGPSTime(String date, String time) throws ParseException { + String[] ymd = date.split("-"); + if (ymd.length != 3) { + System.out.println("Error parsing GPS date " + date + " got " + ymd.length); + throw new ParseException(date, 0); + } + year = parse_int(ymd[0]); + month = parse_int(ymd[1]); + day = parse_int(ymd[2]); + + String[] hms = time.split(":"); + if (hms.length != 3) { + System.out.println("Error parsing GPS time " + time + " got " + hms.length); + throw new ParseException(time, 0); + } + hour = parse_int(hms[0]); + minute = parse_int(hms[1]); + second = parse_int(hms[2]); + } + + public AltosGPSTime() { + year = month = day = 0; + hour = minute = second = 0; + } +}; + +class AltosGPS { + int nsat; + int gps_locked; + int gps_connected; + AltosGPSTime gps_time; + double lat; /* degrees (+N -S) */ + double lon; /* degrees (+E -W) */ + int alt; /* m */ + + int gps_extended; /* has extra data */ + double ground_speed; /* m/s */ + int course; /* degrees */ + double climb_rate; /* m/s */ + double hdop; /* unitless? */ + int h_error; /* m */ + int v_error; /* m */ + +} + +class AltosGPSSat { + int svid; + int c_n0; +} + +class AltosGPSTracking { + int channels; + AltosGPSSat[] cc_gps_sat; +} + +public class AltosTelemetry { + int version; + String callsign; + int serial; + int flight; + int rssi; + int status; + String state; + int tick; + int accel; + int pres; + int temp; + int batt; + int drogue; + int main; + int flight_accel; + int ground_accel; + int flight_vel; + int flight_pres; + int ground_pres; + int accel_plus_g; + int accel_minus_g; + AltosGPS gps; + AltosGPSTracking gps_tracking; + + int parse_int(String v) throws ParseException { + try { + return Integer.parseInt(v); + } catch (NumberFormatException e) { + System.out.println("error parsing int " + v); + throw new ParseException(v, 0); + } + } + + int parse_hex(String v) throws ParseException { + try { + return Integer.parseInt(v, 16); + } catch (NumberFormatException e) { + System.out.println("error parsing hex " + v); + throw new ParseException(v, 0); + } + } + + double parse_double(String v) throws ParseException { + try { + return Double.parseDouble(v); + } catch (NumberFormatException e) { + System.out.println("error parsing double " + v); + throw new ParseException(v, 0); + } + } + + double parse_coord(String coord) throws ParseException { + String[] dsf = coord.split("\\D+"); + + if (dsf.length != 3) { + System.out.println("error parsing coord " + coord); + throw new ParseException(coord, 0); + } + int deg = parse_int(dsf[0]); + int min = parse_int(dsf[1]); + int frac = parse_int(dsf[2]); + + double r = deg + (min + frac / 10000.0) / 60.0; + if (coord.endsWith("S") || coord.endsWith("W")) + r = -r; + return r; + } + + String strip_suffix(String v, String suffix) { + if (v.endsWith(suffix)) + return v.substring(0, v.length() - suffix.length()); + return v; + } + + void word(String v, String m) throws ParseException { + if (!v.equals(m)) { + System.out.println("error matching '" + v + "' '" + m + "'"); + throw new ParseException(v, 0); + } + } + + public AltosTelemetry(String line) throws ParseException { + String[] words = line.split("\\s+"); + + int i = 0; + + word (words[i++], "VERSION"); + version = parse_int(words[i++]); + + word (words[i++], "CALL"); + callsign = words[i++]; + + word (words[i++], "SERIAL"); + serial = parse_int(words[i++]); + + word (words[i++], "FLIGHT"); + flight = parse_int(words[i++]); + + word(words[i++], "RSSI"); + rssi = parse_int(words[i++]); + + word(words[i++], "STATUS"); + status = parse_hex(words[i++]); + + word(words[i++], "STATE"); + state = words[i++]; + + tick = parse_int(words[i++]); + + word(words[i++], "a:"); + accel = parse_int(words[i++]); + + word(words[i++], "p:"); + pres = parse_int(words[i++]); + + word(words[i++], "t:"); + temp = parse_int(words[i++]); + + word(words[i++], "v:"); + batt = parse_int(words[i++]); + + word(words[i++], "d:"); + drogue = parse_int(words[i++]); + + word(words[i++], "m:"); + main = parse_int(words[i++]); + + word(words[i++], "fa:"); + flight_accel = parse_int(words[i++]); + + word(words[i++], "ga:"); + ground_accel = parse_int(words[i++]); + + word(words[i++], "fv:"); + flight_vel = parse_int(words[i++]); + + word(words[i++], "fp:"); + flight_pres = parse_int(words[i++]); + + word(words[i++], "gp:"); + ground_pres = parse_int(words[i++]); + + word(words[i++], "a+:"); + accel_plus_g = parse_int(words[i++]); + + word(words[i++], "a-:"); + accel_minus_g = parse_int(words[i++]); + + word(words[i++], "GPS"); + gps = new AltosGPS(); + gps.nsat = parse_int(words[i++]); + word(words[i++], "sat"); + + gps.gps_connected = 0; + gps.gps_locked = 0; + gps.lat = gps.lon = 0; + gps.alt = 0; + if ((words[i]).equals("unlocked")) { + gps.gps_connected = 1; + gps.gps_time = new AltosGPSTime(); + i++; + } else if (words.length >= 40) { + gps.gps_locked = 1; + gps.gps_connected = 1; + + gps.gps_time = new AltosGPSTime(words[i], words[i+1]); i += 2; + gps.lat = parse_coord(words[i++]); + gps.lon = parse_coord(words[i++]); + gps.alt = parse_int(strip_suffix(words[i++], "m")); + gps.ground_speed = parse_double(strip_suffix(words[i++], "m/s(H)")); + gps.course = parse_int(strip_suffix(words[i++], "°")); + gps.climb_rate = parse_double(strip_suffix(words[i++], "m/s(V)")); + gps.hdop = parse_double(strip_suffix(words[i++], "(hdop)")); + gps.h_error = parse_int(strip_suffix(words[i++], "(herr)")); + gps.v_error = parse_int(strip_suffix(words[i++], "(verr)")); + } else { + gps.gps_time = new AltosGPSTime(); + } + word(words[i++], "SAT"); + gps_tracking = new AltosGPSTracking(); + gps_tracking.channels = parse_int(words[i++]); + gps_tracking.cc_gps_sat = new AltosGPSSat[gps_tracking.channels]; + for (int chan = 0; chan < gps_tracking.channels; chan++) { + gps_tracking.cc_gps_sat[chan] = new AltosGPSSat(); + gps_tracking.cc_gps_sat[chan].svid = parse_int(words[i++]); + gps_tracking.cc_gps_sat[chan].c_n0 = parse_int(words[i++]); + } + } +} -- cgit v1.2.3 From 02f2be90879b682b6e648cf2debc83223d127b9d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 13:37:52 -0700 Subject: Add telem parsing code --- ao-tools/altosui/AltosSerial.java | 152 ++++++++++++++++++++++++----------- ao-tools/altosui/AltosTelemetry.java | 52 +++++++----- ao-tools/altosui/AltosUI.java | 143 ++++++++++++++++++++++++-------- ao-tools/altosui/Makefile | 13 ++- 4 files changed, 260 insertions(+), 100 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 82663eab..9537f190 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -21,18 +21,12 @@ package altosui; -import java.lang.String; -import java.lang.System; -import java.lang.Character; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.FileNotFoundException; +import java.lang.*; +import java.io.*; import java.util.concurrent.LinkedBlockingQueue; -import java.lang.InterruptedException; import java.util.LinkedList; -import altosui.AltosSerialMonitor; import java.util.Iterator; +import altosui.AltosSerialMonitor; /* * This class reads from the serial port and places each received @@ -43,6 +37,7 @@ class AltosSerialReader implements Runnable { FileInputStream serial_in; LinkedBlockingQueue monitor_queue; LinkedBlockingQueue reply_queue; + Thread input_thread; String line; public void run () { @@ -71,20 +66,12 @@ class AltosSerialReader implements Runnable { } } - public String get_telem() { - try { - return monitor_queue.take(); - } catch (InterruptedException e) { - return ""; - } + public String get_telem() throws InterruptedException { + return monitor_queue.take(); } - public String get_reply() { - try { - return reply_queue.take(); - } catch (InterruptedException e) { - return ""; - } + public String get_reply() throws InterruptedException { + return reply_queue.take(); } public void flush () { @@ -94,56 +81,131 @@ class AltosSerialReader implements Runnable { reply_queue.clear(); } } - public AltosSerialReader (FileInputStream in) { - serial_in = in; + + public boolean opened() { + return serial_in != null; + } + + public void close() { + if (serial_in != null) { + try { + serial_in.close(); + } catch (IOException e) { + } + serial_in = null; + } + if (input_thread != null) { + try { + input_thread.join(); + } catch (InterruptedException e) { + } + input_thread = null; + } + } + + public void open(File name) throws FileNotFoundException { + close(); + serial_in = new FileInputStream(name); + input_thread = new Thread(this); + input_thread.start(); + } + public AltosSerialReader () { + serial_in = null; + input_thread = null; + line = ""; monitor_queue = new LinkedBlockingQueue (); reply_queue = new LinkedBlockingQueue (); - line = ""; } } public class AltosSerial implements Runnable { - FileInputStream serial_in = null; FileOutputStream serial_out = null; - AltosSerialReader reader; + Thread monitor_thread = null; + AltosSerialReader reader = null; LinkedList callbacks; public void run() { - for (;;) { - String s = reader.get_reply(); - synchronized(callbacks) { - Iterator i = callbacks.iterator(); - while (i.hasNext()) { - i.next().data(s); + try { + for (;;) { + String s = reader.get_telem(); + synchronized(callbacks) { + Iterator i = callbacks.iterator(); + while (i.hasNext()) { + i.next().data(s); + } } } + } catch (InterruptedException e) { } } - public void start () { - try { - serial_out.write('?'); - serial_out.write('\r'); - } catch (IOException e) { + boolean need_monitor() { + return reader.opened() && !callbacks.isEmpty(); + } + + void maybe_stop_monitor() { + if (!need_monitor() && monitor_thread != null) { + monitor_thread.interrupt(); + try { + monitor_thread.join(); + } catch (InterruptedException e) { + } finally { + monitor_thread = null; + } + } + } + + void maybe_start_monitor() { + if (need_monitor() && monitor_thread == null) { + monitor_thread = new Thread(this); + monitor_thread.start(); } - (new Thread(reader)).start(); - (new Thread(this)).start(); } public void monitor(AltosSerialMonitor monitor) { synchronized(callbacks) { callbacks.add(monitor); + maybe_start_monitor(); } } - public AltosSerial(String serial_name) { + + public void unmonitor(AltosSerialMonitor monitor) { + synchronized(callbacks) { + callbacks.remove(monitor); + maybe_stop_monitor(); + } + } + + public void close() { + synchronized(callbacks) { + reader.close(); + maybe_stop_monitor(); + } + } + + public void open(File serial_name) throws FileNotFoundException { + reader.open(serial_name); + serial_out = new FileOutputStream(serial_name); try { - serial_in = new FileInputStream(serial_name); - serial_out = new FileOutputStream(serial_name); - reader = new AltosSerialReader(serial_in); - callbacks = new LinkedList(); - } catch (FileNotFoundException e) { + serial_out.write('?'); + serial_out.write('\r'); + } catch (IOException e) { } } + + void init() { + reader = new AltosSerialReader(); + callbacks = new LinkedList(); + } + + public AltosSerial() { + init(); + } + + public AltosSerial(File serial_name) throws FileNotFoundException { + init(); + open(serial_name); + } } diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index e072bb34..99e82bbf 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -36,25 +36,21 @@ class AltosGPSTime { try { return Integer.parseInt(v); } catch (NumberFormatException e) { - throw new ParseException(v, 0); + throw new ParseException("error parsing GPS value " + v, 0); } } public AltosGPSTime(String date, String time) throws ParseException { String[] ymd = date.split("-"); - if (ymd.length != 3) { - System.out.println("Error parsing GPS date " + date + " got " + ymd.length); - throw new ParseException(date, 0); - } + if (ymd.length != 3) + throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); year = parse_int(ymd[0]); month = parse_int(ymd[1]); day = parse_int(ymd[2]); String[] hms = time.split(":"); - if (hms.length != 3) { - System.out.println("Error parsing GPS time " + time + " got " + hms.length); - throw new ParseException(time, 0); - } + if (hms.length != 3) + throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); hour = parse_int(hms[0]); minute = parse_int(hms[1]); second = parse_int(hms[2]); @@ -95,6 +91,29 @@ class AltosGPSTracking { AltosGPSSat[] cc_gps_sat; } +/* + * The telemetry data stream is a bit of a mess at present, 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 AltosTelemetry { int version; String callsign; @@ -124,8 +143,7 @@ public class AltosTelemetry { try { return Integer.parseInt(v); } catch (NumberFormatException e) { - System.out.println("error parsing int " + v); - throw new ParseException(v, 0); + throw new ParseException("error parsing int " + v, 0); } } @@ -133,8 +151,7 @@ public class AltosTelemetry { try { return Integer.parseInt(v, 16); } catch (NumberFormatException e) { - System.out.println("error parsing hex " + v); - throw new ParseException(v, 0); + throw new ParseException("error parsing hex " + v, 0); } } @@ -142,8 +159,7 @@ public class AltosTelemetry { try { return Double.parseDouble(v); } catch (NumberFormatException e) { - System.out.println("error parsing double " + v); - throw new ParseException(v, 0); + throw new ParseException("error parsing double " + v, 0); } } @@ -151,8 +167,7 @@ public class AltosTelemetry { String[] dsf = coord.split("\\D+"); if (dsf.length != 3) { - System.out.println("error parsing coord " + coord); - throw new ParseException(coord, 0); + throw new ParseException("error parsing coord " + coord, 0); } int deg = parse_int(dsf[0]); int min = parse_int(dsf[1]); @@ -172,8 +187,7 @@ public class AltosTelemetry { void word(String v, String m) throws ParseException { if (!v.equals(m)) { - System.out.println("error matching '" + v + "' '" + m + "'"); - throw new ParseException(v, 0); + throw new ParseException("error matching '" + v + "' '" + m + "'", 0); } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index b731725c..89eaac15 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -17,29 +17,14 @@ package altosui; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Toolkit; -import java.awt.Window; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JSplitPane; -import javax.swing.JTable; -import javax.swing.KeyStroke; -import javax.swing.table.TableCellEditor; -import javax.swing.table.DefaultTableCellRenderer; +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.io.*; +import java.util.*; +import java.text.*; +import gnu.io.CommPortIdentifier; + import altosui.AltosSerial; import altosui.AltosSerialMonitor; @@ -71,13 +56,10 @@ public class AltosUI extends JFrame { createMenu(); - serialLine = new AltosSerial("/dev/ttyACM0"); + serialLine = new AltosSerial(); serialLine.monitor(new AltosUIMonitor()); - serialLine.start(); - Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); - size.width = size.width*9/10; - size.height = size.height*9/10; - this.setSize(size); + int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); + this.setSize(new Dimension (dpi * 5, dpi * 4)); this.validate(); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @@ -88,6 +70,94 @@ public class AltosUI extends JFrame { }); } + final JFileChooser deviceChooser = new JFileChooser(); + + private void PickSerialDevice() { + java.util.Enumeration port_list = CommPortIdentifier.getPortIdentifiers(); + while (port_list.hasMoreElements()) { + CommPortIdentifier identifier = port_list.nextElement(); + System.out.println("Serial port " + identifier.getName()); + } + } + + private void ConnectToDevice() { + PickSerialDevice(); + int returnVal = deviceChooser.showOpenDialog(AltosUI.this); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = deviceChooser.getSelectedFile(); + try { + serialLine.open(file); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + file.getName(), + "Cannot open serial port", + JOptionPane.ERROR_MESSAGE); + } + } + } + + String readline(FileInputStream s) throws IOException { + int c; + String line = ""; + + while ((c = s.read()) != -1) { + if (c == '\r') + continue; + if (c == '\n') + return line; + line = line + (char) c; + } + return null; + } + + private void Replay() { +// int returnVal = deviceChooser.showOpenDialog(AltosUI.this); + + /* if (returnVal == JFileChooser.APPROVE_OPTION) */ { +// File file = deviceChooser.getSelectedFile(); +// String filename = file.getName(); + String filename = "/home/keithp/src/cc1111/flights/2010-02-13-serial-051-flight-002.telem"; + try { +// FileInputStream replay = new FileInputStream(file); + FileInputStream replay = new FileInputStream(filename); + String line; + + try { + while ((line = readline(replay)) != null) { + try { + AltosTelemetry t = new AltosTelemetry(line); + System.out.println ("Version " + t.version + t.callsign); + } catch (ParseException pp) { + JOptionPane.showMessageDialog(AltosUI.this, + line, + "error parsing", + JOptionPane.ERROR_MESSAGE); + break; + } + } + } catch (IOException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + filename, + "error reading", + JOptionPane.ERROR_MESSAGE); + } finally { + try { + replay.close(); + } catch (IOException e) {} + } + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + filename, + "Cannot open serial port", + JOptionPane.ERROR_MESSAGE); + } + } + } + + private void SaveFlightData() { + } + private void createMenu() { JMenuBar menubar = new JMenuBar(); JMenu menu; @@ -120,6 +190,7 @@ public class AltosUI extends JFrame { item = new JMenuItem("Connect to Device",KeyEvent.VK_C); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + ConnectToDevice(); } }); menu.add(item); @@ -127,6 +198,7 @@ public class AltosUI extends JFrame { item = new JMenuItem("Disconnect from Device",KeyEvent.VK_D); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + serialLine.close(); } }); menu.add(item); @@ -136,6 +208,7 @@ public class AltosUI extends JFrame { item = new JMenuItem("Save Flight Data",KeyEvent.VK_S); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + SaveFlightData(); } }); menu.add(item); @@ -143,6 +216,7 @@ public class AltosUI extends JFrame { item = new JMenuItem("Replay",KeyEvent.VK_R); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + Replay(); } }); menu.add(item); @@ -186,16 +260,21 @@ public class AltosUI extends JFrame { menu = new JMenu("Channel", true); menu.setMnemonic(KeyEvent.VK_C); menubar.add(menu); + ButtonGroup group = new ButtonGroup(); for (int c = 0; c <= 9; c++) { - radioitem = new JRadioButtonMenuItem("Channel " + c + " (" + - (434.550 + c * .1) + ")", - c == 0); + radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c, + 434.550 + c * 0.1), + c == 0); + radioitem.setActionCommand(String.format("%d", c)); radioitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + System.out.println("Command: " + e.getActionCommand() + " param: " + + e.paramString()); } }); menu.add(radioitem); + group.add(radioitem); } } diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index cb422df8..090911ef 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -1,13 +1,18 @@ .SUFFIXES: .java .class -CLASSPATH=.. -CLASSFILES=AltosSerialMonitor.class AltosSerial.class AltosUI.class +CLASSPATH=..:/usr/share/java/* +CLASSFILES=AltosSerialMonitor.class AltosSerial.class AltosTelemetry.class AltosUI.class JAVAFLAGS=-Xlint:unchecked -all: $(CLASSFILES) +all: $(CLASSFILES) altosui .java.class: - javac -cp $(CLASSPATH) $(JAVAFLAGS) $*.java + javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java + +altosui: Makefile + (echo '#!/bin/sh'; \ + echo exec java -cp '"$(CLASSPATH)"' altosui/AltosUI) > $@ + chmod +x $@ clean: rm -f *.class \ No newline at end of file -- cgit v1.2.3 From 65079f84ea64220fa928c3ad96652fed159bf74b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 16:07:40 -0700 Subject: Steal C code from ao-view --- ao-tools/altosui/AltosConvert.java | 245 ++++++++++++++++++++++++++++ ao-tools/altosui/AltosGPS.java | 118 ++++++++++++++ ao-tools/altosui/AltosGreatCircle.java | 66 ++++++++ ao-tools/altosui/AltosParse.java | 75 +++++++++ ao-tools/altosui/AltosState.java | 166 +++++++++++++++++++ ao-tools/altosui/AltosTelemetry.java | 290 ++++++++++----------------------- ao-tools/altosui/AltosUI.java | 76 ++++++++- ao-tools/altosui/Makefile | 12 +- 8 files changed, 837 insertions(+), 211 deletions(-) create mode 100644 ao-tools/altosui/AltosConvert.java create mode 100644 ao-tools/altosui/AltosGPS.java create mode 100644 ao-tools/altosui/AltosGreatCircle.java create mode 100644 ao-tools/altosui/AltosParse.java create mode 100644 ao-tools/altosui/AltosState.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConvert.java b/ao-tools/altosui/AltosConvert.java new file mode 100644 index 00000000..3be0716c --- /dev/null +++ b/ao-tools/altosui/AltosConvert.java @@ -0,0 +1,245 @@ +/* + * Copyright © 2010 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. + */ + +/* + * Sensor data conversion functions + */ +package altosui; + +public class AltosConvert { + /* + * Pressure Sensor Model, version 1.1 + * + * written by Holly Grimes + * + * Uses the International Standard Atmosphere as described in + * "A Quick Derivation relating altitude to air pressure" (version 1.03) + * from the Portland State Aerospace Society, except that the atmosphere + * is divided into layers with each layer having a different lapse rate. + * + * Lapse rate data for each layer was obtained from Wikipedia on Sept. 1, 2007 + * at site MAXIMUM_ALTITUDE) /* FIX ME: use sensor data to improve model */ + return 0; + + /* calculate the base temperature and pressure for the atmospheric layer + associated with the inputted altitude */ + for(layer_number = 0; layer_number < NUMBER_OF_LAYERS - 1 && altitude > base_altitude[layer_number + 1]; layer_number++) { + delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number]; + if (lapse_rate[layer_number] == 0.0) { + exponent = GRAVITATIONAL_ACCELERATION * delta_z + / AIR_GAS_CONSTANT / base_temperature; + base_pressure *= Math.exp(exponent); + } + else { + base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; + exponent = GRAVITATIONAL_ACCELERATION / + (AIR_GAS_CONSTANT * lapse_rate[layer_number]); + base_pressure *= Math.pow(base, exponent); + } + base_temperature += delta_z * lapse_rate[layer_number]; + } + + /* calculate the pressure at the inputted altitude */ + delta_z = altitude - base_altitude[layer_number]; + if (lapse_rate[layer_number] == 0.0) { + exponent = GRAVITATIONAL_ACCELERATION * delta_z + / AIR_GAS_CONSTANT / base_temperature; + pressure = base_pressure * Math.exp(exponent); + } + else { + base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; + exponent = GRAVITATIONAL_ACCELERATION / + (AIR_GAS_CONSTANT * lapse_rate[layer_number]); + pressure = base_pressure * Math.pow(base, exponent); + } + + return pressure; + } + + +/* outputs the altitude associated with the given pressure. the altitude + returned is measured with respect to the mean sea level */ + static double + cc_pressure_to_altitude(double pressure) + { + + double next_base_temperature = LAYER0_BASE_TEMPERATURE; + double next_base_pressure = LAYER0_BASE_PRESSURE; + + double altitude; + double base_pressure; + double base_temperature; + double base; /* base for function to determine base pressure of next layer */ + double exponent; /* exponent for function to determine base pressure + of next layer */ + double coefficient; + int layer_number; /* identifies layer in the atmosphere */ + int delta_z; /* difference between two altitudes */ + + if (pressure < 0) /* illegal pressure */ + return -1; + if (pressure < MINIMUM_PRESSURE) /* FIX ME: use sensor data to improve model */ + return MAXIMUM_ALTITUDE; + + /* calculate the base temperature and pressure for the atmospheric layer + associated with the inputted pressure. */ + layer_number = -1; + do { + layer_number++; + base_pressure = next_base_pressure; + base_temperature = next_base_temperature; + delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number]; + if (lapse_rate[layer_number] == 0.0) { + exponent = GRAVITATIONAL_ACCELERATION * delta_z + / AIR_GAS_CONSTANT / base_temperature; + next_base_pressure *= Math.exp(exponent); + } + else { + base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; + exponent = GRAVITATIONAL_ACCELERATION / + (AIR_GAS_CONSTANT * lapse_rate[layer_number]); + next_base_pressure *= Math.pow(base, exponent); + } + next_base_temperature += delta_z * lapse_rate[layer_number]; + } + while(layer_number < NUMBER_OF_LAYERS - 1 && pressure < next_base_pressure); + + /* calculate the altitude associated with the inputted pressure */ + if (lapse_rate[layer_number] == 0.0) { + coefficient = (AIR_GAS_CONSTANT / GRAVITATIONAL_ACCELERATION) + * base_temperature; + altitude = base_altitude[layer_number] + + coefficient * Math.log(pressure / base_pressure); + } + else { + base = pressure / base_pressure; + exponent = AIR_GAS_CONSTANT * lapse_rate[layer_number] + / GRAVITATIONAL_ACCELERATION; + coefficient = base_temperature / lapse_rate[layer_number]; + altitude = base_altitude[layer_number] + + coefficient * (Math.pow(base, exponent) - 1); + } + + return altitude; + } + + /* + * 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 + cc_barometer_to_pressure(double count) + { + return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; + } + + static double + cc_barometer_to_altitude(double baro) + { + double Pa = cc_barometer_to_pressure(baro); + return cc_pressure_to_altitude(Pa); + } + + static final double count_per_mss = 27.0; + + static double + cc_accelerometer_to_acceleration(double accel, double ground_accel) + { + return (ground_accel - accel) / count_per_mss; + } + + /* 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 + cc_thermometer_to_temperature(double thermo) + { + return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; + } + + static double + cc_battery_to_voltage(double battery) + { + return battery / 32767.0 * 5.0; + } + + static double + cc_ignitor_to_voltage(double ignite) + { + return ignite / 32767 * 15.0; + } +} diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java new file mode 100644 index 00000000..d242ad57 --- /dev/null +++ b/ao-tools/altosui/AltosGPS.java @@ -0,0 +1,118 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; +import altosui.AltosParse; + + +public class AltosGPS { + public class AltosGPSTime { + int year; + int month; + int day; + int hour; + int minute; + int second; + + public AltosGPSTime(String date, String time) throws ParseException { + String[] ymd = date.split("-"); + if (ymd.length != 3) + throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); + year = AltosParse.parse_int(ymd[0]); + month = AltosParse.parse_int(ymd[1]); + day = AltosParse.parse_int(ymd[2]); + + String[] hms = time.split(":"); + if (hms.length != 3) + throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); + hour = AltosParse.parse_int(hms[0]); + minute = AltosParse.parse_int(hms[1]); + second = AltosParse.parse_int(hms[2]); + } + + public AltosGPSTime() { + year = month = day = 0; + hour = minute = second = 0; + } + + } + + public class AltosGPSSat { + int svid; + int c_n0; + } + + int nsat; + boolean gps_locked; + boolean gps_connected; + AltosGPSTime gps_time; + double lat; /* degrees (+N -S) */ + double lon; /* degrees (+E -W) */ + int alt; /* m */ + + int gps_extended; /* has extra data */ + double ground_speed; /* m/s */ + int course; /* degrees */ + double climb_rate; /* m/s */ + double hdop; /* unitless? */ + int h_error; /* m */ + int v_error; /* m */ + + AltosGPSSat[] cc_gps_sat; /* tracking data */ + + public AltosGPS(String[] words, int i) throws ParseException { + AltosParse.word(words[i++], "GPS"); + nsat = AltosParse.parse_int(words[i++]); + AltosParse.word(words[i++], "sat"); + + gps_connected = false; + gps_locked = false; + lat = lon = 0; + alt = 0; + if ((words[i]).equals("unlocked")) { + gps_connected = true; + gps_time = new AltosGPSTime(); + i++; + } else if (words.length >= 40) { + gps_locked = true; + gps_connected = true; + + gps_time = new AltosGPSTime(words[i], words[i+1]); i += 2; + lat = AltosParse.parse_coord(words[i++]); + lon = AltosParse.parse_coord(words[i++]); + alt = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "m")); + ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)")); + course = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "°")); + climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)")); + hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)")); + h_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(herr)")); + v_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(verr)")); + } else { + gps_time = new AltosGPSTime(); + } + AltosParse.word(words[i++], "SAT"); + int tracking_channels = AltosParse.parse_int(words[i++]); + cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels]; + for (int chan = 0; chan < tracking_channels; chan++) { + cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]); + cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]); + } + } +} diff --git a/ao-tools/altosui/AltosGreatCircle.java b/ao-tools/altosui/AltosGreatCircle.java new file mode 100644 index 00000000..878da03e --- /dev/null +++ b/ao-tools/altosui/AltosGreatCircle.java @@ -0,0 +1,66 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.Math; + +public class AltosGreatCircle { + double distance; + double bearing; + + double sqr(double a) { return a * a; } + + static final double rad = Math.PI / 180; + static final double earth_radius = 6371.2 * 1000; /* in meters */ + + AltosGreatCircle (double start_lat, double start_lon, + double end_lat, double end_lon) + { + double lat1 = rad * start_lat; + double lon1 = rad * -start_lon; + double lat2 = rad * end_lat; + double lon2 = rad * -end_lon; + + double d_lon = lon2 - lon1; + + /* From http://en.wikipedia.org/wiki/Great-circle_distance */ + double vdn = Math.sqrt(sqr(Math.cos(lat2) * Math.sin(d_lon)) + + sqr(Math.cos(lat1) * Math.sin(lat2) - + Math.sin(lat1) * Math.cos(lat2) * Math.cos(d_lon))); + double vdd = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(d_lon); + double d = Math.atan2(vdn,vdd); + double course; + + if (Math.cos(lat1) < 1e-20) { + if (lat1 > 0) + course = Math.PI; + else + course = -Math.PI; + } else { + if (d < 1e-10) + course = 0; + else + course = Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(d)) / + (Math.sin(d)*Math.cos(lat1))); + if (Math.sin(lon2-lon1) > 0) + course = 2 * Math.PI-course; + } + distance = d * earth_radius; + bearing = course * 180/Math.PI; + } +} diff --git a/ao-tools/altosui/AltosParse.java b/ao-tools/altosui/AltosParse.java new file mode 100644 index 00000000..a60dc694 --- /dev/null +++ b/ao-tools/altosui/AltosParse.java @@ -0,0 +1,75 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.text.*; +import java.lang.*; + +public class AltosParse { + static int parse_int(String v) throws ParseException { + try { + return Integer.parseInt(v); + } catch (NumberFormatException e) { + throw new ParseException("error parsing int " + v, 0); + } + } + + static int parse_hex(String v) throws ParseException { + try { + return Integer.parseInt(v, 16); + } catch (NumberFormatException e) { + throw new ParseException("error parsing hex " + v, 0); + } + } + + static double parse_double(String v) throws ParseException { + try { + return Double.parseDouble(v); + } catch (NumberFormatException e) { + throw new ParseException("error parsing double " + v, 0); + } + } + + static double parse_coord(String coord) throws ParseException { + String[] dsf = coord.split("\\D+"); + + if (dsf.length != 3) { + throw new ParseException("error parsing coord " + coord, 0); + } + int deg = parse_int(dsf[0]); + int min = parse_int(dsf[1]); + int frac = parse_int(dsf[2]); + + double r = deg + (min + frac / 10000.0) / 60.0; + if (coord.endsWith("S") || coord.endsWith("W")) + r = -r; + return r; + } + + static String strip_suffix(String v, String suffix) { + if (v.endsWith(suffix)) + return v.substring(0, v.length() - suffix.length()); + return v; + } + + static void word(String v, String m) throws ParseException { + if (!v.equals(m)) { + throw new ParseException("error matching '" + v + "' '" + m + "'", 0); + } + } +} diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java new file mode 100644 index 00000000..da465c75 --- /dev/null +++ b/ao-tools/altosui/AltosState.java @@ -0,0 +1,166 @@ +/* + * Copyright © 2010 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. + */ + +/* + * Track flight state from telemetry data stream + */ + +package altosui; + +import altosui.AltosTelemetry; +import altosui.AltosGPS; + +public class AltosState { + AltosTelemetry data; + AltosTelemetry prev_data; + + /* derived data */ + + double report_time; + + int state; + boolean ascent; /* going up? */ + + double ground_altitude; + double height; + double speed; + double acceleration; + double battery; + double temperature; + double main_sense; + double drogue_sense; + double baro_speed; + + double max_height; + double max_acceleration; + double max_speed; + + AltosGPS gps; + AltosGPSTracking gps_tracking; + + boolean gps_valid; + double pad_lat; + double pad_lon; + double pad_alt; + double pad_lat_total; + double pad_lon_total; + double pad_alt_total; + int npad; + int prev_npad; + + AltosGreatCircle from_pad; + + double gps_height; + + int speak_tick; + double speak_altitude; + + static double + aoview_time() + { + return System.currentTimeMillis() / 1000.0; + } + + public AltosState (AltosTelemetry cur, AltosTelemetry prev, int prev_npad) { + int i; + double new_height; + double height_change; + double time_change; + double accel_counts_per_mss; + int tick_count; + + data = cur; + prev_data = prev; + npad = prev_npad; + tick_count = data.tick; + if (tick_count < prev_data.tick) + tick_count += 65536; + time_change = (tick_count - prev_data.tick) / 100.0; + + report_time = aoview_time(); + + ground_altitude = AltosConvert.cc_pressure_to_altitude(data.ground_pres); + new_height = AltosConvert.cc_pressure_to_altitude(data.flight_pres) - ground_altitude; + height_change = new_height - height; + height = new_height; + if (time_change > 0) + baro_speed = (baro_speed * 3 + (height_change / time_change)) / 4.0; + accel_counts_per_mss = ((data.accel_minus_g - data.accel_plus_g) / 2.0) / 9.80665; + acceleration = (data.ground_accel - data.flight_accel) / accel_counts_per_mss; + speed = data.flight_vel / (accel_counts_per_mss * 100.0); + temperature = AltosConvert.cc_thermometer_to_temperature(data.temp); + drogue_sense = AltosConvert.cc_ignitor_to_voltage(data.drogue); + main_sense = AltosConvert.cc_ignitor_to_voltage(data.main); + battery = AltosConvert.cc_battery_to_voltage(data.batt); + state = data.state(); + if (state == AltosTelemetry.ao_flight_pad) { + if (data.gps.gps_locked && data.gps.nsat >= 4) { + npad++; + pad_lat_total += data.gps.lat; + pad_lon_total += data.gps.lon; + pad_alt_total += data.gps.alt; + if (npad > 1) { + pad_lat = (pad_lat * 31 + data.gps.lat) / 32.0; + pad_lon = (pad_lon * 31 + data.gps.lon) / 32.0; + pad_alt = (pad_alt * 31 + data.gps.alt) / 32.0; + } else { + pad_lat = data.gps.lat; + pad_lon = data.gps.lon; + pad_alt = data.gps.alt; + } + } + } + ascent = (AltosTelemetry.ao_flight_boost <= state && + state <= AltosTelemetry.ao_flight_coast); + + /* Only look at accelerometer data on the way up */ + if (ascent && acceleration > max_acceleration) + max_acceleration = acceleration; + if (ascent && speed > max_speed) + max_speed = speed; + + if (height > max_height) + max_height = height; + gps.gps_locked = data.gps.gps_locked; + gps.gps_connected = data.gps.gps_connected; + if (data.gps.gps_locked) { + gps = data.gps; + gps_valid = true; + if (npad > 0) + from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); + } + if (npad > 0) { + gps_height = gps.alt - pad_alt; + } else { + gps_height = 0; + } + } + + public AltosState(AltosTelemetry cur) { + this(cur, cur, 0); + } + + public AltosState (AltosTelemetry cur, AltosState prev) { + this(cur, prev.data, prev.npad); + if (gps == null) { + gps = prev.gps; + gps_valid = prev.gps_valid; + } + if (gps_tracking == null) + gps_tracking = prev.gps_tracking; + } +} diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index 99e82bbf..34b4099f 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -19,77 +19,14 @@ package altosui; import java.lang.*; import java.text.*; +import java.util.HashMap; +import altosui.AltosConvert; +import altosui.AltosGPS; /* * Telemetry data contents */ -class AltosGPSTime { - int year; - int month; - int day; - int hour; - int minute; - int second; - - int parse_int(String v) throws ParseException { - try { - return Integer.parseInt(v); - } catch (NumberFormatException e) { - throw new ParseException("error parsing GPS value " + v, 0); - } - } - - public AltosGPSTime(String date, String time) throws ParseException { - String[] ymd = date.split("-"); - if (ymd.length != 3) - throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); - year = parse_int(ymd[0]); - month = parse_int(ymd[1]); - day = parse_int(ymd[2]); - - String[] hms = time.split(":"); - if (hms.length != 3) - throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); - hour = parse_int(hms[0]); - minute = parse_int(hms[1]); - second = parse_int(hms[2]); - } - - public AltosGPSTime() { - year = month = day = 0; - hour = minute = second = 0; - } -}; - -class AltosGPS { - int nsat; - int gps_locked; - int gps_connected; - AltosGPSTime gps_time; - double lat; /* degrees (+N -S) */ - double lon; /* degrees (+E -W) */ - int alt; /* m */ - - int gps_extended; /* has extra data */ - double ground_speed; /* m/s */ - int course; /* degrees */ - double climb_rate; /* m/s */ - double hdop; /* unitless? */ - int h_error; /* m */ - int v_error; /* m */ - -} - -class AltosGPSSat { - int svid; - int c_n0; -} - -class AltosGPSTracking { - int channels; - AltosGPSSat[] cc_gps_sat; -} /* * The telemetry data stream is a bit of a mess at present, with no consistent @@ -137,58 +74,44 @@ public class AltosTelemetry { int accel_plus_g; int accel_minus_g; AltosGPS gps; - AltosGPSTracking gps_tracking; - - int parse_int(String v) throws ParseException { - try { - return Integer.parseInt(v); - } catch (NumberFormatException e) { - throw new ParseException("error parsing int " + v, 0); - } - } - int parse_hex(String v) throws ParseException { - try { - return Integer.parseInt(v, 16); - } catch (NumberFormatException e) { - throw new ParseException("error parsing hex " + v, 0); - } + public static final int ao_flight_startup = 0; + public static final int ao_flight_idle = 1; + public static final int ao_flight_pad = 2; + public static final int ao_flight_boost = 3; + public static final int ao_flight_fast = 4; + public static final int ao_flight_coast = 5; + public static final int ao_flight_drogue = 6; + public static final int ao_flight_main = 7; + public static final int ao_flight_landed = 8; + public static final int ao_flight_invalid = 9; + + static HashMap states = new HashMap(); + { + states.put("startup", ao_flight_startup); + states.put("idle", ao_flight_idle); + states.put("pad", ao_flight_pad); + states.put("boost", ao_flight_boost); + states.put("fast", ao_flight_fast); + states.put("coast", ao_flight_coast); + states.put("drogue", ao_flight_drogue); + states.put("main", ao_flight_main); + states.put("landed", ao_flight_landed); + states.put("invalid", ao_flight_invalid); } - double parse_double(String v) throws ParseException { - try { - return Double.parseDouble(v); - } catch (NumberFormatException e) { - throw new ParseException("error parsing double " + v, 0); - } - } - - double parse_coord(String coord) throws ParseException { - String[] dsf = coord.split("\\D+"); - - if (dsf.length != 3) { - throw new ParseException("error parsing coord " + coord, 0); - } - int deg = parse_int(dsf[0]); - int min = parse_int(dsf[1]); - int frac = parse_int(dsf[2]); - - double r = deg + (min + frac / 10000.0) / 60.0; - if (coord.endsWith("S") || coord.endsWith("W")) - r = -r; - return r; + public int state() { + if (states.containsKey(state)) + return states.get(state); + return ao_flight_invalid; } - String strip_suffix(String v, String suffix) { - if (v.endsWith(suffix)) - return v.substring(0, v.length() - suffix.length()); - return v; + public double altitude() { + return AltosConvert.cc_pressure_to_altitude(AltosConvert.cc_barometer_to_pressure(pres)); } - void word(String v, String m) throws ParseException { - if (!v.equals(m)) { - throw new ParseException("error matching '" + v + "' '" + m + "'", 0); - } + public double pad_altitude() { + return AltosConvert.cc_pressure_to_altitude(AltosConvert.cc_barometer_to_pressure(ground_pres)); } public AltosTelemetry(String line) throws ParseException { @@ -196,106 +119,67 @@ public class AltosTelemetry { int i = 0; - word (words[i++], "VERSION"); - version = parse_int(words[i++]); + AltosParse.word (words[i++], "VERSION"); + version = AltosParse.parse_int(words[i++]); - word (words[i++], "CALL"); + AltosParse.word (words[i++], "CALL"); callsign = words[i++]; - word (words[i++], "SERIAL"); - serial = parse_int(words[i++]); + AltosParse.word (words[i++], "SERIAL"); + serial = AltosParse.parse_int(words[i++]); - word (words[i++], "FLIGHT"); - flight = parse_int(words[i++]); + AltosParse.word (words[i++], "FLIGHT"); + flight = AltosParse.parse_int(words[i++]); - word(words[i++], "RSSI"); - rssi = parse_int(words[i++]); + AltosParse.word(words[i++], "RSSI"); + rssi = AltosParse.parse_int(words[i++]); - word(words[i++], "STATUS"); - status = parse_hex(words[i++]); + AltosParse.word(words[i++], "STATUS"); + status = AltosParse.parse_hex(words[i++]); - word(words[i++], "STATE"); + AltosParse.word(words[i++], "STATE"); state = words[i++]; - tick = parse_int(words[i++]); - - word(words[i++], "a:"); - accel = parse_int(words[i++]); - - word(words[i++], "p:"); - pres = parse_int(words[i++]); - - word(words[i++], "t:"); - temp = parse_int(words[i++]); - - word(words[i++], "v:"); - batt = parse_int(words[i++]); - - word(words[i++], "d:"); - drogue = parse_int(words[i++]); - - word(words[i++], "m:"); - main = parse_int(words[i++]); - - word(words[i++], "fa:"); - flight_accel = parse_int(words[i++]); - - word(words[i++], "ga:"); - ground_accel = parse_int(words[i++]); - - word(words[i++], "fv:"); - flight_vel = parse_int(words[i++]); - - word(words[i++], "fp:"); - flight_pres = parse_int(words[i++]); - - word(words[i++], "gp:"); - ground_pres = parse_int(words[i++]); - - word(words[i++], "a+:"); - accel_plus_g = parse_int(words[i++]); - - word(words[i++], "a-:"); - accel_minus_g = parse_int(words[i++]); - - word(words[i++], "GPS"); - gps = new AltosGPS(); - gps.nsat = parse_int(words[i++]); - word(words[i++], "sat"); - - gps.gps_connected = 0; - gps.gps_locked = 0; - gps.lat = gps.lon = 0; - gps.alt = 0; - if ((words[i]).equals("unlocked")) { - gps.gps_connected = 1; - gps.gps_time = new AltosGPSTime(); - i++; - } else if (words.length >= 40) { - gps.gps_locked = 1; - gps.gps_connected = 1; - - gps.gps_time = new AltosGPSTime(words[i], words[i+1]); i += 2; - gps.lat = parse_coord(words[i++]); - gps.lon = parse_coord(words[i++]); - gps.alt = parse_int(strip_suffix(words[i++], "m")); - gps.ground_speed = parse_double(strip_suffix(words[i++], "m/s(H)")); - gps.course = parse_int(strip_suffix(words[i++], "°")); - gps.climb_rate = parse_double(strip_suffix(words[i++], "m/s(V)")); - gps.hdop = parse_double(strip_suffix(words[i++], "(hdop)")); - gps.h_error = parse_int(strip_suffix(words[i++], "(herr)")); - gps.v_error = parse_int(strip_suffix(words[i++], "(verr)")); - } else { - gps.gps_time = new AltosGPSTime(); - } - word(words[i++], "SAT"); - gps_tracking = new AltosGPSTracking(); - gps_tracking.channels = parse_int(words[i++]); - gps_tracking.cc_gps_sat = new AltosGPSSat[gps_tracking.channels]; - for (int chan = 0; chan < gps_tracking.channels; chan++) { - gps_tracking.cc_gps_sat[chan] = new AltosGPSSat(); - gps_tracking.cc_gps_sat[chan].svid = parse_int(words[i++]); - gps_tracking.cc_gps_sat[chan].c_n0 = parse_int(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:"); + drogue = 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++]); + + AltosParse.word(words[i++], "gp:"); + ground_pres = AltosParse.parse_int(words[i++]); + + 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++]); + } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 89eaac15..21c3e7a2 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -20,6 +20,8 @@ package altosui; import java.awt.*; import java.awt.event.*; import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.AbstractTableModel; import java.io.*; import java.util.*; import java.text.*; @@ -27,6 +29,8 @@ import gnu.io.CommPortIdentifier; import altosui.AltosSerial; import altosui.AltosSerialMonitor; +import altosui.AltosTelemetry; +import altosui.AltosState; class AltosUIMonitor implements AltosSerialMonitor { public void data(String data) { @@ -34,6 +38,32 @@ class AltosUIMonitor implements AltosSerialMonitor { } } +class AltosFlightStatusTableModel extends AbstractTableModel { + private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; + private Object[] data = { 0, "idle", 0, 0 }; + + public int getColumnCount() { return columnNames.length; } + public int getRowCount() { return 1; } + public String getColumnName(int col) { return columnNames[col]; } + public Object getValueAt(int row, int col) { return data[col]; } + + public void setValueAt(Object value, int col) { + data[col] = value; + fireTableCellUpdated(0, col); + } + + public void setValueAt(Object value, int row, int col) { + setValueAt(value, col); + } + + public void set(AltosState state) { + setValueAt(state.height, 0); + setValueAt(state.data.state, 1); + setValueAt(state.data.rssi, 2); + setValueAt(state.speed, 3); + } +} + public class AltosUI extends JFrame { private int channel = -1; @@ -71,6 +101,31 @@ public class AltosUI extends JFrame { } final JFileChooser deviceChooser = new JFileChooser(); + final JFileChooser logdirChooser = new JFileChooser(); + final String logdirName = "TeleMetrum"; + File logdir = null; + + private void setLogdir() { + if (logdir == null) + logdir = new File(logdirChooser.getCurrentDirectory(), logdirName); + logdirChooser.setCurrentDirectory(logdir); + } + + private void makeLogdir() { + setLogdir(); + if (!logdir.exists()) { + if (!logdir.mkdirs()) + JOptionPane.showMessageDialog(AltosUI.this, + logdir.getName(), + "Cannot create directory", + JOptionPane.ERROR_MESSAGE); + } else if (!logdir.isDirectory()) { + JOptionPane.showMessageDialog(AltosUI.this, + logdir.getName(), + "Is not a directory", + JOptionPane.ERROR_MESSAGE); + } + } private void PickSerialDevice() { java.util.Enumeration port_list = CommPortIdentifier.getPortIdentifiers(); @@ -111,16 +166,23 @@ public class AltosUI extends JFrame { return null; } + /* + * Open an existing telemetry file and replay it in realtime + */ + private void Replay() { -// int returnVal = deviceChooser.showOpenDialog(AltosUI.this); + setLogdir(); + logdirChooser.setDialogTitle("Select Telemetry File"); + logdirChooser.setFileFilter(new FileNameExtensionFilter("Telemetry file", "telem")); + int returnVal = logdirChooser.showOpenDialog(AltosUI.this); - /* if (returnVal == JFileChooser.APPROVE_OPTION) */ { -// File file = deviceChooser.getSelectedFile(); -// String filename = file.getName(); - String filename = "/home/keithp/src/cc1111/flights/2010-02-13-serial-051-flight-002.telem"; + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = logdirChooser.getSelectedFile(); + if (file == null) + System.out.println("No file selected?"); + String filename = file.getName(); try { -// FileInputStream replay = new FileInputStream(file); - FileInputStream replay = new FileInputStream(filename); + FileInputStream replay = new FileInputStream(file); String line; try { diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 090911ef..1fb964d6 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -1,7 +1,17 @@ .SUFFIXES: .java .class CLASSPATH=..:/usr/share/java/* -CLASSFILES=AltosSerialMonitor.class AltosSerial.class AltosTelemetry.class AltosUI.class +CLASSFILES=\ + AltosConvert.class \ + AltosGPS.class \ + AltosGreatCircle.class \ + AltosParse.class \ + AltosSerialMonitor.class \ + AltosSerial.class \ + AltosState.class \ + AltosTelemetry.class \ + AltosUI.class + JAVAFLAGS=-Xlint:unchecked all: $(CLASSFILES) altosui -- cgit v1.2.3 From a579402f428dd6a0529505069d1846f70b83ab5d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 18:10:59 -0700 Subject: Display table of flight info. gps is not working yet though --- ao-tools/altosui/AltosState.java | 30 ++-- ao-tools/altosui/AltosUI.java | 289 +++++++++++++++++++++++++++++++++++---- 2 files changed, 272 insertions(+), 47 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index da465c75..b3054ce9 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -35,6 +35,8 @@ public class AltosState { int state; boolean ascent; /* going up? */ + double time_change; + double ground_altitude; double height; double speed; @@ -50,9 +52,7 @@ public class AltosState { double max_speed; AltosGPS gps; - AltosGPSTracking gps_tracking; - boolean gps_valid; double pad_lat; double pad_lon; double pad_alt; @@ -75,11 +75,10 @@ public class AltosState { return System.currentTimeMillis() / 1000.0; } - public AltosState (AltosTelemetry cur, AltosTelemetry prev, int prev_npad) { + void init (AltosTelemetry cur, AltosTelemetry prev, int prev_npad) { int i; double new_height; double height_change; - double time_change; double accel_counts_per_mss; int tick_count; @@ -108,7 +107,7 @@ public class AltosState { battery = AltosConvert.cc_battery_to_voltage(data.batt); state = data.state(); if (state == AltosTelemetry.ao_flight_pad) { - if (data.gps.gps_locked && data.gps.nsat >= 4) { + if (data.gps != null && data.gps.gps_locked && data.gps.nsat >= 4) { npad++; pad_lat_total += data.gps.lat; pad_lon_total += data.gps.lon; @@ -135,12 +134,9 @@ public class AltosState { if (height > max_height) max_height = height; - gps.gps_locked = data.gps.gps_locked; - gps.gps_connected = data.gps.gps_connected; - if (data.gps.gps_locked) { + if (data.gps != null) { gps = data.gps; - gps_valid = true; - if (npad > 0) + if (npad > 0 && gps.gps_locked) from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); } if (npad > 0) { @@ -151,16 +147,16 @@ public class AltosState { } public AltosState(AltosTelemetry cur) { - this(cur, cur, 0); + init(cur, cur, 0); } public AltosState (AltosTelemetry cur, AltosState prev) { - this(cur, prev.data, prev.npad); - if (gps == null) { - gps = prev.gps; - gps_valid = prev.gps_valid; + if (prev == null) + init(cur, cur, 0); + else { + init(cur, prev.data, prev.npad); + if (gps == null) + gps = prev.gps; } - if (gps_tracking == null) - gps_tracking = prev.gps_tracking; } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 21c3e7a2..47a03f4e 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -57,30 +57,114 @@ class AltosFlightStatusTableModel extends AbstractTableModel { } public void set(AltosState state) { - setValueAt(state.height, 0); + setValueAt(String.format("%1.0f", state.height), 0); setValueAt(state.data.state, 1); setValueAt(state.data.rssi, 2); - setValueAt(state.speed, 3); + double speed = state.baro_speed; + if (state.ascent) + speed = state.speed; + setValueAt(String.format("%1.0f", speed), 3); + } +} + +class AltosFlightInfoTableModel extends AbstractTableModel { + private String[] columnNames = {"Field", "Value"}; + + class InfoLine { + String name; + String value; + + public InfoLine(String n, String v) { + name = n; + value = v; + } + } + + private ArrayList rows = new ArrayList(); + + public int getColumnCount() { return columnNames.length; } + public String getColumnName(int col) { return columnNames[col]; } + + public int getRowCount() { return 20; } + + public Object getValueAt(int row, int col) { + if (row >= rows.size()) + return ""; + if (col == 0) + return rows.get(row).name; + else + return rows.get(row).value; + } + + int current_row = 0; + int prev_num_rows = 0; + + public void resetRow() { + current_row = 0; + } + public void addRow(String name, String value) { + if (current_row >= rows.size()) + rows.add(current_row, new InfoLine(name, value)); + else + rows.set(current_row, new InfoLine(name, value)); + current_row++; + } + public void finish() { + if (current_row > prev_num_rows) { + fireTableRowsInserted(prev_num_rows, current_row - 1); + prev_num_rows = current_row; + } + fireTableDataChanged(); } } public class AltosUI extends JFrame { private int channel = -1; + private AltosFlightStatusTableModel flightStatusModel; private JTable flightStatus; - private JTable flightInfo; + + static final int info_columns = 3; + + private AltosFlightInfoTableModel[] flightInfoModel; + private JTable[] flightInfo; private AltosSerial serialLine; + private Box[] ibox; + private Box vbox; + private Box hbox; public AltosUI() { String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; Object[][] statusData = { { "0", "pad", "-50", "0" } }; - flightStatus = new JTable(statusData, statusNames); + vbox = Box.createVerticalBox(); + this.add(vbox); + + flightStatusModel = new AltosFlightStatusTableModel(); + flightStatus = new JTable(flightStatusModel); flightStatus.setShowGrid(false); - this.add(flightStatus); + flightInfo = new JTable[3]; + flightInfoModel = new AltosFlightInfoTableModel[3]; + ibox = new Box[3]; + + vbox.add(flightStatus.getTableHeader()); + vbox.add(flightStatus); + + hbox = Box.createHorizontalBox(); + vbox.add(hbox); + + for (int i = 0; i < info_columns; i++) { + ibox[i] = Box.createVerticalBox(); + flightInfoModel[i] = new AltosFlightInfoTableModel(); + flightInfo[i] = new JTable(flightInfoModel[i]); + flightInfo[i].setShowGrid(true); + ibox[i].add(flightInfo[i].getTableHeader()); + ibox[i].add(flightInfo[i]); + hbox.add(ibox[i]); + } setTitle("AltOS"); @@ -100,6 +184,131 @@ public class AltosUI extends JFrame { }); } + public void info_reset() { + for (int i = 0; i < info_columns; i++) + flightInfoModel[i].resetRow(); + } + + public void info_add_row(int col, String name, String value) { + flightInfoModel[col].addRow(name, value); + } + + public void info_add_row(int col, String name, String format, Object value) { + flightInfoModel[col].addRow(name, String.format(format, value)); + } + + public void info_add_row(int col, String name, String format, Object v1, Object v2) { + flightInfoModel[col].addRow(name, String.format(format, v1, v2)); + } + + public void info_add_row(int col, String name, String format, Object v1, Object v2, Object v3) { + flightInfoModel[col].addRow(name, String.format(format, v1, v2, v3)); + } + + public void info_add_deg(int col, String name, double v, int pos, int neg) { + int c = pos; + if (v < 0) { + c = neg; + v = -v; + } + double deg = Math.floor(v); + double min = (v - deg) * 60; + + flightInfoModel[col].addRow(name, String.format("%3.0f°%08.5f'", deg, min)); + } + + public void info_finish() { + for (int i = 0; i < info_columns; i++) + flightInfoModel[i].finish(); + } + + static final int MIN_PAD_SAMPLES = 10; + + public void show(AltosState state) { + flightStatusModel.set(state); + + info_reset(); + if (state.npad >= MIN_PAD_SAMPLES) + info_add_row(0, "Ground state", "%s", "ready"); + else + info_add_row(0, "Ground state", "waiting for gps (%d)", + MIN_PAD_SAMPLES - state.npad); + info_add_row(0, "Rocket state", "%s", state.data.state); + info_add_row(0, "Callsign", "%s", state.data.callsign); + info_add_row(0, "Rocket serial", "%d", state.data.serial); + info_add_row(0, "Rocket flight", "%d", state.data.flight); + + info_add_row(0, "RSSI", "%6ddBm", state.data.rssi); + info_add_row(0, "Height", "%6.0fm", state.height); + info_add_row(0, "Max height", "%6.0fm", state.max_height); + info_add_row(0, "Acceleration", "%7.1fm/s²", state.acceleration); + info_add_row(0, "Max acceleration", "%7.1fm/s²", state.max_acceleration); + info_add_row(0, "Speed", "%7.1fm/s", state.ascent ? state.speed : state.baro_speed); + info_add_row(0, "Max Speed", "%7.1fm/s", state.max_speed); + info_add_row(0, "Temperature", "%6.2f°C", state.temperature); + info_add_row(0, "Battery", "%5.2fV", state.battery); + info_add_row(0, "Drogue", "%5.2fV", state.drogue_sense); + info_add_row(0, "Main", "%5.2fV", state.main_sense); + info_add_row(0, "Pad altitude", "%6.0fm", state.ground_altitude); + if (state.gps != null) + info_add_row(1, "Satellites", "%d", state.gps.nsat); + else + info_add_row(1, "Satellites", "%d", 0); + if (state.gps != null && state.gps.gps_locked) { + info_add_row(1, "GPS", "locked"); + } else if (state.gps != null && state.gps.gps_connected) { + info_add_row(1, "GPS", "unlocked"); + } else { + info_add_row(1, "GPS", "not available"); + } + if (state.gps != null) { + 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", "%d", state.gps.alt); + info_add_row(1, "GPS height", "%d", state.gps_height); + info_add_row(1, "GPS date", "%04d-%02d-%02d", + state.gps.gps_time.year, + state.gps.gps_time.month, + state.gps.gps_time.day); + info_add_row(1, "GPS time", "%02d:%02d:%02d", + state.gps.gps_time.hour, + state.gps.gps_time.minute, + state.gps.gps_time.second); + info_add_row(1, "GPS ground speed", "%7.1fm/s %d°", + state.gps.ground_speed, + state.gps.course); + info_add_row(1, "GPS climb rate", "%7.1fm/s", + state.gps.climb_rate); + info_add_row(1, "GPS precision", "%4.1f(hdop) %3dm(h) %3dm(v)", + state.gps.hdop, state.gps.h_error, state.gps.v_error); + } + if (state.npad > 0) { + info_add_row(1, "Distance from pad", "%5.0fm", state.from_pad.distance); + info_add_row(1, "Direction from pad", "%4.0f°", state.from_pad.bearing); + info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); + info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); + info_add_row(1, "Pad GPS alt", "%gm", state.pad_alt); + } + if (state.gps != null && state.gps.gps_connected) { + int nsat_vis = 0; + int c; + + if (state.gps.cc_gps_sat == null) + info_add_row(2, "Satellites Visible", "%d", 0); + else { + info_add_row(2, "Satellites Visible", "%d", state.gps.cc_gps_sat.length); + for (c = 0; c < state.gps.cc_gps_sat.length; c++) { + info_add_row(2, "Satellite id,C/N0", + "%3d,%2d", + state.gps.cc_gps_sat[c].svid, + state.gps.cc_gps_sat[c].c_n0); + } + } + } + info_finish(); + } + + final JFileChooser deviceChooser = new JFileChooser(); final JFileChooser logdirChooser = new JFileChooser(); final String logdirName = "TeleMetrum"; @@ -170,6 +379,49 @@ public class AltosUI extends JFrame { * Open an existing telemetry file and replay it in realtime */ + class ReplayThread extends Thread { + FileInputStream replay; + String filename; + + ReplayThread(FileInputStream in, String name) { + replay = in; + filename = name; + } + + public void run() { + String line; + AltosState state = null; + try { + while ((line = readline(replay)) != null) { + try { + AltosTelemetry t = new AltosTelemetry(line); + state = new AltosState(t, state); + show(state); + try { + if (state.state > AltosTelemetry.ao_flight_pad) + Thread.sleep((int) (state.time_change * 1000)); + } catch (InterruptedException e) {} + } catch (ParseException pp) { + JOptionPane.showMessageDialog(AltosUI.this, + line, + "error parsing", + JOptionPane.ERROR_MESSAGE); + break; + } + } + } catch (IOException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + filename, + "error reading", + JOptionPane.ERROR_MESSAGE); + } finally { + try { + replay.close(); + } catch (IOException e) {} + } + } + } + private void Replay() { setLogdir(); logdirChooser.setDialogTitle("Select Telemetry File"); @@ -183,31 +435,8 @@ public class AltosUI extends JFrame { String filename = file.getName(); try { FileInputStream replay = new FileInputStream(file); - String line; - - try { - while ((line = readline(replay)) != null) { - try { - AltosTelemetry t = new AltosTelemetry(line); - System.out.println ("Version " + t.version + t.callsign); - } catch (ParseException pp) { - JOptionPane.showMessageDialog(AltosUI.this, - line, - "error parsing", - JOptionPane.ERROR_MESSAGE); - break; - } - } - } catch (IOException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - filename, - "error reading", - JOptionPane.ERROR_MESSAGE); - } finally { - try { - replay.close(); - } catch (IOException e) {} - } + ReplayThread thread = new ReplayThread(replay, filename); + thread.start(); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, filename, -- cgit v1.2.3 From caa0bf49668344937483190d1c258bfa32971d19 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 21:44:00 -0700 Subject: Fix up table formatting --- ao-tools/altosui/AltosUI.java | 96 +++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 27 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 47a03f4e..7befe778 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.AbstractTableModel; +import javax.swing.table.*; import java.io.*; import java.util.*; import java.text.*; @@ -43,9 +43,12 @@ class AltosFlightStatusTableModel extends AbstractTableModel { private Object[] data = { 0, "idle", 0, 0 }; public int getColumnCount() { return columnNames.length; } - public int getRowCount() { return 1; } - public String getColumnName(int col) { return columnNames[col]; } - public Object getValueAt(int row, int col) { return data[col]; } + public int getRowCount() { return 2; } + public Object getValueAt(int row, int col) { + if (row == 0) + return columnNames[col]; + return data[col]; + } public void setValueAt(Object value, int col) { data[col] = value; @@ -67,6 +70,26 @@ class AltosFlightStatusTableModel extends AbstractTableModel { } } +class AltosFlightStatusCellRenderer extends DefaultTableCellRenderer { + + static Font statusFont = new Font("SansSerif", Font.BOLD, 24); + + @Override public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, + boolean hasFocus, int row, int column) + { + Component cell = super.getTableCellRendererComponent + (table, value, isSelected, hasFocus, row, column); + System.out.println("Selecting new font for cell " + row + " " + column + " " + statusFont); + cell.setFont(statusFont); + return cell; + } + + public AltosFlightStatusCellRenderer () { + super(); + System.out.println("Made a status cell renderer\n"); + } +} + class AltosFlightInfoTableModel extends AbstractTableModel { private String[] columnNames = {"Field", "Value"}; @@ -133,6 +156,10 @@ public class AltosUI extends JFrame { private Box vbox; private Box hbox; + private Font statusFont = new Font("SansSerif", Font.BOLD, 24); + private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14); + private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14); + public AltosUI() { String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; @@ -143,23 +170,37 @@ public class AltosUI extends JFrame { flightStatusModel = new AltosFlightStatusTableModel(); flightStatus = new JTable(flightStatusModel); + flightStatus.setFont(statusFont); + TableColumnModel tcm = flightStatus.getColumnModel(); + for (int i = 0; i < flightStatusModel.getColumnCount(); i++) { + DefaultTableCellRenderer r = new DefaultTableCellRenderer(); + r.setFont(statusFont); + r.setHorizontalAlignment(SwingConstants.CENTER); + tcm.getColumn(i).setCellRenderer(r); + } + FontMetrics statusMetrics = flightStatus.getFontMetrics(statusFont); + int statusHeight = (statusMetrics.getHeight() + statusMetrics.getLeading()) * 15 / 10; + flightStatus.setRowHeight(statusHeight); flightStatus.setShowGrid(false); - flightInfo = new JTable[3]; - flightInfoModel = new AltosFlightInfoTableModel[3]; - ibox = new Box[3]; - - vbox.add(flightStatus.getTableHeader()); vbox.add(flightStatus); hbox = Box.createHorizontalBox(); vbox.add(hbox); + flightInfo = new JTable[3]; + flightInfoModel = new AltosFlightInfoTableModel[3]; + ibox = new Box[3]; + FontMetrics infoValueMetrics = flightStatus.getFontMetrics(infoValueFont); + int infoHeight = (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 20 / 10; + for (int i = 0; i < info_columns; i++) { ibox[i] = Box.createVerticalBox(); flightInfoModel[i] = new AltosFlightInfoTableModel(); flightInfo[i] = new JTable(flightInfoModel[i]); + flightInfo[i].setFont(infoValueFont); + flightInfo[i].setRowHeight(infoHeight); flightInfo[i].setShowGrid(true); ibox[i].add(flightInfo[i].getTableHeader()); ibox[i].add(flightInfo[i]); @@ -173,7 +214,8 @@ public class AltosUI extends JFrame { serialLine = new AltosSerial(); serialLine.monitor(new AltosUIMonitor()); int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); - this.setSize(new Dimension (dpi * 5, dpi * 4)); + this.setSize(new Dimension (infoValueMetrics.charWidth('0') * 6 * 15, + statusHeight * 4 + infoHeight * 17)); this.validate(); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @@ -235,25 +277,25 @@ public class AltosUI extends JFrame { MIN_PAD_SAMPLES - state.npad); info_add_row(0, "Rocket state", "%s", state.data.state); info_add_row(0, "Callsign", "%s", state.data.callsign); - info_add_row(0, "Rocket serial", "%d", state.data.serial); - info_add_row(0, "Rocket flight", "%d", state.data.flight); - - info_add_row(0, "RSSI", "%6ddBm", state.data.rssi); - info_add_row(0, "Height", "%6.0fm", state.height); - info_add_row(0, "Max height", "%6.0fm", state.max_height); - info_add_row(0, "Acceleration", "%7.1fm/s²", state.acceleration); - info_add_row(0, "Max acceleration", "%7.1fm/s²", state.max_acceleration); - info_add_row(0, "Speed", "%7.1fm/s", state.ascent ? state.speed : state.baro_speed); - info_add_row(0, "Max Speed", "%7.1fm/s", state.max_speed); - info_add_row(0, "Temperature", "%6.2f°C", state.temperature); - info_add_row(0, "Battery", "%5.2fV", state.battery); - info_add_row(0, "Drogue", "%5.2fV", state.drogue_sense); - info_add_row(0, "Main", "%5.2fV", state.main_sense); - info_add_row(0, "Pad altitude", "%6.0fm", state.ground_altitude); + info_add_row(0, "Rocket serial", "%6d", state.data.serial); + info_add_row(0, "Rocket flight", "%6d", state.data.flight); + + info_add_row(0, "RSSI", "%6d dBm", state.data.rssi); + info_add_row(0, "Height", "%6.0f m", state.height); + info_add_row(0, "Max height", "%6.0f m", state.max_height); + info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration); + info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration); + info_add_row(0, "Speed", "%8.1f m/s", state.ascent ? state.speed : state.baro_speed); + info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed); + info_add_row(0, "Temperature", "%9.2f °C", state.temperature); + info_add_row(0, "Battery", "%9.2f V", state.battery); + info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense); + info_add_row(0, "Main", "%9.2f V", state.main_sense); + info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude); if (state.gps != null) - info_add_row(1, "Satellites", "%d", state.gps.nsat); + info_add_row(1, "Satellites", "%6d", state.gps.nsat); else - info_add_row(1, "Satellites", "%d", 0); + info_add_row(1, "Satellites", "%6d", 0); if (state.gps != null && state.gps.gps_locked) { info_add_row(1, "GPS", "locked"); } else if (state.gps != null && state.gps.gps_connected) { -- cgit v1.2.3 From 6d523ee4dad3b9890d3cf05852459101fe7e26ea Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 21:48:41 -0700 Subject: Fix status update --- ao-tools/altosui/AltosUI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 7befe778..66c75487 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -52,7 +52,7 @@ class AltosFlightStatusTableModel extends AbstractTableModel { public void setValueAt(Object value, int col) { data[col] = value; - fireTableCellUpdated(0, col); + fireTableCellUpdated(1, col); } public void setValueAt(Object value, int row, int col) { @@ -273,7 +273,7 @@ public class AltosUI extends JFrame { if (state.npad >= MIN_PAD_SAMPLES) info_add_row(0, "Ground state", "%s", "ready"); else - info_add_row(0, "Ground state", "waiting for gps (%d)", + info_add_row(0, "Ground state", "wait (%d)", MIN_PAD_SAMPLES - state.npad); info_add_row(0, "Rocket state", "%s", state.data.state); info_add_row(0, "Callsign", "%s", state.data.callsign); -- cgit v1.2.3 From 9cc48698ec14c34d437baad7b6540edc31e9741c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 22:47:40 -0700 Subject: Fix state updates --- ao-tools/altosui/AltosGPS.java | 1 + ao-tools/altosui/AltosState.java | 86 ++++++++++++++++++++---------------- ao-tools/altosui/AltosTelemetry.java | 1 + ao-tools/altosui/AltosUI.java | 50 +++++++++++---------- 4 files changed, 76 insertions(+), 62 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index d242ad57..92a17018 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -111,6 +111,7 @@ public class AltosGPS { int tracking_channels = AltosParse.parse_int(words[i++]); cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels]; for (int chan = 0; chan < tracking_channels; chan++) { + cc_gps_sat[chan] = new AltosGPS.AltosGPSSat(); cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]); cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]); } diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index b3054ce9..aacddfdf 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -26,17 +26,17 @@ import altosui.AltosGPS; public class AltosState { AltosTelemetry data; - AltosTelemetry prev_data; /* derived data */ double report_time; + double time_change; + int tick; + int state; boolean ascent; /* going up? */ - double time_change; - double ground_altitude; double height; double speed; @@ -56,9 +56,6 @@ public class AltosState { double pad_lat; double pad_lon; double pad_alt; - double pad_lat_total; - double pad_lon_total; - double pad_alt_total; int npad; int prev_npad; @@ -75,29 +72,18 @@ public class AltosState { return System.currentTimeMillis() / 1000.0; } - void init (AltosTelemetry cur, AltosTelemetry prev, int prev_npad) { - int i; - double new_height; - double height_change; + void init (AltosTelemetry cur, AltosState prev_state) { + int i; + AltosTelemetry prev; double accel_counts_per_mss; - int tick_count; data = cur; - prev_data = prev; - npad = prev_npad; - tick_count = data.tick; - if (tick_count < prev_data.tick) - tick_count += 65536; - time_change = (tick_count - prev_data.tick) / 100.0; + + ground_altitude = AltosConvert.cc_barometer_to_altitude(data.ground_pres); + height = AltosConvert.cc_barometer_to_altitude(data.flight_pres) - ground_altitude; report_time = aoview_time(); - ground_altitude = AltosConvert.cc_pressure_to_altitude(data.ground_pres); - new_height = AltosConvert.cc_pressure_to_altitude(data.flight_pres) - ground_altitude; - height_change = new_height - height; - height = new_height; - if (time_change > 0) - baro_speed = (baro_speed * 3 + (height_change / time_change)) / 4.0; accel_counts_per_mss = ((data.accel_minus_g - data.accel_plus_g) / 2.0) / 9.80665; acceleration = (data.ground_accel - data.flight_accel) / accel_counts_per_mss; speed = data.flight_vel / (accel_counts_per_mss * 100.0); @@ -105,17 +91,46 @@ public class AltosState { drogue_sense = AltosConvert.cc_ignitor_to_voltage(data.drogue); main_sense = AltosConvert.cc_ignitor_to_voltage(data.main); battery = AltosConvert.cc_battery_to_voltage(data.batt); + tick = data.tick; state = data.state(); + + if (prev_state != null) { + + /* Preserve any existing gps data */ + npad = prev_state.npad; + gps = prev_state.gps; + pad_lat = prev_state.pad_lat; + pad_lon = prev_state.pad_lon; + pad_alt = prev_state.pad_alt; + + /* make sure the clock is monotonic */ + while (tick < prev_state.tick) + tick += 65536; + + time_change = (tick - prev_state.tick) / 100.0; + + /* compute barometric speed */ + + double height_change = height - prev_state.height; + if (time_change > 0) + baro_speed = (prev_state.baro_speed * 3 + (height_change / time_change)) / 4.0; + else + baro_speed = prev_state.baro_speed; + } else { + npad = 0; + gps = null; + baro_speed = 0; + time_change = 0; + } + if (state == AltosTelemetry.ao_flight_pad) { if (data.gps != null && data.gps.gps_locked && data.gps.nsat >= 4) { npad++; - pad_lat_total += data.gps.lat; - pad_lon_total += data.gps.lon; - pad_alt_total += data.gps.alt; if (npad > 1) { - pad_lat = (pad_lat * 31 + data.gps.lat) / 32.0; - pad_lon = (pad_lon * 31 + data.gps.lon) / 32.0; - pad_alt = (pad_alt * 31 + data.gps.alt) / 32.0; + /* 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; @@ -135,7 +150,8 @@ public class AltosState { if (height > max_height) max_height = height; if (data.gps != null) { - gps = data.gps; + if (gps == null || !gps.gps_locked || data.gps.gps_locked) + gps = data.gps; if (npad > 0 && gps.gps_locked) from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); } @@ -147,16 +163,10 @@ public class AltosState { } public AltosState(AltosTelemetry cur) { - init(cur, cur, 0); + init(cur, null); } public AltosState (AltosTelemetry cur, AltosState prev) { - if (prev == null) - init(cur, cur, 0); - else { - init(cur, prev.data, prev.npad); - if (gps == null) - gps = prev.gps; - } + init(cur, prev); } } diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index 34b4099f..e13b42e2 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -181,5 +181,6 @@ public class AltosTelemetry { AltosParse.word(words[i++], "a-:"); accel_minus_g = AltosParse.parse_int(words[i++]); + gps = new AltosGPS(words, i); } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 66c75487..1c6fd699 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -214,7 +214,7 @@ public class AltosUI extends JFrame { serialLine = new AltosSerial(); serialLine.monitor(new AltosUIMonitor()); int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); - this.setSize(new Dimension (infoValueMetrics.charWidth('0') * 6 * 15, + this.setSize(new Dimension (infoValueMetrics.charWidth('0') * 6 * 20, statusHeight * 4 + infoHeight * 17)); this.validate(); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); @@ -292,22 +292,20 @@ public class AltosUI extends JFrame { info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense); info_add_row(0, "Main", "%9.2f V", state.main_sense); info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude); - if (state.gps != null) - info_add_row(1, "Satellites", "%6d", state.gps.nsat); - else - info_add_row(1, "Satellites", "%6d", 0); - if (state.gps != null && state.gps.gps_locked) { - info_add_row(1, "GPS", "locked"); - } else if (state.gps != null && state.gps.gps_connected) { - info_add_row(1, "GPS", "unlocked"); - } else { + if (state.gps == null) { info_add_row(1, "GPS", "not available"); - } - if (state.gps != null) { + } else { + if (state.gps.gps_locked) + info_add_row(1, "GPS", "locked"); + else if (state.gps.gps_connected) + info_add_row(1, "GPS", "unlocked"); + else + info_add_row(1, "GPS", "missing"); + info_add_row(1, "Satellites", "%6d", state.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", "%d", state.gps.alt); - info_add_row(1, "GPS height", "%d", state.gps_height); + info_add_row(1, "GPS height", "%6.0f", state.gps_height); info_add_row(1, "GPS date", "%04d-%02d-%02d", state.gps.gps_time.year, state.gps.gps_time.month, @@ -321,17 +319,21 @@ public class AltosUI extends JFrame { state.gps.course); info_add_row(1, "GPS climb rate", "%7.1fm/s", state.gps.climb_rate); - info_add_row(1, "GPS precision", "%4.1f(hdop) %3dm(h) %3dm(v)", - state.gps.hdop, state.gps.h_error, state.gps.v_error); - } - if (state.npad > 0) { - info_add_row(1, "Distance from pad", "%5.0fm", state.from_pad.distance); - info_add_row(1, "Direction from pad", "%4.0f°", state.from_pad.bearing); - info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); - info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); - info_add_row(1, "Pad GPS alt", "%gm", state.pad_alt); - } - if (state.gps != null && state.gps.gps_connected) { + info_add_row(1, "GPS hdop", "%4.1f", state.gps.hdop); + info_add_row(1, "GPS error", "%3dm(h) %3dm(v)", + state.gps.h_error, state.gps.v_error); + if (state.npad > 0) { + if (state.from_pad != null) { + info_add_row(1, "Distance from pad", "%5.0fm", state.from_pad.distance); + info_add_row(1, "Direction from pad", "%4.0f°", state.from_pad.bearing); + } else { + info_add_row(1, "Distance from pad", "unknown"); + info_add_row(1, "Direction from pad", "unknown"); + } + info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); + info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); + info_add_row(1, "Pad GPS alt", "%gm", state.pad_alt); + } int nsat_vis = 0; int c; -- cgit v1.2.3 From 3f9b66b307ee88172151e3bee58e50f5acbde109 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 23:00:30 -0700 Subject: Clean up GPS data formatting --- ao-tools/altosui/AltosUI.java | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 1c6fd699..599c5aec 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -295,55 +295,55 @@ public class AltosUI extends JFrame { if (state.gps == null) { info_add_row(1, "GPS", "not available"); } else { - if (state.gps.gps_locked) - info_add_row(1, "GPS", "locked"); - else if (state.gps.gps_connected) - info_add_row(1, "GPS", "unlocked"); + if (state.data.gps.gps_locked) + info_add_row(1, "GPS", " locked"); + else if (state.data.gps.gps_connected) + info_add_row(1, "GPS", " unlocked"); else - info_add_row(1, "GPS", "missing"); + info_add_row(1, "GPS", " missing"); info_add_row(1, "Satellites", "%6d", state.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", "%d", state.gps.alt); + 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, "GPS date", "%04d-%02d-%02d", - state.gps.gps_time.year, - state.gps.gps_time.month, - state.gps.gps_time.day); - info_add_row(1, "GPS time", "%02d:%02d:%02d", - state.gps.gps_time.hour, - state.gps.gps_time.minute, - state.gps.gps_time.second); - info_add_row(1, "GPS ground speed", "%7.1fm/s %d°", + info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°", state.gps.ground_speed, state.gps.course); - info_add_row(1, "GPS climb rate", "%7.1fm/s", + info_add_row(1, "GPS climb rate", "%8.1f m/s", state.gps.climb_rate); - info_add_row(1, "GPS hdop", "%4.1f", state.gps.hdop); - info_add_row(1, "GPS error", "%3dm(h) %3dm(v)", + info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop); + info_add_row(1, "GPS error", "%6d m(h)%3d m(v)", state.gps.h_error, state.gps.v_error); if (state.npad > 0) { if (state.from_pad != null) { - info_add_row(1, "Distance from pad", "%5.0fm", state.from_pad.distance); - info_add_row(1, "Direction from pad", "%4.0f°", state.from_pad.bearing); + info_add_row(1, "Distance from pad", "%6.0f m", state.from_pad.distance); + info_add_row(1, "Direction from pad", "%6.0f°", state.from_pad.bearing); } else { info_add_row(1, "Distance from pad", "unknown"); info_add_row(1, "Direction from pad", "unknown"); } info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); - info_add_row(1, "Pad GPS alt", "%gm", state.pad_alt); + info_add_row(1, "Pad GPS alt", "%9.2fm", state.pad_alt); } + info_add_row(1, "GPS date", "%04d-%02d-%02d", + state.gps.gps_time.year, + state.gps.gps_time.month, + state.gps.gps_time.day); + info_add_row(1, "GPS time", " %02d:%02d:%02d", + state.gps.gps_time.hour, + state.gps.gps_time.minute, + state.gps.gps_time.second); int nsat_vis = 0; int c; if (state.gps.cc_gps_sat == null) - info_add_row(2, "Satellites Visible", "%d", 0); + info_add_row(2, "Satellites Visible", "%4d", 0); else { - info_add_row(2, "Satellites Visible", "%d", state.gps.cc_gps_sat.length); + info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length); for (c = 0; c < state.gps.cc_gps_sat.length; c++) { info_add_row(2, "Satellite id,C/N0", - "%3d,%2d", + "%4d, %4d", state.gps.cc_gps_sat[c].svid, state.gps.cc_gps_sat[c].c_n0); } -- cgit v1.2.3 From ebd49d4ec6b0b60c85b2de45cfe2e36add8fe9bf Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 23:05:40 -0700 Subject: Report current gps nsat, not last locked nsat --- ao-tools/altosui/AltosUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 599c5aec..2cf326fc 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -301,7 +301,7 @@ public class AltosUI extends JFrame { info_add_row(1, "GPS", " unlocked"); else info_add_row(1, "GPS", " missing"); - info_add_row(1, "Satellites", "%6d", state.gps.nsat); + 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); -- cgit v1.2.3 From 4ad062969ae8a608b8428620579bbe114e580a11 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 23:20:38 -0700 Subject: Remove GPS data missing from skytraq. Save max height/accel/speed --- ao-tools/altosui/AltosState.java | 3 +++ ao-tools/altosui/AltosUI.java | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index aacddfdf..192011d0 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -102,6 +102,9 @@ public class AltosState { 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_speed = prev_state.max_speed; /* make sure the clock is monotonic */ while (tick < prev_state.tick) diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 2cf326fc..91278afe 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -306,14 +306,19 @@ public class AltosUI extends JFrame { 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, "GPS ground speed", "%8.1f m/s %3d°", - state.gps.ground_speed, - state.gps.course); - info_add_row(1, "GPS climb rate", "%8.1f m/s", - state.gps.climb_rate); + + /* The SkyTraq GPS doesn't report these values */ + if (false) { + info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°", + state.gps.ground_speed, + state.gps.course); + info_add_row(1, "GPS climb rate", "%8.1f m/s", + state.gps.climb_rate); + info_add_row(1, "GPS error", "%6d m(h)%3d m(v)", + state.gps.h_error, state.gps.v_error); + } info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop); - info_add_row(1, "GPS error", "%6d m(h)%3d m(v)", - state.gps.h_error, state.gps.v_error); + if (state.npad > 0) { if (state.from_pad != null) { info_add_row(1, "Distance from pad", "%6.0f m", state.from_pad.distance); @@ -324,7 +329,7 @@ public class AltosUI extends JFrame { } info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); - info_add_row(1, "Pad GPS alt", "%9.2fm", state.pad_alt); + info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt); } info_add_row(1, "GPS date", "%04d-%02d-%02d", state.gps.gps_time.year, -- cgit v1.2.3 From 4bea4c327e002ce8f88218f0d840af7c1521bc35 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 2 Apr 2010 23:25:02 -0700 Subject: Remove unused cell renderer class --- ao-tools/altosui/AltosUI.java | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 91278afe..8880618b 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -70,26 +70,6 @@ class AltosFlightStatusTableModel extends AbstractTableModel { } } -class AltosFlightStatusCellRenderer extends DefaultTableCellRenderer { - - static Font statusFont = new Font("SansSerif", Font.BOLD, 24); - - @Override public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, - boolean hasFocus, int row, int column) - { - Component cell = super.getTableCellRendererComponent - (table, value, isSelected, hasFocus, row, column); - System.out.println("Selecting new font for cell " + row + " " + column + " " + statusFont); - cell.setFont(statusFont); - return cell; - } - - public AltosFlightStatusCellRenderer () { - super(); - System.out.println("Made a status cell renderer\n"); - } -} - class AltosFlightInfoTableModel extends AbstractTableModel { private String[] columnNames = {"Field", "Value"}; @@ -437,8 +417,11 @@ public class AltosUI extends JFrame { filename = name; } + /* Run the replay in a separate thread + * so that the UI can update + */ public void run() { - String line; + String line; AltosState state = null; try { while ((line = readline(replay)) != null) { @@ -446,6 +429,8 @@ public class AltosUI extends JFrame { AltosTelemetry t = new AltosTelemetry(line); state = new AltosState(t, state); show(state); + + /* Make it run in realtime after the rocket leaves the pad */ try { if (state.state > AltosTelemetry.ao_flight_pad) Thread.sleep((int) (state.time_change * 1000)); -- cgit v1.2.3 From 3d34c488c5b71020d86f83156fd821fd860bf214 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 3 Apr 2010 00:02:44 -0700 Subject: Make .jar file --- ao-tools/altosui/Makefile | 13 ++++++++++--- ao-tools/altosui/Manifest.txt | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 ao-tools/altosui/Manifest.txt (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 1fb964d6..74b29f7f 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -10,11 +10,15 @@ CLASSFILES=\ AltosSerial.class \ AltosState.class \ AltosTelemetry.class \ - AltosUI.class + AltosUI.class \ + AltosDevice.class \ + AltosDeviceName.class \ + AltosDeviceLinux.class \ + AltosDeviceNameLinux.class JAVAFLAGS=-Xlint:unchecked -all: $(CLASSFILES) altosui +all: $(CLASSFILES) altosui altosui.jar .java.class: javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java @@ -24,5 +28,8 @@ altosui: Makefile echo exec java -cp '"$(CLASSPATH)"' altosui/AltosUI) > $@ chmod +x $@ +altosui.jar: $(CLASSFILES) Manifest.txt + cd .. && jar cfm altosui/$@ altosui/Manifest.txt altosui/*.class + clean: - rm -f *.class \ No newline at end of file + rm -f *.class diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt new file mode 100644 index 00000000..0305fcfb --- /dev/null +++ b/ao-tools/altosui/Manifest.txt @@ -0,0 +1 @@ +Main-Class: altosui.AltosUI -- cgit v1.2.3 From 0e7abc9fedec568b431c983d3df1b0b29f4f10e3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 4 Apr 2010 16:32:04 -0700 Subject: Use RXTX for serial comm. Add logdir preference saving --- ao-tools/altosui/AltosSerial.java | 34 ++++++++--- ao-tools/altosui/AltosUI.java | 124 ++++++++++++++++++++++++++++++-------- 2 files changed, 126 insertions(+), 32 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 9537f190..305222dc 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -26,6 +26,7 @@ import java.io.*; import java.util.concurrent.LinkedBlockingQueue; import java.util.LinkedList; import java.util.Iterator; +import gnu.io.*; import altosui.AltosSerialMonitor; /* @@ -34,7 +35,7 @@ import altosui.AltosSerialMonitor; * threads. */ class AltosSerialReader implements Runnable { - FileInputStream serial_in; + InputStream serial_in; LinkedBlockingQueue monitor_queue; LinkedBlockingQueue reply_queue; Thread input_thread; @@ -109,6 +110,12 @@ class AltosSerialReader implements Runnable { input_thread = new Thread(this); input_thread.start(); } + public void open(CommPort c) throws IOException { + close(); + serial_in = c.getInputStream(); + input_thread = new Thread(this); + input_thread.start(); + } public AltosSerialReader () { serial_in = null; input_thread = null; @@ -120,7 +127,7 @@ class AltosSerialReader implements Runnable { } public class AltosSerial implements Runnable { - FileOutputStream serial_out = null; + OutputStream serial_out = null; Thread monitor_thread = null; AltosSerialReader reader = null; LinkedList callbacks; @@ -188,11 +195,19 @@ public class AltosSerial implements Runnable { public void open(File serial_name) throws FileNotFoundException { reader.open(serial_name); serial_out = new FileOutputStream(serial_name); - try { - serial_out.write('?'); - serial_out.write('\r'); - } catch (IOException e) { - } + } + + public void open(CommPort comm_port) throws IOException { + reader.open(comm_port); + serial_out = comm_port.getOutputStream(); + } + + public void connect(String port_name) throws IOException, NoSuchPortException, PortInUseException { + System.out.printf("Opening serial port %s\n", port_name); + CommPort comm_port = new RXTXPort(port_name); +// CommPortIdentifier port_identifier = CommPortIdentifier.getPortIdentifier(port_name); +// CommPort comm_port = port_identifier.open("Altos", 1000); + open(comm_port); } void init() { @@ -208,4 +223,9 @@ public class AltosSerial implements Runnable { init(); open(serial_name); } + + public AltosSerial(CommPort comm_port) throws IOException { + init(); + open(comm_port); + } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 8880618b..ab5f1828 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -25,7 +25,8 @@ import javax.swing.table.*; import java.io.*; import java.util.*; import java.text.*; -import gnu.io.CommPortIdentifier; +import java.util.prefs.*; +import gnu.io.*; import altosui.AltosSerial; import altosui.AltosSerialMonitor; @@ -337,32 +338,63 @@ public class AltosUI extends JFrame { info_finish(); } + /* User Preferences */ + Preferences altosui_preferences = Preferences.userNodeForPackage(this.getClass()); - final JFileChooser deviceChooser = new JFileChooser(); - final JFileChooser logdirChooser = new JFileChooser(); - final String logdirName = "TeleMetrum"; - File logdir = null; + /* Log directory */ + private File logdir = null; - private void setLogdir() { - if (logdir == null) - logdir = new File(logdirChooser.getCurrentDirectory(), logdirName); - logdirChooser.setCurrentDirectory(logdir); + /* logdir preference name */ + final static String logdirPreference = "LOGDIR"; + + /* Default logdir is ~/TeleMetrum */ + final static String logdirName = "TeleMetrum"; + + /* Initialize logdir from preferences */ + { + String logdir_string = altosui_preferences.get(logdirPreference, null); + if (logdir_string != null) + logdir = new File(logdir_string); + else + /* a hack -- make the file chooser tell us what the default directory + * would be and stick our logdir in a subdirectory of that. + */ + logdir = new File(new JFileChooser().getCurrentDirectory(), logdirName); + } + + private void set_logdir(File new_logdir) { + logdir = new_logdir; + System.out.printf("Set logdir to %s\n", logdir.toString()); + synchronized (altosui_preferences) { + altosui_preferences.put(logdirPreference, logdir.getPath()); + try { + altosui_preferences.flush(); + } catch (BackingStoreException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + altosui_preferences.absolutePath(), + "Cannot save prefernces", + JOptionPane.ERROR_MESSAGE); + } + } } - private void makeLogdir() { - setLogdir(); - if (!logdir.exists()) { - if (!logdir.mkdirs()) + private boolean check_dir(File dir) { + if (!dir.exists()) { + if (!dir.mkdirs()) { JOptionPane.showMessageDialog(AltosUI.this, - logdir.getName(), + dir.getName(), "Cannot create directory", JOptionPane.ERROR_MESSAGE); - } else if (!logdir.isDirectory()) { + return false; + } + } else if (!dir.isDirectory()) { JOptionPane.showMessageDialog(AltosUI.this, - logdir.getName(), + dir.getName(), "Is not a directory", JOptionPane.ERROR_MESSAGE); + return false; } + return true; } private void PickSerialDevice() { @@ -374,18 +406,33 @@ public class AltosUI extends JFrame { } private void ConnectToDevice() { - PickSerialDevice(); - int returnVal = deviceChooser.showOpenDialog(AltosUI.this); + JFileChooser device_chooser = new JFileChooser(); + int returnVal = device_chooser.showOpenDialog(AltosUI.this); if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = deviceChooser.getSelectedFile(); + File file = device_chooser.getSelectedFile(); try { - serialLine.open(file); + serialLine.connect(file.getCanonicalPath()); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, file.getName(), "Cannot open serial port", JOptionPane.ERROR_MESSAGE); + } catch (NoSuchPortException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + file.getName(), + "No such serial port", + JOptionPane.ERROR_MESSAGE); + } catch (PortInUseException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + file.getName(), + "Port in use", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + file.getName(), + "Unkonwn I/O error", + JOptionPane.ERROR_MESSAGE); } } } @@ -456,14 +503,19 @@ public class AltosUI extends JFrame { } } + /* + * Replay a flight from telemetry data + */ private void Replay() { - setLogdir(); - logdirChooser.setDialogTitle("Select Telemetry File"); - logdirChooser.setFileFilter(new FileNameExtensionFilter("Telemetry file", "telem")); - int returnVal = logdirChooser.showOpenDialog(AltosUI.this); + JFileChooser logfile_chooser = new JFileChooser(); + + logfile_chooser.setDialogTitle("Select Telemetry File"); + logfile_chooser.setFileFilter(new FileNameExtensionFilter("Telemetry file", "telem")); + logfile_chooser.setCurrentDirectory(logdir); + int returnVal = logfile_chooser.showOpenDialog(AltosUI.this); if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = logdirChooser.getSelectedFile(); + File file = logfile_chooser.getSelectedFile(); if (file == null) System.out.println("No file selected?"); String filename = file.getName(); @@ -480,9 +532,30 @@ public class AltosUI extends JFrame { } } + /* + * Connect to TeleMetrum, either directly or through + * a TeleDongle over the packet link + */ private void SaveFlightData() { } + /* Configure the log directory. This is where all telemetry and eeprom files + * will be written to, and where replay will look for telemetry files + */ + private void ConfigureLog() { + JFileChooser logdir_chooser = new JFileChooser(); + + logdir_chooser.setDialogTitle("Configure Data Logging Directory"); + logdir_chooser.setCurrentDirectory(logdir.getParentFile()); + logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + + if (logdir_chooser.showDialog(AltosUI.this, "Select Directory") == JFileChooser.APPROVE_OPTION) { + File dir = logdir_chooser.getSelectedFile(); + if (check_dir(dir)) + set_logdir(dir); + } + } + private void createMenu() { JMenuBar menubar = new JMenuBar(); JMenu menu; @@ -562,6 +635,7 @@ public class AltosUI extends JFrame { item = new JMenuItem("Configure Log",KeyEvent.VK_C); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + ConfigureLog(); } }); menu.add(item); -- cgit v1.2.3 From d22ba55ae0e056530a727df50f14ad853d79a2c8 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 4 Apr 2010 20:55:18 -0700 Subject: Clean up some altosui comments --- ao-tools/altosui/AltosUI.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index ab5f1828..a51ca1eb 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -532,8 +532,7 @@ public class AltosUI extends JFrame { } } - /* - * Connect to TeleMetrum, either directly or through + /* Connect to TeleMetrum, either directly or through * a TeleDongle over the packet link */ private void SaveFlightData() { @@ -556,6 +555,8 @@ public class AltosUI extends JFrame { } } + /* Create the AltosUI menus + */ private void createMenu() { JMenuBar menubar = new JMenuBar(); JMenu menu; -- cgit v1.2.3 From cc600a0389720bc7e435dbda8bec080ef19e0c58 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 5 Apr 2010 22:21:46 -0700 Subject: Add Linux device discovery AltosDeviceLinux.java scans /proc to locate suitable devices. This will be hooked up to the UI shortly. --- ao-tools/altosui/AltosDevice.java | 30 ++++++ ao-tools/altosui/AltosDeviceLinux.java | 171 +++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 4 + ao-tools/altosui/Makefile | 2 - 4 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 ao-tools/altosui/AltosDevice.java create mode 100644 ao-tools/altosui/AltosDeviceLinux.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java new file mode 100644 index 00000000..66800c5c --- /dev/null +++ b/ao-tools/altosui/AltosDevice.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; +import java.lang.*; +import java.util.*; + +public class AltosDevice { + String tty; /* suitable to be passed to AltosSerial.connect */ + String manufacturer; + String product; + int serial; + int idProduct; + int idVendor; + +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosDeviceLinux.java b/ao-tools/altosui/AltosDeviceLinux.java new file mode 100644 index 00000000..b7774627 --- /dev/null +++ b/ao-tools/altosui/AltosDeviceLinux.java @@ -0,0 +1,171 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; +import java.lang.*; +import java.io.*; +import java.util.*; +import altosui.AltosDeviceName; +import altosui.AltosDeviceNameLinux; +import altosui.AltosDevice; + +public class AltosDeviceLinux extends AltosDevice { + + String load_string(File file) { + try { + FileInputStream in = new FileInputStream(file); + String result = ""; + int c; + try { + while ((c = in.read()) != -1) { + if (c == '\n') + break; + result = result + (char) c; + } + return result; + } catch (IOException ee) { + return ""; + } + } catch (FileNotFoundException ee) { + return ""; + } + } + String load_string(File dir, String name) { + return load_string(new File(dir, name)); + } + + int load_hex(File file) { + try { + return Integer.parseInt(load_string(file).trim(), 16); + } catch (NumberFormatException ee) { + return -1; + } + } + + int load_hex(File dir, String name) { + return load_hex(new File(dir, name)); + } + + int load_dec(File file) { + try { + return Integer.parseInt(load_string(file).trim()); + } catch (NumberFormatException ee) { + return -1; + } + } + + int load_dec(File dir, String name) { + return load_dec(new File(dir, name)); + } + + String usb_tty(File sys_dir) { + String base = sys_dir.getName(); + int num_configs = load_hex(sys_dir, "bNumConfigurations"); + int num_inters = load_hex(sys_dir, "bNumInterfaces"); + for (int config = 1; config <= num_configs; config++) { + for (int inter = 0; inter < num_inters; inter++) { + String endpoint_base = String.format("%s:%d.%d", + base, config, inter); + File endpoint_full = new File(sys_dir, endpoint_base); + + File[] namelist; + + /* Check for tty:ttyACMx style names */ + class tty_colon_filter implements FilenameFilter { + public boolean accept(File dir, String name) { + return name.startsWith("tty:"); + } + } + namelist = endpoint_full.listFiles(new tty_colon_filter()); + if (namelist != null && namelist.length > 0) + return new File ("/dev", namelist[0].getName().substring(4)).getPath(); + + /* Check for tty/ttyACMx style names */ + class tty_filter implements FilenameFilter { + public boolean accept(File dir, String name) { + return name.startsWith("tty"); + } + } + File tty_dir = new File(endpoint_full, "tty"); + namelist = tty_dir.listFiles(new tty_filter()); + if (namelist != null && namelist.length > 0) + return new File ("/dev", namelist[0].getName()).getPath(); + } + } + return null; + } + + public AltosDeviceLinux (File sys) { + sys = sys; + manufacturer = load_string(sys, "manufacturer"); + product = load_string(sys, "product"); + serial = load_dec(sys, "serial"); + idProduct = load_hex(sys, "idProduct"); + idVendor = load_hex(sys, "idVendor"); + tty = usb_tty(sys); + } + + public String toString() { + return manufacturer + " " + product + " " + serial + " " + idProduct + " " + idVendor + " " + tty; + } + static public AltosDeviceLinux[] list() { + LinkedList devices = new LinkedList(); + + class dev_filter implements FilenameFilter{ + public boolean accept(File dir, String name) { + for (int i = 0; i < name.length(); i++) { + char c = name.charAt(i); + if (Character.isDigit(c)) + continue; + if (c == '-') + continue; + if (c == '.' && i != 1) + continue; + return false; + } + return true; + } + } + + File usb_devices = new File("/sys/bus/usb/devices"); + File[] devs = usb_devices.listFiles(new dev_filter()); + if (devs != null) { + for (int e = 0; e < devs.length; e++) { + AltosDeviceLinux dev = new AltosDeviceLinux(devs[e]); + if (dev.idVendor == 0xfffe && dev.tty != null) { + devices.add(dev); + } + } + } + AltosDeviceLinux[] foo = new AltosDeviceLinux[devices.size()]; + for (int e = 0; e < devices.size(); e++) { + foo[e] = devices.get(e); + System.out.println("Device " + foo[e]); + } + return foo; + } + + static public AltosDeviceLinux[] list(String model) { + AltosDeviceLinux[] devices = list(); + LinkedList subset = new LinkedList(); + for (int i = 0; i < devices.length; i++) { + if (devices[i].product.startsWith(model)) + subset.add(devices[i]); + } + return (AltosDeviceLinux[]) subset.toArray(); + } +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index a51ca1eb..54016ac5 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -682,6 +682,10 @@ public class AltosUI extends JFrame { } public static void main(final String[] args) { + AltosDevice[] devices = AltosDeviceLinux.list(); + for (int i = 0; i < devices.length; i++) + System.out.printf("Model: %s Serial: %d Tty: %s\n", + devices[i].product, devices[i].serial, devices[i].tty); AltosUI altosui = new AltosUI(); altosui.setVisible(true); } diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 74b29f7f..fcb259eb 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -12,9 +12,7 @@ CLASSFILES=\ AltosTelemetry.class \ AltosUI.class \ AltosDevice.class \ - AltosDeviceName.class \ AltosDeviceLinux.class \ - AltosDeviceNameLinux.class JAVAFLAGS=-Xlint:unchecked -- cgit v1.2.3 From c099a67d9ea37e731e0eca318102560281ac240f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 5 Apr 2010 22:42:05 -0700 Subject: Interrupt running replay thread when starting another replay Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 54016ac5..b2305a21 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -481,7 +481,9 @@ public class AltosUI extends JFrame { try { if (state.state > AltosTelemetry.ao_flight_pad) Thread.sleep((int) (state.time_change * 1000)); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + break; + } } catch (ParseException pp) { JOptionPane.showMessageDialog(AltosUI.this, line, @@ -503,6 +505,7 @@ public class AltosUI extends JFrame { } } + ReplayThread replay_thread; /* * Replay a flight from telemetry data */ @@ -522,7 +525,10 @@ public class AltosUI extends JFrame { try { FileInputStream replay = new FileInputStream(file); ReplayThread thread = new ReplayThread(replay, filename); - thread.start(); + if (thread != null && replay_thread != null && replay_thread.isAlive()) + replay_thread.interrupt(); + replay_thread = thread; + replay_thread.start(); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, filename, -- cgit v1.2.3 From e064d05da87926c19fb665b40fb280fb59328183 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 6 Apr 2010 00:54:52 -0700 Subject: serial port read function cannot be interrupted. poll every 1 second --- ao-tools/altosui/AltosSerial.java | 95 ++++++++++++--------------------------- 1 file changed, 29 insertions(+), 66 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 305222dc..e4cedde2 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -45,7 +45,12 @@ class AltosSerialReader implements Runnable { int c; try { - while ((c = serial_in.read()) != -1) { + for (;;) { + c = serial_in.read(); + if (Thread.interrupted()) + break; + if (c == -1) + continue; if (c == '\r') continue; synchronized(this) { @@ -68,7 +73,9 @@ class AltosSerialReader implements Runnable { } public String get_telem() throws InterruptedException { - return monitor_queue.take(); + String s = monitor_queue.take(); + System.out.println(s); + return s; } public String get_reply() throws InterruptedException { @@ -97,6 +104,7 @@ class AltosSerialReader implements Runnable { } if (input_thread != null) { try { + input_thread.interrupt(); input_thread.join(); } catch (InterruptedException e) { } @@ -112,6 +120,10 @@ class AltosSerialReader implements Runnable { } public void open(CommPort c) throws IOException { close(); + try { + c.enableReceiveTimeout(1000); /* icky. the read method cannot be interrupted */ + } catch (UnsupportedCommOperationException ee) { + } serial_in = c.getInputStream(); input_thread = new Thread(this); input_thread.start(); @@ -126,69 +138,24 @@ class AltosSerialReader implements Runnable { } -public class AltosSerial implements Runnable { +public class AltosSerial { OutputStream serial_out = null; - Thread monitor_thread = null; AltosSerialReader reader = null; - LinkedList callbacks; - - public void run() { - try { - for (;;) { - String s = reader.get_telem(); - synchronized(callbacks) { - Iterator i = callbacks.iterator(); - while (i.hasNext()) { - i.next().data(s); - } - } - } - } catch (InterruptedException e) { - } - } - - boolean need_monitor() { - return reader.opened() && !callbacks.isEmpty(); - } - - void maybe_stop_monitor() { - if (!need_monitor() && monitor_thread != null) { - monitor_thread.interrupt(); - try { - monitor_thread.join(); - } catch (InterruptedException e) { - } finally { - monitor_thread = null; - } - } - } - - void maybe_start_monitor() { - if (need_monitor() && monitor_thread == null) { - monitor_thread = new Thread(this); - monitor_thread.start(); - } - } - public void monitor(AltosSerialMonitor monitor) { - synchronized(callbacks) { - callbacks.add(monitor); - maybe_start_monitor(); - } + public String get_telem() throws InterruptedException { + return reader.get_telem(); } - - public void unmonitor(AltosSerialMonitor monitor) { - synchronized(callbacks) { - callbacks.remove(monitor); - maybe_stop_monitor(); - } - } + CommPort comm_port = null; public void close() { - synchronized(callbacks) { - reader.close(); - maybe_stop_monitor(); + try { + serial_out.close(); + } catch (IOException ee) { + } + reader.close(); + if (comm_port != null) { + comm_port.close(); } } @@ -197,22 +164,18 @@ public class AltosSerial implements Runnable { serial_out = new FileOutputStream(serial_name); } - public void open(CommPort comm_port) throws IOException { - reader.open(comm_port); - serial_out = comm_port.getOutputStream(); + public void open(CommPort c) throws IOException { + reader.open(c); + serial_out = c.getOutputStream(); } public void connect(String port_name) throws IOException, NoSuchPortException, PortInUseException { - System.out.printf("Opening serial port %s\n", port_name); - CommPort comm_port = new RXTXPort(port_name); -// CommPortIdentifier port_identifier = CommPortIdentifier.getPortIdentifier(port_name); -// CommPort comm_port = port_identifier.open("Altos", 1000); + comm_port = new RXTXPort(port_name); open(comm_port); } void init() { reader = new AltosSerialReader(); - callbacks = new LinkedList(); } public AltosSerial() { -- cgit v1.2.3 From a7fc7901cd591c93d9d0cffeec2977ebb17554d4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 6 Apr 2010 00:55:19 -0700 Subject: TD reports "not-connected" when GPS has 0 sats --- ao-tools/altosui/AltosGPS.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index 92a17018..c3b368e2 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -108,7 +108,12 @@ public class AltosGPS { gps_time = new AltosGPSTime(); } AltosParse.word(words[i++], "SAT"); - int tracking_channels = AltosParse.parse_int(words[i++]); + int tracking_channels = 0; + if (words[i].equals("not-connected")) + tracking_channels = 0; + else + tracking_channels = AltosParse.parse_int(words[i]); + i++; cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels]; for (int chan = 0; chan < tracking_channels; chan++) { cc_gps_sat[chan] = new AltosGPS.AltosGPSSat(); -- cgit v1.2.3 From 10330d23518c94a8b791193a97a6cc07b1c9a97c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 6 Apr 2010 00:58:00 -0700 Subject: Enable telemetry monitoring Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDeviceDialog.java | 45 +++++++++ ao-tools/altosui/AltosDeviceLinux.java | 23 ++--- ao-tools/altosui/AltosUI.java | 157 ++++++++++++++++++++------------ ao-tools/altosui/Makefile | 1 + 4 files changed, 157 insertions(+), 69 deletions(-) create mode 100644 ao-tools/altosui/AltosDeviceDialog.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java new file mode 100644 index 00000000..cb1eef8b --- /dev/null +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -0,0 +1,45 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.util.*; +import javax.swing.*; +import altosui.AltosDevice; +import altosui.AltosDeviceLinux; + +public class AltosDeviceDialog { + + static AltosDevice show (JFrame frame, String product) { + AltosDevice[] devices = null; + if (System.getProperty("os.name").startsWith("Linux")) + devices = AltosDeviceLinux.list(product); + if (devices != null & devices.length > 0) { + Object o = JOptionPane.showInputDialog(frame, + "Select a device", + "Device Selection", + JOptionPane.PLAIN_MESSAGE, + null, + devices, + devices[0]); + return (AltosDevice) o; + } else { + return null; + } + } +} diff --git a/ao-tools/altosui/AltosDeviceLinux.java b/ao-tools/altosui/AltosDeviceLinux.java index b7774627..ffc70aff 100644 --- a/ao-tools/altosui/AltosDeviceLinux.java +++ b/ao-tools/altosui/AltosDeviceLinux.java @@ -19,8 +19,6 @@ package altosui; import java.lang.*; import java.io.*; import java.util.*; -import altosui.AltosDeviceName; -import altosui.AltosDeviceNameLinux; import altosui.AltosDevice; public class AltosDeviceLinux extends AltosDevice { @@ -120,7 +118,7 @@ public class AltosDeviceLinux extends AltosDevice { } public String toString() { - return manufacturer + " " + product + " " + serial + " " + idProduct + " " + idVendor + " " + tty; + return String.format("%-20s %6d %-15s", product, serial, tty == null ? "" : tty); } static public AltosDeviceLinux[] list() { LinkedList devices = new LinkedList(); @@ -152,20 +150,23 @@ public class AltosDeviceLinux extends AltosDevice { } } AltosDeviceLinux[] foo = new AltosDeviceLinux[devices.size()]; - for (int e = 0; e < devices.size(); e++) { + for (int e = 0; e < devices.size(); e++) foo[e] = devices.get(e); - System.out.println("Device " + foo[e]); - } return foo; } static public AltosDeviceLinux[] list(String model) { AltosDeviceLinux[] devices = list(); - LinkedList subset = new LinkedList(); - for (int i = 0; i < devices.length; i++) { - if (devices[i].product.startsWith(model)) - subset.add(devices[i]); + if (model != null) { + LinkedList subset = new LinkedList(); + for (int i = 0; i < devices.length; i++) { + if (devices[i].product.startsWith(model)) + subset.add(devices[i]); + } + devices = new AltosDeviceLinux[subset.size()]; + for (int e = 0; e < subset.size(); e++) + devices[e] = subset.get(e); } - return (AltosDeviceLinux[]) subset.toArray(); + return devices; } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index b2305a21..7f008f3a 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -32,12 +32,7 @@ import altosui.AltosSerial; import altosui.AltosSerialMonitor; import altosui.AltosTelemetry; import altosui.AltosState; - -class AltosUIMonitor implements AltosSerialMonitor { - public void data(String data) { - System.out.println(data); - } -} +import altosui.AltosDeviceDialog; class AltosFlightStatusTableModel extends AbstractTableModel { private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; @@ -193,7 +188,6 @@ public class AltosUI extends JFrame { createMenu(); serialLine = new AltosSerial(); - serialLine.monitor(new AltosUIMonitor()); int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); this.setSize(new Dimension (infoValueMetrics.charWidth('0') * 6 * 20, statusHeight * 4 + infoHeight * 17)); @@ -405,38 +399,94 @@ public class AltosUI extends JFrame { } } + class DisplayThread extends Thread { + String read() throws InterruptedException { return null; } + + void close() { } + + void update(AltosState state) throws InterruptedException { } + + public void run() { + String line; + AltosState state = null; + + info_reset(); + info_finish(); + try { + while ((line = read()) != null) { + try { + AltosTelemetry t = new AltosTelemetry(line); + state = new AltosState(t, state); + update(state); + show(state); + } catch (ParseException pp) { + System.out.printf("Parse error on %s\n", line); + System.out.println("exception " + pp); + } + } + } catch (InterruptedException ee) { + } finally { + close(); + } + } + } + + class DeviceThread extends DisplayThread { + AltosSerial serial; + + String read() throws InterruptedException { + System.out.println("Waiting for telemetry"); + String s = serial.get_telem(); + System.out.println("Got telemetry " + s); + return s; + } + + void close() { + serial.close(); + System.out.println("DisplayThread done"); + } + + public DeviceThread(AltosSerial s) { + serial = s; + } + } + private void ConnectToDevice() { - JFileChooser device_chooser = new JFileChooser(); - int returnVal = device_chooser.showOpenDialog(AltosUI.this); + AltosDevice device = AltosDeviceDialog.show(AltosUI.this, "TeleDongle"); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = device_chooser.getSelectedFile(); + if (device != null) { try { - serialLine.connect(file.getCanonicalPath()); + serialLine.connect(device.tty); + DeviceThread thread = new DeviceThread(serialLine); + run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, - file.getName(), + device.tty, "Cannot open serial port", JOptionPane.ERROR_MESSAGE); } catch (NoSuchPortException ee) { JOptionPane.showMessageDialog(AltosUI.this, - file.getName(), + device.tty, "No such serial port", JOptionPane.ERROR_MESSAGE); } catch (PortInUseException ee) { JOptionPane.showMessageDialog(AltosUI.this, - file.getName(), + device.tty, "Port in use", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, - file.getName(), + device.tty, "Unkonwn I/O error", JOptionPane.ERROR_MESSAGE); } } } + void DisconnectFromDevice () { + stop_display(); + } + String readline(FileInputStream s) throws IOException { int c; String line = ""; @@ -455,7 +505,7 @@ public class AltosUI extends JFrame { * Open an existing telemetry file and replay it in realtime */ - class ReplayThread extends Thread { + class ReplayThread extends DisplayThread { FileInputStream replay; String filename; @@ -464,48 +514,46 @@ public class AltosUI extends JFrame { filename = name; } - /* Run the replay in a separate thread - * so that the UI can update - */ - public void run() { - String line; - AltosState state = null; + String read() { try { - while ((line = readline(replay)) != null) { - try { - AltosTelemetry t = new AltosTelemetry(line); - state = new AltosState(t, state); - show(state); - - /* Make it run in realtime after the rocket leaves the pad */ - try { - if (state.state > AltosTelemetry.ao_flight_pad) - Thread.sleep((int) (state.time_change * 1000)); - } catch (InterruptedException e) { - break; - } - } catch (ParseException pp) { - JOptionPane.showMessageDialog(AltosUI.this, - line, - "error parsing", - JOptionPane.ERROR_MESSAGE); - break; - } - } + return readline(replay); } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, filename, "error reading", JOptionPane.ERROR_MESSAGE); - } finally { - try { - replay.close(); - } catch (IOException e) {} + } + return null; + } + + void close () { + try { + replay.close(); + } catch (IOException ee) { } } + + void update(AltosState state) throws InterruptedException { + /* Make it run in realtime after the rocket leaves the pad */ + if (state.state > AltosTelemetry.ao_flight_pad) + Thread.sleep((int) (state.time_change * 1000)); + } + } + + Thread display_thread; + + private void stop_display() { + if (display_thread != null && display_thread.isAlive()) + display_thread.interrupt(); + display_thread = null; + } + + private void run_display(Thread thread) { + stop_display(); + display_thread = thread; + display_thread.start(); } - ReplayThread replay_thread; /* * Replay a flight from telemetry data */ @@ -525,10 +573,7 @@ public class AltosUI extends JFrame { try { FileInputStream replay = new FileInputStream(file); ReplayThread thread = new ReplayThread(replay, filename); - if (thread != null && replay_thread != null && replay_thread.isAlive()) - replay_thread.interrupt(); - replay_thread = thread; - replay_thread.start(); + run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, filename, @@ -603,7 +648,7 @@ public class AltosUI extends JFrame { item = new JMenuItem("Disconnect from Device",KeyEvent.VK_D); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - serialLine.close(); + DisconnectFromDevice(); } }); menu.add(item); @@ -688,10 +733,6 @@ public class AltosUI extends JFrame { } public static void main(final String[] args) { - AltosDevice[] devices = AltosDeviceLinux.list(); - for (int i = 0; i < devices.length; i++) - System.out.printf("Model: %s Serial: %d Tty: %s\n", - devices[i].product, devices[i].serial, devices[i].tty); AltosUI altosui = new AltosUI(); altosui.setVisible(true); } diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index fcb259eb..fbe0a5eb 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -13,6 +13,7 @@ CLASSFILES=\ AltosUI.class \ AltosDevice.class \ AltosDeviceLinux.class \ + AltosDeviceDialog.class JAVAFLAGS=-Xlint:unchecked -- cgit v1.2.3 From a4356b9bcf679c4d7b88fbbad77a98ecb0f80098 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 8 Apr 2010 13:30:16 -0700 Subject: Use 16-bit flite voice (which appears to have changed symbols recently) --- ao-tools/ao-view/aoview_flite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_flite.c b/ao-tools/ao-view/aoview_flite.c index bc702b0f..00e6c9de 100644 --- a/ao-tools/ao-view/aoview_flite.c +++ b/ao-tools/ao-view/aoview_flite.c @@ -20,7 +20,7 @@ #include "aoview.h" #include -cst_voice *register_cmu_us_kal(); +cst_voice *register_cmu_us_kal16(); static cst_voice *voice; static FILE *pipe_write; @@ -118,7 +118,7 @@ aoview_flite_start(void) if (!once) { flite_init(); - voice = register_cmu_us_kal(); + voice = register_cmu_us_kal16(); if (!voice) { perror("register voice"); exit(1); -- cgit v1.2.3 From 97f4874d19ec05c81a04a3ecd06abffcf7fbfafc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 22 Apr 2010 16:25:35 -0700 Subject: More ALtosUI changes --- ao-tools/altosui/AltosSerial.java | 39 ++++++++++++++++++++++++--------------- ao-tools/altosui/AltosUI.java | 18 ++++++------------ ao-tools/altosui/Makefile | 3 +++ 3 files changed, 33 insertions(+), 27 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index e4cedde2..03ab28c5 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -36,7 +36,7 @@ import altosui.AltosSerialMonitor; */ class AltosSerialReader implements Runnable { InputStream serial_in; - LinkedBlockingQueue monitor_queue; + LinkedList> monitors; LinkedBlockingQueue reply_queue; Thread input_thread; String line; @@ -56,9 +56,12 @@ class AltosSerialReader implements Runnable { synchronized(this) { if (c == '\n') { if (line != "") { - if (line.startsWith("VERSION")) - monitor_queue.put(line); - else + if (line.startsWith("VERSION")) { + for (int e = 0; e < monitors.size(); e++) { + LinkedBlockingQueue q = monitors.get(e); + q.put(line); + } + } else reply_queue.put(line); line = ""; } @@ -72,16 +75,18 @@ class AltosSerialReader implements Runnable { } } - public String get_telem() throws InterruptedException { - String s = monitor_queue.take(); - System.out.println(s); - return s; - } - public String get_reply() throws InterruptedException { return reply_queue.take(); } + public void add_monitor(LinkedBlockingQueue q) { + monitors.add(q); + } + + public void remove_monitor(LinkedBlockingQueue q) { + monitors.remove(q); + } + public void flush () { synchronized(this) { if (!"VERSION".startsWith(line) && !line.startsWith("VERSION")) @@ -132,7 +137,7 @@ class AltosSerialReader implements Runnable { serial_in = null; input_thread = null; line = ""; - monitor_queue = new LinkedBlockingQueue (); + monitors = new LinkedList> (); reply_queue = new LinkedBlockingQueue (); } @@ -142,10 +147,6 @@ public class AltosSerial { OutputStream serial_out = null; AltosSerialReader reader = null; - public String get_telem() throws InterruptedException { - return reader.get_telem(); - } - CommPort comm_port = null; public void close() { @@ -178,6 +179,14 @@ public class AltosSerial { reader = new AltosSerialReader(); } + public void add_monitor(LinkedBlockingQueue q) { + reader.add_monitor(q); + } + + public void remove_monitor(LinkedBlockingQueue q) { + reader.remove_monitor(q); + } + public AltosSerial() { init(); } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 7f008f3a..2952fcc0 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -26,6 +26,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; import gnu.io.*; import altosui.AltosSerial; @@ -391,14 +392,6 @@ public class AltosUI extends JFrame { return true; } - private void PickSerialDevice() { - java.util.Enumeration port_list = CommPortIdentifier.getPortIdentifiers(); - while (port_list.hasMoreElements()) { - CommPortIdentifier identifier = port_list.nextElement(); - System.out.println("Serial port " + identifier.getName()); - } - } - class DisplayThread extends Thread { String read() throws InterruptedException { return null; } @@ -433,21 +426,22 @@ public class AltosUI extends JFrame { class DeviceThread extends DisplayThread { AltosSerial serial; + LinkedBlockingQueue telem; String read() throws InterruptedException { - System.out.println("Waiting for telemetry"); - String s = serial.get_telem(); - System.out.println("Got telemetry " + s); - return s; + return telem.take(); } void close() { serial.close(); + serial.remove_monitor(telem); System.out.println("DisplayThread done"); } public DeviceThread(AltosSerial s) { serial = s; + telem = new LinkedBlockingQueue(); + serial.add_monitor(telem); } } diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index fbe0a5eb..b9f025da 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -3,9 +3,12 @@ CLASSPATH=..:/usr/share/java/* CLASSFILES=\ AltosConvert.class \ + AltosFile.class \ AltosGPS.class \ AltosGreatCircle.class \ + AltosLog.class \ AltosParse.class \ + AltosPreferences.class \ AltosSerialMonitor.class \ AltosSerial.class \ AltosState.class \ -- cgit v1.2.3 From 75d8ffd4eadf31d50b2f58c021530c17ff1bdc66 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 23 Apr 2010 13:53:25 -0700 Subject: Autodetect flite voice registration function Old versions of flite exported the function 'register_cmu_us_kal' while new ones export 'register_cmu_us_kal16'. This patch just checks which one is available and uses that. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview_flite.c | 8 ++++++++ configure.ac | 4 ++++ 2 files changed, 12 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_flite.c b/ao-tools/ao-view/aoview_flite.c index 00e6c9de..abcdc491 100644 --- a/ao-tools/ao-view/aoview_flite.c +++ b/ao-tools/ao-view/aoview_flite.c @@ -21,6 +21,8 @@ #include cst_voice *register_cmu_us_kal16(); +cst_voice *register_cmu_us_kal(); + static cst_voice *voice; static FILE *pipe_write; @@ -118,7 +120,13 @@ aoview_flite_start(void) if (!once) { flite_init(); +#if HAVE_REGISTER_CMU_US_KAL16 voice = register_cmu_us_kal16(); +#else +#if HAVE_REGISTER_CMU_US_KAL + voice = register_cmu_us_kal(); +#endif +#endif if (!voice) { perror("register voice"); exit(1); diff --git a/configure.ac b/configure.ac index d4ddda18..d6c8682b 100644 --- a/configure.ac +++ b/configure.ac @@ -50,6 +50,10 @@ if test "x$HAVE_FLITE_H" = "xyes" -a "x$HAVE_LIBFLITE" = "xyes"; then AC_DEFINE(HAVE_FLITE,1,[Define if the flite library is usable]) AC_SUBST(FLITE_LIBS,"-lflite_cmu_us_kal16 -lflite_usenglish -lflite_cmulex -lflite -lasound -lm") AC_SUBST(FLITE_INCS,-Iflite) + save_LIBS="$LIBS" + LIBS="$LIBS $FLITE_LIBS" + AC_CHECK_FUNCS([register_cmu_us_kal16 register_cmu_us_kal],break) + LIBS="$save_LIBS" fi AM_CONDITIONAL(USE_FLITE,test "x$HAVE_FLITE_H" = "xyes" -a "x$HAVE_LIBFLITE" = "xyes") -- cgit v1.2.3 From 563a9dcdfef42718370c49f16cc2271642b3e055 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 17 May 2010 21:30:57 -0700 Subject: Finish basic flight monitoring UI with voice using FreeTTS This captures telemetry data to log files and presents flight status information in audio form using FreeTTS. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFile.java | 37 ++++++++ ao-tools/altosui/AltosLog.java | 104 ++++++++++++++++++++++ ao-tools/altosui/AltosPreferences.java | 117 +++++++++++++++++++++++++ ao-tools/altosui/AltosState.java | 9 +- ao-tools/altosui/AltosUI.java | 152 ++++++++++++++++++--------------- ao-tools/altosui/AltosVoice.java | 69 +++++++++++++++ ao-tools/altosui/Makefile | 5 +- ao-tools/altosui/voices.txt | 1 + 8 files changed, 415 insertions(+), 79 deletions(-) create mode 100644 ao-tools/altosui/AltosFile.java create mode 100644 ao-tools/altosui/AltosLog.java create mode 100644 ao-tools/altosui/AltosPreferences.java create mode 100644 ao-tools/altosui/AltosVoice.java create mode 100644 ao-tools/altosui/voices.txt (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFile.java b/ao-tools/altosui/AltosFile.java new file mode 100644 index 00000000..c7ee8679 --- /dev/null +++ b/ao-tools/altosui/AltosFile.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.File; +import java.util.*; +import altosui.AltosTelemetry; +import altosui.AltosPreferences; + +class AltosFile extends File { + public AltosFile(AltosTelemetry telem) { + super (AltosPreferences.logdir(), + String.format("%04d-%02d-%02d-serial-%03d-flight-%03d.%s", + Calendar.getInstance().get(Calendar.YEAR), + Calendar.getInstance().get(Calendar.MONTH), + Calendar.getInstance().get(Calendar.DAY_OF_MONTH), + telem.serial, + telem.flight, + "telem")); + } +} diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java new file mode 100644 index 00000000..ec868b9c --- /dev/null +++ b/ao-tools/altosui/AltosLog.java @@ -0,0 +1,104 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.io.*; +import java.lang.*; +import java.util.*; +import java.text.ParseException; +import java.util.concurrent.LinkedBlockingQueue; +import altosui.AltosSerial; +import altosui.AltosFile; + +/* + * This creates a thread to capture telemetry data and write it to + * a log file + */ +class AltosLog implements Runnable { + + LinkedBlockingQueue input_queue; + LinkedBlockingQueue pending_queue; + int serial; + int flight; + FileWriter log_file; + Thread log_thread; + + void close() throws IOException { + if (log_file != null) + log_file.close(); + } + + boolean open (AltosTelemetry telem) throws IOException { + AltosFile a = new AltosFile(telem); + + log_file = new FileWriter(a, true); + if (log_file != null) { + while (!pending_queue.isEmpty()) { + try { + String s = pending_queue.take(); + log_file.write(s); + log_file.write('\n'); + } catch (InterruptedException ie) { + } + } + log_file.flush(); + } + return log_file != null; + } + + public void run () { + try { + for (;;) { + String line = input_queue.take(); + try { + AltosTelemetry telem = new AltosTelemetry(line); + if (telem.serial != serial || telem.flight != flight || log_file == null) { + close(); + serial = telem.serial; + flight = telem.flight; + open(telem); + } + } catch (ParseException pe) { + } + if (log_file != null) { + log_file.write(line); + log_file.write('\n'); + log_file.flush(); + } else + pending_queue.put(line); + } + } catch (InterruptedException ie) { + } catch (IOException ie) { + } + try { + close(); + } catch (IOException ie) { + } + } + + public AltosLog (AltosSerial s) { + pending_queue = new LinkedBlockingQueue (); + input_queue = new LinkedBlockingQueue (); + s.add_monitor(input_queue); + serial = -1; + flight = -1; + log_file = null; + log_thread = new Thread(this); + log_thread.start(); + } +} diff --git a/ao-tools/altosui/AltosPreferences.java b/ao-tools/altosui/AltosPreferences.java new file mode 100644 index 00000000..0296d935 --- /dev/null +++ b/ao-tools/altosui/AltosPreferences.java @@ -0,0 +1,117 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.awt.Component; +import javax.swing.*; +import javax.swing.filechooser.FileSystemView; + +class AltosPreferences { + static Preferences preferences; + + /* logdir preference name */ + final static String logdirPreference = "LOGDIR"; + + /* Default logdir is ~/TeleMetrum */ + final static String logdirName = "TeleMetrum"; + + /* UI Component to pop dialogs up */ + static Component component; + + /* Log directory */ + static File logdir; + + public static void init(Component ui) { + preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); + + component = ui; + + /* Initialize logdir from preferences */ + String logdir_string = preferences.get(logdirPreference, null); + if (logdir_string != null) + logdir = new File(logdir_string); + else { + /* Use the file system view default directory */ + logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName); + if (!logdir.exists()) + logdir.mkdirs(); + } + } + + static void flush_preferences() { + try { + preferences.flush(); + } catch (BackingStoreException ee) { + JOptionPane.showMessageDialog(component, + preferences.absolutePath(), + "Cannot save prefernces", + JOptionPane.ERROR_MESSAGE); + } + } + + public static void set_logdir(File new_logdir) { + logdir = new_logdir; + synchronized (preferences) { + preferences.put(logdirPreference, logdir.getPath()); + flush_preferences(); + } + } + + private static boolean check_dir(File dir) { + if (!dir.exists()) { + if (!dir.mkdirs()) { + JOptionPane.showMessageDialog(component, + dir.getName(), + "Cannot create directory", + JOptionPane.ERROR_MESSAGE); + return false; + } + } else if (!dir.isDirectory()) { + JOptionPane.showMessageDialog(component, + dir.getName(), + "Is not a directory", + JOptionPane.ERROR_MESSAGE); + return false; + } + return true; + } + + /* Configure the log directory. This is where all telemetry and eeprom files + * will be written to, and where replay will look for telemetry files + */ + public static void ConfigureLog() { + JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile()); + + logdir_chooser.setDialogTitle("Configure Data Logging Directory"); + logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + + if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) { + File dir = logdir_chooser.getSelectedFile(); + if (check_dir(dir)) + set_logdir(dir); + } + } + + public static File logdir() { + return logdir; + } +} diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index 192011d0..59a1999e 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -29,7 +29,7 @@ public class AltosState { /* derived data */ - double report_time; + long report_time; double time_change; int tick; @@ -66,11 +66,6 @@ public class AltosState { int speak_tick; double speak_altitude; - static double - aoview_time() - { - return System.currentTimeMillis() / 1000.0; - } void init (AltosTelemetry cur, AltosState prev_state) { int i; @@ -82,7 +77,7 @@ public class AltosState { ground_altitude = AltosConvert.cc_barometer_to_altitude(data.ground_pres); height = AltosConvert.cc_barometer_to_altitude(data.flight_pres) - ground_altitude; - report_time = aoview_time(); + report_time = System.currentTimeMillis(); accel_counts_per_mss = ((data.accel_minus_g - data.accel_plus_g) / 2.0) / 9.80665; acceleration = (data.ground_accel - data.flight_accel) / accel_counts_per_mss; diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 2952fcc0..43c40799 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -34,6 +34,9 @@ import altosui.AltosSerialMonitor; import altosui.AltosTelemetry; import altosui.AltosState; import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; class AltosFlightStatusTableModel extends AbstractTableModel { private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; @@ -128,7 +131,8 @@ public class AltosUI extends JFrame { private AltosFlightInfoTableModel[] flightInfoModel; private JTable[] flightInfo; - private AltosSerial serialLine; + private AltosSerial serial_line; + private AltosLog altos_log; private Box[] ibox; private Box vbox; private Box hbox; @@ -137,11 +141,15 @@ public class AltosUI extends JFrame { private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14); private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14); + public AltosVoice voice = new AltosVoice(); + public AltosUI() { String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; Object[][] statusData = { { "0", "pad", "-50", "0" } }; + AltosPreferences.init(this); + vbox = Box.createVerticalBox(); this.add(vbox); @@ -188,7 +196,8 @@ public class AltosUI extends JFrame { createMenu(); - serialLine = new AltosSerial(); + serial_line = new AltosSerial(); + altos_log = new AltosLog(serial_line); int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); this.setSize(new Dimension (infoValueMetrics.charWidth('0') * 6 * 20, statusHeight * 4 + infoHeight * 17)); @@ -333,63 +342,76 @@ public class AltosUI extends JFrame { info_finish(); } - /* User Preferences */ - Preferences altosui_preferences = Preferences.userNodeForPackage(this.getClass()); - - /* Log directory */ - private File logdir = null; + class IdleThread extends Thread { - /* logdir preference name */ - final static String logdirPreference = "LOGDIR"; + private AltosState state; - /* Default logdir is ~/TeleMetrum */ - final static String logdirName = "TeleMetrum"; - - /* Initialize logdir from preferences */ - { - String logdir_string = altosui_preferences.get(logdirPreference, null); - if (logdir_string != null) - logdir = new File(logdir_string); - else - /* a hack -- make the file chooser tell us what the default directory - * would be and stick our logdir in a subdirectory of that. - */ - logdir = new File(new JFileChooser().getCurrentDirectory(), logdirName); - } + public void run () { + int reported_landing = 0; - private void set_logdir(File new_logdir) { - logdir = new_logdir; - System.out.printf("Set logdir to %s\n", logdir.toString()); - synchronized (altosui_preferences) { - altosui_preferences.put(logdirPreference, logdir.getPath()); + state = null; try { - altosui_preferences.flush(); - } catch (BackingStoreException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - altosui_preferences.absolutePath(), - "Cannot save prefernces", - JOptionPane.ERROR_MESSAGE); + for (;;) { + Thread.sleep(10000); + if (state == null) + continue; + + /* reset the landing count once we hear about a new flight */ + if (state.state < AltosTelemetry.ao_flight_drogue) + reported_landing = 0; + + /* Shut up once the rocket is on the ground */ + if (reported_landing > 2) + continue; + + /* If the rocket isn't on the pad, then report height */ + if (state.state > AltosTelemetry.ao_flight_pad) { + voice.speak(String.format("%d meters", (int) (state.height + 0.5))); + } + + /* 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.ascent && + (System.currentTimeMillis() - state.report_time > 10000 || + state.state == AltosTelemetry.ao_flight_landed)) + { + if (Math.abs(state.baro_speed) < 20 && state.height < 100) + voice.speak("rocket landed safely"); + else + voice.speak("rocket may have crashed"); + if (state.gps != null) + voice.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; + } + } + } catch (InterruptedException ie) { } } + + public void notice(AltosState new_state) { + state = new_state; + } } - private boolean check_dir(File dir) { - if (!dir.exists()) { - if (!dir.mkdirs()) { - JOptionPane.showMessageDialog(AltosUI.this, - dir.getName(), - "Cannot create directory", - JOptionPane.ERROR_MESSAGE); - return false; + private void tell(AltosState state, AltosState old_state) { + if (old_state == null || old_state.state != state.state) { + voice.speak(state.data.state); + switch (state.state) { + case AltosTelemetry.ao_flight_fast: + voice.speak(String.format("max speed %d meters per second", + (int) (state.max_speed + 0.5))); + break; + case AltosTelemetry.ao_flight_drogue: + voice.speak(String.format("max height %d meters", + (int) (state.max_height + 0.5))); + break; } - } else if (!dir.isDirectory()) { - JOptionPane.showMessageDialog(AltosUI.this, - dir.getName(), - "Is not a directory", - JOptionPane.ERROR_MESSAGE); - return false; } - return true; + old_state = state; } class DisplayThread extends Thread { @@ -402,16 +424,22 @@ public class AltosUI extends JFrame { public void run() { String line; AltosState state = null; + AltosState old_state = null; + IdleThread idle_thread = new IdleThread(); info_reset(); info_finish(); + idle_thread.start(); try { while ((line = read()) != null) { try { AltosTelemetry t = new AltosTelemetry(line); + old_state = state; state = new AltosState(t, state); update(state); show(state); + tell(state, old_state); + idle_thread.notice(state); } catch (ParseException pp) { System.out.printf("Parse error on %s\n", line); System.out.println("exception " + pp); @@ -420,6 +448,7 @@ public class AltosUI extends JFrame { } catch (InterruptedException ee) { } finally { close(); + idle_thread.interrupt(); } } } @@ -450,8 +479,8 @@ public class AltosUI extends JFrame { if (device != null) { try { - serialLine.connect(device.tty); - DeviceThread thread = new DeviceThread(serialLine); + serial_line.connect(device.tty); + DeviceThread thread = new DeviceThread(serial_line); run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, @@ -556,7 +585,7 @@ public class AltosUI extends JFrame { logfile_chooser.setDialogTitle("Select Telemetry File"); logfile_chooser.setFileFilter(new FileNameExtensionFilter("Telemetry file", "telem")); - logfile_chooser.setCurrentDirectory(logdir); + logfile_chooser.setCurrentDirectory(AltosPreferences.logdir()); int returnVal = logfile_chooser.showOpenDialog(AltosUI.this); if (returnVal == JFileChooser.APPROVE_OPTION) { @@ -583,23 +612,6 @@ public class AltosUI extends JFrame { private void SaveFlightData() { } - /* Configure the log directory. This is where all telemetry and eeprom files - * will be written to, and where replay will look for telemetry files - */ - private void ConfigureLog() { - JFileChooser logdir_chooser = new JFileChooser(); - - logdir_chooser.setDialogTitle("Configure Data Logging Directory"); - logdir_chooser.setCurrentDirectory(logdir.getParentFile()); - logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - - if (logdir_chooser.showDialog(AltosUI.this, "Select Directory") == JFileChooser.APPROVE_OPTION) { - File dir = logdir_chooser.getSelectedFile(); - if (check_dir(dir)) - set_logdir(dir); - } - } - /* Create the AltosUI menus */ private void createMenu() { @@ -681,7 +693,7 @@ public class AltosUI extends JFrame { item = new JMenuItem("Configure Log",KeyEvent.VK_C); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - ConfigureLog(); + AltosPreferences.ConfigureLog(); } }); menu.add(item); diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java new file mode 100644 index 00000000..e4ea99a2 --- /dev/null +++ b/ao-tools/altosui/AltosVoice.java @@ -0,0 +1,69 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import com.sun.speech.freetts.Voice; +import com.sun.speech.freetts.VoiceManager; +import com.sun.speech.freetts.audio.JavaClipAudioPlayer; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosVoice implements Runnable { + VoiceManager voice_manager; + Voice voice; + LinkedBlockingQueue phrases; + Thread thread; + + final static String voice_name = "kevin16"; + + public void run() { + try { + for (;;) { + String s = phrases.take(); + voice.speak(s); + } + } catch (InterruptedException e) { + } + } + public void speak(String s) { + try { + if (voice != null) + phrases.put(s); + } catch (InterruptedException e) { + } + } + + public AltosVoice () { + voice_manager = VoiceManager.getInstance(); + voice = voice_manager.getVoice(voice_name); + if (voice != null) { + voice.allocate(); + phrases = new LinkedBlockingQueue (); + thread = new Thread(this); + thread.start(); + speak("Rocket Flight Monitor Ready"); + } else { + System.out.printf("Voice manager failed to open %s\n", voice_name); + Voice[] voices = voice_manager.getVoices(); + System.out.printf("Available voices:\n"); + for (int i = 0; i < voices.length; i++) { + System.out.println(" " + voices[i].getName() + + " (" + voices[i].getDomain() + " domain)"); + } + } + } +} diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index b9f025da..57c889b8 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -1,6 +1,6 @@ .SUFFIXES: .java .class -CLASSPATH=..:/usr/share/java/* +CLASSPATH=..:/usr/share/java/*:/home/keithp/src/freetts/freetts-1.2.2 CLASSFILES=\ AltosConvert.class \ AltosFile.class \ @@ -16,7 +16,8 @@ CLASSFILES=\ AltosUI.class \ AltosDevice.class \ AltosDeviceLinux.class \ - AltosDeviceDialog.class + AltosDeviceDialog.class \ + AltosVoice.class JAVAFLAGS=-Xlint:unchecked diff --git a/ao-tools/altosui/voices.txt b/ao-tools/altosui/voices.txt new file mode 100644 index 00000000..e8825fc3 --- /dev/null +++ b/ao-tools/altosui/voices.txt @@ -0,0 +1 @@ +com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory -- cgit v1.2.3 From 24393eab0ea085f2d0224b59fdc3c00693e5d3a9 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Thu, 17 Jun 2010 14:04:01 +1200 Subject: Extension to KML output format, and minor bug fix Extended KML output by breaking flight into coloured segments representing flight state. Add extra statistical information to description bubbles visible in Google Earth when clicking on links in My Places. Fix Bugs: * output kml to file provided as argument. * move kml coordinate output code to take advantage of nsat calculation * remove superfluous %9.2f format specifier from raw_file output. Signed-off-by: Mike Beattie --- ao-tools/ao-postflight/ao-postflight.c | 169 ++++++++++++++++++++++++--------- 1 file changed, 126 insertions(+), 43 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index cbf9c047..bf427d3b 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -39,6 +39,19 @@ static const char *state_names[] = { "invalid" }; +static const char *kml_state_colours[] = { + "FF000000", + "FF000000", + "FF000000", + "FF0000FF", + "FF4080FF", + "FF00FFFF", + "FFFF0000", + "FF00FF00", + "FF000000", + "FFFFFFFF" +}; + static int plot_colors[3][3] = { { 0, 0x90, 0 }, /* height */ { 0xa0, 0, 0 }, /* speed */ @@ -161,28 +174,48 @@ merge_data(struct cc_perioddata *first, struct cc_perioddata *last, double split return pd; } -static const char kml_header[] = +static const char kml_header_start[] = "\n" - "\n" + "\n" + "\n" + " %s\n" + " \n"; +static const char kml_header_end[] = + " \n" + " 0\n"; + +static const char kml_style_start[] = + " \n"; + +static const char kml_placemark_start[] = " \n" - " gps\n" - " \n" - " \n" - " \n" - " 1\n" - " absolute\n" - " \n"; + " %s\n" + " #ao-flightstate-%s\n" + " \n" + " 1\n" + " absolute\n" + " \n"; + +static const char kml_coord_fmt[] = + " %12.7f, %12.7f, %12.7f \n"; + +static const char kml_placemark_end[] = + " \n" + " \n" + " \n"; static const char kml_footer[] = - "\n" + " \n" " \n" - " \n" - "\n" + " \n" + "\n" "\n"; static unsigned @@ -272,22 +305,33 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, double state_start, state_stop; struct cc_flightcooked *cooked; double apogee; + char buf[128]; + + if (kml_file) { + snprintf(buf, sizeof (buf), "AO Flight#%d S/N: %03d", f->flight, f->serial); + fprintf(kml_file, kml_header_start, buf); + } fprintf(summary_file, "Serial: %9d\n" "Flight: %9d\n", f->serial, f->flight); + if (f->year) { - fprintf(summary_file, + snprintf(buf, sizeof (buf), "Date: %04d-%02d-%02d\n", f->year, f->month, f->day); + fprintf(summary_file, "%s", buf); + if (kml_file) fprintf(kml_file, "%s", buf); } if (f->gps.num) { - fprintf(summary_file, + snprintf(buf, sizeof (buf), "Time: %2d:%02d:%02d\n", f->gps.data[0].hour, f->gps.data[0].minute, f->gps.data[0].second); + fprintf(summary_file, "%s", buf); + if (kml_file) fprintf(kml_file, "%s", buf); } boost_start = f->accel.data[0].time; boost_stop = f->accel.data[f->accel.num-1].time; @@ -309,10 +353,12 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, min_pres = f->pres.data[pres_i].value; height = cc_barometer_to_altitude(min_pres) - cc_barometer_to_altitude(f->ground_pres); - fprintf(summary_file, "Max height: %9.2fm %9.2fft %9.2fs\n", + apogee = f->pres.data[pres_i].time; + snprintf(buf, sizeof (buf), "Max height: %9.2fm %9.2fft %9.2fs\n", height, height * 100 / 2.54 / 12, (f->pres.data[pres_i].time - boost_start) / 100.0); - apogee = f->pres.data[pres_i].time; + fprintf(summary_file, "%s", buf); + if (kml_file) fprintf(kml_file, "%s", buf); } cooked = cc_flight_cook(f); @@ -320,9 +366,11 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, speed_i = cc_perioddata_max(&cooked->accel_speed, boost_start, boost_stop); if (speed_i >= 0) { speed = cooked->accel_speed.data[speed_i]; - fprintf(summary_file, "Max speed: %9.2fm/s %9.2fft/s %9.2fs\n", + snprintf(buf, sizeof (buf), "Max speed: %9.2fm/s %9.2fft/s %9.2fs\n", speed, speed * 100 / 2.4 / 12.0, (cooked->accel_speed.start + speed_i * cooked->accel_speed.step - boost_start) / 100.0); + fprintf(summary_file, "%s", buf); + if (kml_file) fprintf(kml_file, "%s", buf); } } accel_i = cc_timedata_min(&f->accel, boost_start, boost_stop); @@ -330,11 +378,16 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, { accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, f->ground_accel); - fprintf(summary_file, "Max accel: %9.2fm/s² %9.2fg %9.2fs\n", + snprintf(buf, sizeof (buf), "Max accel: %9.2fm/s² %9.2fg %9.2fs\n", accel, accel / 9.80665, (f->accel.data[accel_i].time - boost_start) / 100.0); + fprintf(summary_file, "%s", buf); + if (kml_file) fprintf(kml_file, "%s", buf); } + if (kml_file) + fprintf(kml_file, "%s", kml_header_end); + for (i = 0; i < f->state.num; i++) { state = f->state.data[i].value; state_start = f->state.data[i].time; @@ -347,14 +400,23 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, fprintf(summary_file, "State: %s\n", state_names[state]); fprintf(summary_file, "\tStart: %9.2fs\n", (state_start - boost_start) / 100.0); fprintf(summary_file, "\tDuration: %9.2fs\n", (state_stop - state_start) / 100.0); + if (kml_file) { + fprintf(kml_file, kml_style_start, state_names[state], kml_state_colours[state]); + fprintf(kml_file, "\tState: %s\n", state_names[state]); + fprintf(kml_file, "\tStart: %9.2fs\n", (state_start - boost_start) / 100.0); + fprintf(kml_file, "\tDuration: %9.2fs\n", (state_stop - state_start) / 100.0); + } + accel_i = cc_timedata_min(&f->accel, state_start, state_stop); if (accel_i >= 0) { accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value, f->ground_accel); - fprintf(summary_file, "\tMax accel: %9.2fm/s² %9.2fg %9.2fs\n", + snprintf(buf, sizeof (buf), "\tMax accel: %9.2fm/s² %9.2fg %9.2fs\n", accel, accel / 9.80665, (f->accel.data[accel_i].time - boost_start) / 100.0); + fprintf(summary_file, "%s", buf); + if (kml_file) fprintf(kml_file, "%s", buf); } if (cooked) { @@ -371,11 +433,16 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, } if (speed_i >= 0) { - fprintf(summary_file, "\tMax speed: %9.2fm/s %9.2fft/s %9.2fs\n", + snprintf(buf, sizeof (buf), "\tMax speed: %9.2fm/s %9.2fft/s %9.2fs\n", speed, speed * 100 / 2.4 / 12.0, (cooked->accel_speed.start + speed_i * cooked->accel_speed.step - boost_start) / 100.0); - fprintf(summary_file, "\tAvg speed: %9.2fm/s %9.2fft/s\n", + fprintf(summary_file, "%s", buf); + if (kml_file) fprintf(kml_file, "%s", buf); + + snprintf(buf, sizeof (buf), "\tAvg speed: %9.2fm/s %9.2fft/s\n", avg_speed, avg_speed * 100 / 2.4 / 12.0); + fprintf(summary_file, "%s", buf); + if (kml_file) fprintf(kml_file, "%s", buf); } } pres_i = cc_timedata_min(&f->pres, state_start, state_stop); @@ -384,10 +451,13 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, min_pres = f->pres.data[pres_i].value; height = cc_barometer_to_altitude(min_pres) - cc_barometer_to_altitude(f->ground_pres); - fprintf(summary_file, "\tMax height: %9.2fm %9.2fft %9.2fs\n", + snprintf(buf, sizeof (buf), "\tMax height: %9.2fm %9.2fft %9.2fs\n", height, height * 100 / 2.54 / 12, (f->pres.data[pres_i].time - boost_start) / 100.0); + fprintf(summary_file, "%s", buf); + if (kml_file) fprintf(kml_file, "%s", buf); } + if (kml_file) fprintf(kml_file, "%s", kml_style_end); } if (cooked && detail_file) { double max_height = 0; @@ -431,7 +501,7 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, daytime = compute_daytime_ms(time, &f->gps); else daytime = 0; - fprintf(raw_file, "%9.2f %9.2f %9.2f %9.2f %02d:%02d:%02d.%03d\n", + fprintf(raw_file, "%9.2f %9.2f %9.2f %02d:%02d:%02d.%03d\n", time, pres, accel, daytime_hour(daytime), daytime_minute(daytime), @@ -443,13 +513,17 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, int j = 0, baro_pos; double baro_offset; double baro = 0.0; + int state_idx = 0; if (gps_file) fprintf(gps_file, "%2s %2s %2s %9s %12s %12s %9s %8s %5s\n", "hr", "mn", "sc", "time", "lat", "lon", "alt", "baro", "nsat"); if (kml_file) - fprintf(kml_file, "%s", kml_header); + fprintf(kml_file, kml_placemark_start, + state_names[(int)f->state.data[state_idx].value], + state_names[(int)f->state.data[state_idx].value]); + if (f->gps.num) baro_offset = f->gps.data[0].alt; else @@ -484,19 +558,6 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, f->gps.data[i].lon, f->gps.data[i].alt, baro + baro_offset); - if (kml_file) { - fprintf(kml_file, "%12.7f, %12.7f, %12.7f ", - f->gps.data[i].lon, - f->gps.data[i].lat, - baro + baro_offset, - f->gps.data[i].alt, - (f->gps.data[i].time - boost_start) / 100.0, - nsat); - if (i < f->gps.num - 1) - fprintf(kml_file, ",\n"); - else - fprintf(kml_file, "\n"); - } nsat = 0; if (f->gps.sats) { @@ -516,6 +577,28 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, fprintf(gps_file, "\n"); } } + + if (kml_file) { + snprintf(buf, sizeof (buf), kml_coord_fmt, + f->gps.data[i].lon, + f->gps.data[i].lat, + baro + baro_offset, + f->gps.data[i].alt, + (f->gps.data[i].time - boost_start) / 100.0, + nsat); + fprintf(kml_file, "%s", buf); + if (state_idx + 1 <= f->state.num && f->state.data[state_idx + 1].time <= f->gps.data[i].time) { + state_idx++; + if (f->state.data[state_idx - 1].value != f->state.data[state_idx].value) { + fprintf(kml_file, "%s", kml_placemark_end); + fprintf(kml_file, kml_placemark_start, + state_names[(int)f->state.data[state_idx].value], + state_names[(int)f->state.data[state_idx].value]); + fprintf(kml_file, "%s", buf); + } + } + } + } if (kml_file) fprintf(kml_file, "%s", kml_footer); @@ -705,7 +788,7 @@ main (int argc, char **argv) if (has_gps && !gps_file) gps_file = open_output(gps_name, argv[i], ".gps"); if (has_kml && !kml_file) - kml_file = open_output(gps_name, argv[i], ".kml"); + kml_file = open_output(kml_name, argv[i], ".kml"); s = strstr(argv[i], "-serial-"); if (s) serial = atoi(s + 8); -- cgit v1.2.3 From 50ae347bf9de49ccfc92d26888f36e155fb406a3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 16 Jun 2010 21:48:04 -0700 Subject: ao-view: disable radio telemetry monitoring during channel change This makes ao-view disable the radio so that the channel change has an immediate effect rather than waiting for a packet on the old channel. Note that this should also be fixed in the TM code itself so that this change wouldn't be required. Signed-off-by: Keith Packard --- ao-tools/ao-view/aoview_monitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c index 4d7e7a9f..1f9937b2 100644 --- a/ao-tools/ao-view/aoview_monitor.c +++ b/ao-tools/ao-view/aoview_monitor.c @@ -83,8 +83,11 @@ aoview_monitor_callback(gpointer user_data, void aoview_monitor_set_channel(int channel) { - if (monitor_serial) + if (monitor_serial) { + aoview_serial_printf(monitor_serial, "m 0\n"); aoview_serial_printf(monitor_serial, "c r %d\n", channel); + aoview_serial_printf(monitor_serial, "m 1\n"); + } } gboolean @@ -98,9 +101,7 @@ aoview_monitor_connect(char *tty) aoview_table_clear(); aoview_state_reset(); channel = aoview_channel_current(); - if (channel >= 0) - aoview_monitor_set_channel(channel); - aoview_serial_printf(monitor_serial, "m 1\n"); + aoview_monitor_set_channel(channel); aoview_serial_set_callback(monitor_serial, aoview_monitor_callback); return TRUE; -- cgit v1.2.3 From 5933eaa44fe45027b856f1303dd657b974eb53e7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 21 Jun 2010 11:44:32 -0700 Subject: ao-postflight: was walking off state.data array --- ao-tools/ao-postflight/ao-postflight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-postflight/ao-postflight.c b/ao-tools/ao-postflight/ao-postflight.c index bf427d3b..e5b55665 100644 --- a/ao-tools/ao-postflight/ao-postflight.c +++ b/ao-tools/ao-postflight/ao-postflight.c @@ -587,7 +587,7 @@ analyse_flight(struct cc_flightraw *f, FILE *summary_file, FILE *detail_file, (f->gps.data[i].time - boost_start) / 100.0, nsat); fprintf(kml_file, "%s", buf); - if (state_idx + 1 <= f->state.num && f->state.data[state_idx + 1].time <= f->gps.data[i].time) { + if (state_idx + 1 < f->state.num && f->state.data[state_idx + 1].time <= f->gps.data[i].time) { state_idx++; if (f->state.data[state_idx - 1].value != f->state.data[state_idx].value) { fprintf(kml_file, "%s", kml_placemark_end); -- cgit v1.2.3 From a9ec6be0e92dee01f7aac006ef6f7779c1da1b36 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 3 Jul 2010 17:42:36 -0400 Subject: Telemetry code was mis-computing RSSI The RSSI data from the hardware reports in 1/2 dBm increments, and so must be divided to report plain RSSI numbers. Signed-off-by: Keith Packard --- ao-tools/lib/cc-telem.c | 4 ++++ configure.ac | 2 ++ src/ao.h | 2 +- src/ao_monitor.c | 10 +++++++--- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/lib/cc-telem.c b/ao-tools/lib/cc-telem.c index ccd40ac2..aa52b7c5 100644 --- a/ao-tools/lib/cc-telem.c +++ b/ao-tools/lib/cc-telem.c @@ -101,6 +101,10 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem) telem->flight = 0; cc_parse_int(&telem->rssi, words[5]); + if (version <= 2) { + /* Older telemetry versions mis-computed the rssi value */ + telem->rssi = (telem->rssi + 74) / 2 - 74; + } cc_parse_string(telem->state, sizeof (telem->state), words[9]); cc_parse_int(&telem->tick, words[10]); cc_parse_int(&telem->accel, words[12]); diff --git a/configure.ac b/configure.ac index d6c8682b..fafc6b34 100644 --- a/configure.ac +++ b/configure.ac @@ -77,6 +77,8 @@ PKG_CHECK_MODULES([ALSA], [alsa]) PKG_CHECK_MODULES([PLPLOT], [plplotd]) +PKG_CHECK_MODULES([SNDFILE], [sndfile]) + AC_OUTPUT([ Makefile ao-tools/Makefile diff --git a/src/ao.h b/src/ao.h index a2dfadd0..dfff8a8d 100644 --- a/src/ao.h +++ b/src/ao.h @@ -804,7 +804,7 @@ ao_gps_report_init(void); */ #define AO_MAX_CALLSIGN 8 -#define AO_TELEMETRY_VERSION 2 +#define AO_TELEMETRY_VERSION 3 struct ao_telemetry { uint8_t addr; diff --git a/src/ao_monitor.c b/src/ao_monitor.c index f2f3fc2e..f019d3b4 100644 --- a/src/ao_monitor.c +++ b/src/ao_monitor.c @@ -26,6 +26,7 @@ ao_monitor(void) __xdata struct ao_radio_recv recv; __xdata char callsign[AO_MAX_CALLSIGN+1]; uint8_t state; + int16_t rssi; for (;;) { __critical while (!ao_monitoring) @@ -33,6 +34,9 @@ ao_monitor(void) if (!ao_radio_recv(&recv)) continue; state = recv.telemetry.flight_state; + + /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */ + rssi = (int16_t) (recv.rssi >> 1) - 74; memcpy(callsign, recv.telemetry.callsign, AO_MAX_CALLSIGN); if (state > ao_flight_invalid) state = ao_flight_invalid; @@ -42,7 +46,7 @@ ao_monitor(void) callsign, recv.telemetry.addr, recv.telemetry.flight, - (int) recv.rssi - 74, recv.status, + rssi, recv.status, ao_state_names[state]); printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d " "fa: %5d ga: %d fv: %7ld fp: %5d gp: %5d a+: %5d a-: %5d ", @@ -64,9 +68,9 @@ ao_monitor(void) putchar(' '); ao_gps_tracking_print(&recv.telemetry.gps_tracking); putchar('\n'); - ao_rssi_set((int) recv.rssi - 74); + ao_rssi_set(rssi); } else { - printf("CRC INVALID RSSI %3d\n", (int) recv.rssi - 74); + printf("CRC INVALID RSSI %3d\n", rssi); } ao_usb_flush(); ao_led_toggle(ao_monitor_led); -- cgit v1.2.3 From c726d8f6eb861801d7543552beab6ee2c920c96f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 26 Jul 2010 15:41:39 -0700 Subject: Add libaltos which talks to USB connected altos devices --- ao-tools/libaltos/Makefile | 61 ++++++ ao-tools/libaltos/cjnitest.c | 25 +++ ao-tools/libaltos/libaltos.c | 479 ++++++++++++++++++++++++++++++++++++++++++ ao-tools/libaltos/libaltos.h | 54 +++++ ao-tools/libaltos/libaltos.i0 | 5 + 5 files changed, 624 insertions(+) create mode 100644 ao-tools/libaltos/Makefile create mode 100644 ao-tools/libaltos/cjnitest.c create mode 100644 ao-tools/libaltos/libaltos.c create mode 100644 ao-tools/libaltos/libaltos.h create mode 100644 ao-tools/libaltos/libaltos.i0 (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile new file mode 100644 index 00000000..5ffbdadf --- /dev/null +++ b/ao-tools/libaltos/Makefile @@ -0,0 +1,61 @@ +.SUFFIXES: .java .class + +CLASSPATH=".:jnitest/*:libaltosJNI:/usr/share/java/*" + +SWIG_DIR=swig_bindings/java +SWIG_FILE=$(SWIG_DIR)/libaltos.swig +SWIG_WRAP=$(SWIG_DIR)/libaltos_wrap.c + +JNI_DIR=libaltosJNI +JNI_FILE=$(JNI_DIR)/libaltosJNI.java +JNI_SRCS=$(JNI_FILE) \ + $(JNI_DIR)/SWIGTYPE_p_altos_file.java \ + $(JNI_DIR)/SWIGTYPE_p_altos_list.java \ + $(JNI_DIR)/altos_device.java \ + $(JNI_DIR)/libaltos.java + +LIBEXT=dylib + +JAVAFILES=\ + $(JNI_SRCS) + +CLASSFILES = $(JAVAFILES:%.java=%.class) + +JAVAFLAGS=-Xlint:unchecked + +all: libaltos.$(LIBEXT) cjnitest $(CLASSFILES) + +.java.class: + javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java + +DARWIN_CFLAGS=\ + -I/System/Library/Frameworks/JavaVM.framework/Headers \ + -I/System/Library/Frameworks/IOKit.framework/Headers \ + -I/System/Library/Frameworks/CoreFoundation.framework/Headers +DARWIN_LIBS=\ + -framework IOKit -framework CoreFoundation + +CFLAGS = $(DARWIN_CFLAGS) -I. -O0 -g + +HEADERS=libaltos.h +SRCS = libaltos.c $(SWIG_WRAP) +OBJS = $(SRCS:%.c=%.o) +LIBS = $(DARWIN_LIBS) + +cjnitest: cjnitest.o $(OBJS) + cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBS) + +libaltos.$(LIBEXT): $(OBJS) + gcc -shared -o $@ $(OBJS) $(LIBS) + +clean: + rm -f $(CLASSFILES) $(OBJS) libaltos.$(LIBEXT) cjnitest + +$(JNI_FILE): libaltos.i0 $(HEADERS) + mkdir -p $(SWIG_DIR) + mkdir -p libaltosJNI + sed 's;//%;%;' libaltos.i0 $(HEADERS) > $(SWIG_FILE) + swig -java -package libaltosJNI $(SWIG_FILE) + cp swig_bindings/java/*.java libaltosJNI + +$(SWIG_WRAP): $(JNI_FILE) diff --git a/ao-tools/libaltos/cjnitest.c b/ao-tools/libaltos/cjnitest.c new file mode 100644 index 00000000..cd3898ed --- /dev/null +++ b/ao-tools/libaltos/cjnitest.c @@ -0,0 +1,25 @@ +#include +#include "libaltos.h" + +main () +{ + struct altos_device device; + struct altos_list *list; + + altos_init(); + list = altos_list_start(); + while (altos_list_next(list, &device)) { + struct altos_file *file; + int c; + + file = altos_open(&device); + altos_putchar(file, '?'); altos_putchar(file, '\n'); altos_flush(file); + while ((c = altos_getchar(file, 100)) >= 0) { + putchar (c); + } + printf ("getchar returns %d\n", c); + altos_close(file); + } + altos_list_finish(list); + altos_fini(); +} diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c new file mode 100644 index 00000000..417c8fe5 --- /dev/null +++ b/ao-tools/libaltos/libaltos.c @@ -0,0 +1,479 @@ +/* + * Copyright © 2010 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 "libaltos.h" + +#define USE_DARWIN + +#ifdef USE_DARWIN + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct altos_list { + io_iterator_t iterator; +}; + +static int +get_string(io_object_t object, CFStringRef entry, char *result, int result_len) +{ + CFTypeRef entry_as_string; + Boolean got_string; + + entry_as_string = IORegistryEntrySearchCFProperty (object, + kIOServicePlane, + entry, + kCFAllocatorDefault, + kIORegistryIterateRecursively); + if (entry_as_string) { + got_string = CFStringGetCString(entry_as_string, + result, result_len, + kCFStringEncodingASCII); + + CFRelease(entry_as_string); + if (got_string) + return 1; + } + return 0; +} + +int +altos_init(void) +{ + return 1; +} + +void +altos_fini(void) +{ +} + +struct altos_list * +altos_list_start(void) +{ + struct altos_list *list = calloc (sizeof (struct altos_list), 1); + CFMutableDictionaryRef matching_dictionary = IOServiceMatching("IOUSBDevice"); + UInt32 vendor = 0xfffe, product = 0x000a; + CFNumberRef vendor_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vendor); + CFNumberRef product_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &product); + io_iterator_t tdIterator; + io_object_t tdObject; + + CFDictionaryAddValue(matching_dictionary, CFSTR(kUSBVendorID), vendor_ref); + CFDictionaryAddValue(matching_dictionary, CFSTR(kUSBProductID), product_ref); + + IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dictionary, &list->iterator); + + CFRelease(vendor_ref); + CFRelease(product_ref); + return list; +} + +int +altos_list_next(struct altos_list *list, struct altos_device *device) +{ + io_object_t object; + char serial_string[128]; + + for (;;) { + object = IOIteratorNext(list->iterator); + if (!object) + return 0; + + if (get_string (object, CFSTR("IOCalloutDevice"), device->path, sizeof (device->path)) && + get_string (object, CFSTR("USB Product Name"), device->product, sizeof (device->product)) && + get_string (object, CFSTR("USB Serial Number"), serial_string, sizeof (serial_string))) { + device->serial = atoi(serial_string); + return 1; + } + } +} + +void +altos_list_finish(struct altos_list *list) +{ + IOObjectRelease (list->iterator); + free(list); +} + + +#define USB_BUF_SIZE 64 + +struct altos_file { + int fd; + unsigned char out_data[USB_BUF_SIZE]; + int out_used; + unsigned char in_data[USB_BUF_SIZE]; + int in_used; + int in_read; +}; + +void +altos_test(char *path) +{ + int n; + char buf[16]; + int fd; + struct termios term; + + fd = open(path, O_RDWR | O_NOCTTY); + if (fd < 0) { + perror(path); + return; + } + if (ioctl(fd, TIOCEXCL, (char *) 0) < 0) { + perror("TIOCEXCL"); + close (fd); + return; + } + + n = tcgetattr(fd, &term); + if (n < 0) { + perror("tcgetattr"); + close(fd); + return; + } + cfmakeraw(&term); + term.c_cc[VMIN] = 0; + term.c_cc[VTIME] = 1; + n = tcsetattr(fd, TCSAFLUSH, &term); + if (n < 0) { + perror("tcsetattr"); + close(fd); + return; + } + write(fd, "\n?\n", 3); + for (;;) { + n = read(fd, buf, sizeof (buf)); + if (n < 0) { + perror("read"); + break; + } + if (n == 0) + break; + write(1, buf, n); + } + close(fd); +} + +struct altos_file * +altos_open(struct altos_device *device) +{ + struct altos_file *file = calloc (sizeof (struct altos_file), 1); + int ret; + struct termios term; + + if (!file) + return NULL; + + file->fd = open(device->path, O_RDWR | O_NOCTTY); + if (file->fd < 0) { + perror(device->path); + free(file); + return NULL; + } + ret = tcgetattr(file->fd, &term); + if (ret < 0) { + perror("tcgetattr"); + close(file->fd); + free(file); + return NULL; + } + cfmakeraw(&term); + term.c_cc[VMIN] = 0; + term.c_cc[VTIME] = 1; + ret = tcsetattr(file->fd, TCSAFLUSH, &term); + if (ret < 0) { + perror("tcsetattr"); + close(file->fd); + free(file); + return NULL; + } + return file; +} + +void +altos_close(struct altos_file *file) +{ + close(file->fd); + free(file); +} + +int +altos_putchar(struct altos_file *file, char c) +{ + int ret; + + if (file->out_used == USB_BUF_SIZE) { + ret = altos_flush(file); + if (ret) + return ret; + } + file->out_data[file->out_used++] = c; + if (file->out_used == USB_BUF_SIZE) + return altos_flush(file); + return 0; +} + +int +altos_flush(struct altos_file *file) +{ + while (file->out_used) { + int ret; + + ret = write (file->fd, file->out_data, file->out_used); + if (ret < 0) + return -errno; + if (ret) { + memmove(file->out_data, file->out_data + ret, + file->out_used - ret); + file->out_used -= ret; + } + } +} + +int +altos_getchar(struct altos_file *file, int timeout) +{ + while (file->in_read == file->in_used) { + int ret; + + altos_flush(file); + ret = read(file->fd, file->in_data, USB_BUF_SIZE); + if (ret < 0) + return -errno; + file->in_read = 0; + file->in_used = ret; + } + return file->in_data[file->in_read++]; +} + +#endif /* USE_DARWIN */ + +#ifdef USE_LIBUSB +#include +#include +#include +#include + +libusb_context *usb_context; + +int altos_init(void) +{ + int ret; + ret = libusb_init(&usb_context); + if (ret) + return ret; + libusb_set_debug(usb_context, 3); + return 0; +} + +void altos_fini(void) +{ + libusb_exit(usb_context); + usb_context = NULL; +} + +static libusb_device **list; +static ssize_t num, current; + +int altos_list_start(void) +{ + if (list) + altos_list_finish(); + current = 0; + num = libusb_get_device_list(usb_context, &list); + if (num == 0) { + current = num = 0; + list = NULL; + return 0; + } + return 1; +} + +int altos_list_next(struct altos_device *device) +{ + while (current < num) { + struct libusb_device_descriptor descriptor; + libusb_device *usb_device = list[current++]; + + if (libusb_get_device_descriptor(usb_device, &descriptor) == 0) { + if (descriptor.idVendor == 0xfffe) + { + libusb_device_handle *handle; + if (libusb_open(usb_device, &handle) == 0) { + char serial_number[256]; + libusb_get_string_descriptor_ascii(handle, descriptor.iProduct, + device->product, + sizeof(device->product)); + libusb_get_string_descriptor_ascii(handle, descriptor.iSerialNumber, + serial_number, + sizeof (serial_number)); + libusb_close(handle); + device->serial = atoi(serial_number); + device->device = usb_device; + return 1; + } + } + } + } + return 0; +} + +void altos_list_finish(void) +{ + if (list) { + libusb_free_device_list(list, 1); + list = NULL; + } +} + +#define USB_BUF_SIZE 64 + +struct altos_file { + struct libusb_device *device; + struct libusb_device_handle *handle; + int out_ep; + int out_size; + int in_ep; + int in_size; + unsigned char out_data[USB_BUF_SIZE]; + int out_used; + unsigned char in_data[USB_BUF_SIZE]; + int in_used; + int in_read; +}; + +struct altos_file * +altos_open(struct altos_device *device) +{ + struct altos_file *file; + struct libusb_device_handle *handle; + if (libusb_open(device->device, &handle) == 0) { + int ret; + + ret = libusb_claim_interface(handle, 1); +#if 0 + if (ret) { + libusb_close(handle); + return NULL; + } +#endif + ret = libusb_detach_kernel_driver(handle, 1); +#if 0 + if (ret) { + libusb_close(handle); + return NULL; + } +#endif + + file = calloc(sizeof (struct altos_file), 1); + file->device = libusb_ref_device(device->device); + file->handle = handle; + /* XXX should get these from the endpoint descriptors */ + file->out_ep = 4 | LIBUSB_ENDPOINT_OUT; + file->out_size = 64; + file->in_ep = 5 | LIBUSB_ENDPOINT_IN; + file->in_size = 64; + + return file; + } + return NULL; +} + +void +altos_close(struct altos_file *file) +{ + libusb_close(file->handle); + libusb_unref_device(file->device); + file->handle = NULL; + free(file); +} + +int +altos_putchar(struct altos_file *file, char c) +{ + int ret; + + if (file->out_used == file->out_size) { + ret = altos_flush(file); + if (ret) + return ret; + } + file->out_data[file->out_used++] = c; + if (file->out_used == file->out_size) + return altos_flush(file); + return 0; +} + +int +altos_flush(struct altos_file *file) +{ + while (file->out_used) { + int transferred; + int ret; + + ret = libusb_bulk_transfer(file->handle, + file->out_ep, + file->out_data, + file->out_used, + &transferred, + 0); + if (ret) + return ret; + if (transferred) { + memmove(file->out_data, file->out_data + transferred, + file->out_used - transferred); + file->out_used -= transferred; + } + } +} + +int +altos_getchar(struct altos_file *file, int timeout) +{ + while (file->in_read == file->in_used) { + int ret; + int transferred; + + altos_flush(file); + ret = libusb_bulk_transfer(file->handle, + file->in_ep, + file->in_data, + file->in_size, + &transferred, + (unsigned int) timeout); + if (ret) + return ret; + file->in_read = 0; + file->in_used = transferred; + } + return file->in_data[file->in_read++]; +} + +#endif /* USE_LIBUSB */ diff --git a/ao-tools/libaltos/libaltos.h b/ao-tools/libaltos/libaltos.h new file mode 100644 index 00000000..782f244e --- /dev/null +++ b/ao-tools/libaltos/libaltos.h @@ -0,0 +1,54 @@ +/* + * Copyright © 2010 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. + */ + +#ifndef _LIBALTOS_H_ +#define _LIBALTOS_H_ + +struct altos_device { + //%immutable; + char product[256]; + int serial; + char path[256]; + //%mutable; +}; + +int altos_init(void); + +void altos_fini(void); + +struct altos_list * +altos_list_start(void); + +int altos_list_next(struct altos_list *list, struct altos_device *device); + +void altos_list_finish(struct altos_list *list); + +struct altos_file * +altos_open(struct altos_device *device); + +void altos_close(struct altos_file *file); + +int +altos_putchar(struct altos_file *file, char c); + +int +altos_flush(struct altos_file *file); + +int +altos_getchar(struct altos_file *file, int timeout); + +#endif /* _LIBALTOS_H_ */ diff --git a/ao-tools/libaltos/libaltos.i0 b/ao-tools/libaltos/libaltos.i0 new file mode 100644 index 00000000..d06468f5 --- /dev/null +++ b/ao-tools/libaltos/libaltos.i0 @@ -0,0 +1,5 @@ +%module libaltos +%{ +#include "libaltos.h" +%} + -- cgit v1.2.3 From 005e2d6a7bb3b0546b0c1273296875621632ec6d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 26 Jul 2010 15:42:48 -0700 Subject: Switch AltosUI to libaltos for device access Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDevice.java | 35 +++++-- ao-tools/altosui/AltosDeviceDialog.java | 14 +-- ao-tools/altosui/AltosDeviceLinux.java | 172 -------------------------------- ao-tools/altosui/AltosGPS.java | 4 + ao-tools/altosui/AltosSerial.java | 72 ++++--------- ao-tools/altosui/AltosUI.java | 21 ++-- ao-tools/altosui/AltosVoice.java | 20 ++-- ao-tools/altosui/Makefile | 12 +-- 8 files changed, 78 insertions(+), 272 deletions(-) delete mode 100644 ao-tools/altosui/AltosDeviceLinux.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index 66800c5c..8ebd3b99 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -18,13 +18,36 @@ package altosui; import java.lang.*; import java.util.*; +import libaltosJNI.*; public class AltosDevice { - String tty; /* suitable to be passed to AltosSerial.connect */ - String manufacturer; - String product; - int serial; - int idProduct; - int idVendor; + static { + System.loadLibrary("altos"); + libaltos.altos_init(); + } + static altos_device[] list(String product) { + SWIGTYPE_p_altos_list list = libaltos.altos_list_start(); + + ArrayList device_list = new ArrayList(); + if (list != null) { + SWIGTYPE_p_altos_file file; + + for (;;) { + altos_device device = new altos_device(); + if (libaltos.altos_list_next(list, device) == 0) + break; + System.out.printf("Found device %s %d %s\n", + device.getProduct(), device.getSerial(), device.getPath()); + + device_list.add(device); + } + libaltos.altos_list_finish(list); + } + + altos_device[] devices = new altos_device[device_list.size()]; + for (int i = 0; i < device_list.size(); i++) + devices[i] = device_list.get(i); + return devices; + } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java index cb1eef8b..b3a0f9be 100644 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -20,15 +20,17 @@ package altosui; import java.lang.*; import java.util.*; import javax.swing.*; +import libaltosJNI.libaltos; +import libaltosJNI.altos_device; +import libaltosJNI.SWIGTYPE_p_altos_file; +import libaltosJNI.SWIGTYPE_p_altos_list; import altosui.AltosDevice; -import altosui.AltosDeviceLinux; public class AltosDeviceDialog { - static AltosDevice show (JFrame frame, String product) { - AltosDevice[] devices = null; - if (System.getProperty("os.name").startsWith("Linux")) - devices = AltosDeviceLinux.list(product); + static altos_device show (JFrame frame, String product) { + altos_device[] devices = null; + devices = AltosDevice.list(product); if (devices != null & devices.length > 0) { Object o = JOptionPane.showInputDialog(frame, "Select a device", @@ -37,7 +39,7 @@ public class AltosDeviceDialog { null, devices, devices[0]); - return (AltosDevice) o; + return (altos_device) o; } else { return null; } diff --git a/ao-tools/altosui/AltosDeviceLinux.java b/ao-tools/altosui/AltosDeviceLinux.java deleted file mode 100644 index ffc70aff..00000000 --- a/ao-tools/altosui/AltosDeviceLinux.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; -import java.lang.*; -import java.io.*; -import java.util.*; -import altosui.AltosDevice; - -public class AltosDeviceLinux extends AltosDevice { - - String load_string(File file) { - try { - FileInputStream in = new FileInputStream(file); - String result = ""; - int c; - try { - while ((c = in.read()) != -1) { - if (c == '\n') - break; - result = result + (char) c; - } - return result; - } catch (IOException ee) { - return ""; - } - } catch (FileNotFoundException ee) { - return ""; - } - } - String load_string(File dir, String name) { - return load_string(new File(dir, name)); - } - - int load_hex(File file) { - try { - return Integer.parseInt(load_string(file).trim(), 16); - } catch (NumberFormatException ee) { - return -1; - } - } - - int load_hex(File dir, String name) { - return load_hex(new File(dir, name)); - } - - int load_dec(File file) { - try { - return Integer.parseInt(load_string(file).trim()); - } catch (NumberFormatException ee) { - return -1; - } - } - - int load_dec(File dir, String name) { - return load_dec(new File(dir, name)); - } - - String usb_tty(File sys_dir) { - String base = sys_dir.getName(); - int num_configs = load_hex(sys_dir, "bNumConfigurations"); - int num_inters = load_hex(sys_dir, "bNumInterfaces"); - for (int config = 1; config <= num_configs; config++) { - for (int inter = 0; inter < num_inters; inter++) { - String endpoint_base = String.format("%s:%d.%d", - base, config, inter); - File endpoint_full = new File(sys_dir, endpoint_base); - - File[] namelist; - - /* Check for tty:ttyACMx style names */ - class tty_colon_filter implements FilenameFilter { - public boolean accept(File dir, String name) { - return name.startsWith("tty:"); - } - } - namelist = endpoint_full.listFiles(new tty_colon_filter()); - if (namelist != null && namelist.length > 0) - return new File ("/dev", namelist[0].getName().substring(4)).getPath(); - - /* Check for tty/ttyACMx style names */ - class tty_filter implements FilenameFilter { - public boolean accept(File dir, String name) { - return name.startsWith("tty"); - } - } - File tty_dir = new File(endpoint_full, "tty"); - namelist = tty_dir.listFiles(new tty_filter()); - if (namelist != null && namelist.length > 0) - return new File ("/dev", namelist[0].getName()).getPath(); - } - } - return null; - } - - public AltosDeviceLinux (File sys) { - sys = sys; - manufacturer = load_string(sys, "manufacturer"); - product = load_string(sys, "product"); - serial = load_dec(sys, "serial"); - idProduct = load_hex(sys, "idProduct"); - idVendor = load_hex(sys, "idVendor"); - tty = usb_tty(sys); - } - - public String toString() { - return String.format("%-20s %6d %-15s", product, serial, tty == null ? "" : tty); - } - static public AltosDeviceLinux[] list() { - LinkedList devices = new LinkedList(); - - class dev_filter implements FilenameFilter{ - public boolean accept(File dir, String name) { - for (int i = 0; i < name.length(); i++) { - char c = name.charAt(i); - if (Character.isDigit(c)) - continue; - if (c == '-') - continue; - if (c == '.' && i != 1) - continue; - return false; - } - return true; - } - } - - File usb_devices = new File("/sys/bus/usb/devices"); - File[] devs = usb_devices.listFiles(new dev_filter()); - if (devs != null) { - for (int e = 0; e < devs.length; e++) { - AltosDeviceLinux dev = new AltosDeviceLinux(devs[e]); - if (dev.idVendor == 0xfffe && dev.tty != null) { - devices.add(dev); - } - } - } - AltosDeviceLinux[] foo = new AltosDeviceLinux[devices.size()]; - for (int e = 0; e < devices.size(); e++) - foo[e] = devices.get(e); - return foo; - } - - static public AltosDeviceLinux[] list(String model) { - AltosDeviceLinux[] devices = list(); - if (model != null) { - LinkedList subset = new LinkedList(); - for (int i = 0; i < devices.length; i++) { - if (devices[i].product.startsWith(model)) - subset.add(devices[i]); - } - devices = new AltosDeviceLinux[subset.size()]; - for (int e = 0; e < subset.size(); e++) - devices[e] = subset.get(e); - } - return devices; - } -} diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index c3b368e2..f8eb5f48 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -90,6 +90,9 @@ public class AltosGPS { gps_connected = true; gps_time = new AltosGPSTime(); i++; + } else if ((words[i]).equals("not-connected")) { + gps_time = new AltosGPSTime(); + i++; } else if (words.length >= 40) { gps_locked = true; gps_connected = true; @@ -106,6 +109,7 @@ public class AltosGPS { v_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(verr)")); } else { gps_time = new AltosGPSTime(); + i++; } AltosParse.word(words[i++], "SAT"); int tracking_channels = 0; diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 03ab28c5..073bfb78 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -26,8 +26,11 @@ import java.io.*; import java.util.concurrent.LinkedBlockingQueue; import java.util.LinkedList; import java.util.Iterator; -import gnu.io.*; import altosui.AltosSerialMonitor; +import libaltosJNI.libaltos; +import libaltosJNI.altos_device; +import libaltosJNI.SWIGTYPE_p_altos_file; +import libaltosJNI.SWIGTYPE_p_altos_list; /* * This class reads from the serial port and places each received @@ -35,7 +38,7 @@ import altosui.AltosSerialMonitor; * threads. */ class AltosSerialReader implements Runnable { - InputStream serial_in; + SWIGTYPE_p_altos_file altos; LinkedList> monitors; LinkedBlockingQueue reply_queue; Thread input_thread; @@ -46,7 +49,7 @@ class AltosSerialReader implements Runnable { try { for (;;) { - c = serial_in.read(); + c = libaltos.altos_getchar(altos, 0); if (Thread.interrupted()) break; if (c == -1) @@ -70,7 +73,6 @@ class AltosSerialReader implements Runnable { } } } - } catch (IOException e) { } catch (InterruptedException e) { } } @@ -96,16 +98,13 @@ class AltosSerialReader implements Runnable { } public boolean opened() { - return serial_in != null; + return altos != null; } public void close() { - if (serial_in != null) { - try { - serial_in.close(); - } catch (IOException e) { - } - serial_in = null; + if (altos != null) { + libaltos.altos_close(altos); + altos = null; } if (input_thread != null) { try { @@ -117,62 +116,30 @@ class AltosSerialReader implements Runnable { } } - public void open(File name) throws FileNotFoundException { - close(); - serial_in = new FileInputStream(name); - input_thread = new Thread(this); - input_thread.start(); - } - public void open(CommPort c) throws IOException { + public void open(altos_device device) throws FileNotFoundException { close(); - try { - c.enableReceiveTimeout(1000); /* icky. the read method cannot be interrupted */ - } catch (UnsupportedCommOperationException ee) { - } - serial_in = c.getInputStream(); + altos = libaltos.altos_open(device); input_thread = new Thread(this); input_thread.start(); } public AltosSerialReader () { - serial_in = null; + altos = null; input_thread = null; line = ""; monitors = new LinkedList> (); reply_queue = new LinkedBlockingQueue (); } - } public class AltosSerial { - OutputStream serial_out = null; AltosSerialReader reader = null; - CommPort comm_port = null; - public void close() { - try { - serial_out.close(); - } catch (IOException ee) { - } reader.close(); - if (comm_port != null) { - comm_port.close(); - } - } - - public void open(File serial_name) throws FileNotFoundException { - reader.open(serial_name); - serial_out = new FileOutputStream(serial_name); } - public void open(CommPort c) throws IOException { - reader.open(c); - serial_out = c.getOutputStream(); - } - - public void connect(String port_name) throws IOException, NoSuchPortException, PortInUseException { - comm_port = new RXTXPort(port_name); - open(comm_port); + public void open(altos_device device) throws FileNotFoundException { + reader.open(device); } void init() { @@ -191,13 +158,8 @@ public class AltosSerial { init(); } - public AltosSerial(File serial_name) throws FileNotFoundException { - init(); - open(serial_name); - } - - public AltosSerial(CommPort comm_port) throws IOException { + public AltosSerial(altos_device device) throws FileNotFoundException { init(); - open(comm_port); + open(device); } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 43c40799..33ed2c90 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -27,7 +27,6 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import gnu.io.*; import altosui.AltosSerial; import altosui.AltosSerialMonitor; @@ -38,6 +37,8 @@ import altosui.AltosPreferences; import altosui.AltosLog; import altosui.AltosVoice; +import libaltosJNI.*; + class AltosFlightStatusTableModel extends AbstractTableModel { private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; private Object[] data = { 0, "idle", 0, 0 }; @@ -475,31 +476,21 @@ public class AltosUI extends JFrame { } private void ConnectToDevice() { - AltosDevice device = AltosDeviceDialog.show(AltosUI.this, "TeleDongle"); + altos_device device = AltosDeviceDialog.show(AltosUI.this, "TeleDongle"); if (device != null) { try { - serial_line.connect(device.tty); + serial_line.open(device); DeviceThread thread = new DeviceThread(serial_line); run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, - device.tty, + device.getPath(), "Cannot open serial port", JOptionPane.ERROR_MESSAGE); - } catch (NoSuchPortException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - device.tty, - "No such serial port", - JOptionPane.ERROR_MESSAGE); - } catch (PortInUseException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - device.tty, - "Port in use", - JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, - device.tty, + device.getPath(), "Unkonwn I/O error", JOptionPane.ERROR_MESSAGE); } diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java index e4ea99a2..0c34795c 100644 --- a/ao-tools/altosui/AltosVoice.java +++ b/ao-tools/altosui/AltosVoice.java @@ -17,14 +17,16 @@ package altosui; -import com.sun.speech.freetts.Voice; +/*import com.sun.speech.freetts.Voice; import com.sun.speech.freetts.VoiceManager; -import com.sun.speech.freetts.audio.JavaClipAudioPlayer; +import com.sun.speech.freetts.audio.JavaClipAudioPlayer; */ import java.util.concurrent.LinkedBlockingQueue; public class AltosVoice implements Runnable { +/* VoiceManager voice_manager; Voice voice; +*/ LinkedBlockingQueue phrases; Thread thread; @@ -34,29 +36,29 @@ public class AltosVoice implements Runnable { try { for (;;) { String s = phrases.take(); - voice.speak(s); +/* voice.speak(s); */ } } catch (InterruptedException e) { } } public void speak(String s) { try { - if (voice != null) +/* if (voice != null) */ phrases.put(s); } catch (InterruptedException e) { } } public AltosVoice () { - voice_manager = VoiceManager.getInstance(); +/* voice_manager = VoiceManager.getInstance(); voice = voice_manager.getVoice(voice_name); - if (voice != null) { - voice.allocate(); + if (voice != null) */ { +/* voice.allocate(); */ phrases = new LinkedBlockingQueue (); thread = new Thread(this); thread.start(); speak("Rocket Flight Monitor Ready"); - } else { + } /* else { System.out.printf("Voice manager failed to open %s\n", voice_name); Voice[] voices = voice_manager.getVoices(); System.out.printf("Available voices:\n"); @@ -64,6 +66,6 @@ public class AltosVoice implements Runnable { System.out.println(" " + voices[i].getName() + " (" + voices[i].getDomain() + " domain)"); } - } + } */ } } diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 57c889b8..1c49ba11 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -1,6 +1,6 @@ .SUFFIXES: .java .class -CLASSPATH=..:/usr/share/java/*:/home/keithp/src/freetts/freetts-1.2.2 +CLASSPATH=..:../libaltos:/usr/share/java/*:/home/keithp/src/freetts/freetts-1.2.2 CLASSFILES=\ AltosConvert.class \ AltosFile.class \ @@ -15,24 +15,18 @@ CLASSFILES=\ AltosTelemetry.class \ AltosUI.class \ AltosDevice.class \ - AltosDeviceLinux.class \ AltosDeviceDialog.class \ AltosVoice.class JAVAFLAGS=-Xlint:unchecked -all: $(CLASSFILES) altosui altosui.jar +all: $(CLASSFILES) altosui.jar .java.class: javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java -altosui: Makefile - (echo '#!/bin/sh'; \ - echo exec java -cp '"$(CLASSPATH)"' altosui/AltosUI) > $@ - chmod +x $@ - altosui.jar: $(CLASSFILES) Manifest.txt - cd .. && jar cfm altosui/$@ altosui/Manifest.txt altosui/*.class + jar cfm $@ altosui/Manifest.txt altosui/*.class libaltosJNI/*.class clean: rm -f *.class -- cgit v1.2.3 From 17188f36fe18c23bc2eb877ac9a01b7693f4b863 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 26 Jul 2010 17:03:47 -0700 Subject: Present list of altos devices in nice format --- ao-tools/altosui/AltosDevice.java | 18 ++++++++++-------- ao-tools/altosui/AltosDeviceDialog.java | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index 8ebd3b99..0e7d01da 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -20,32 +20,34 @@ import java.lang.*; import java.util.*; import libaltosJNI.*; -public class AltosDevice { +public class AltosDevice extends altos_device { + + public String toString() { + return String.format("%-20.20s %4d %s", + getProduct(), getSerial(), getPath()); + } static { System.loadLibrary("altos"); libaltos.altos_init(); } - static altos_device[] list(String product) { + static AltosDevice[] list(String product) { SWIGTYPE_p_altos_list list = libaltos.altos_list_start(); - ArrayList device_list = new ArrayList(); + ArrayList device_list = new ArrayList(); if (list != null) { SWIGTYPE_p_altos_file file; for (;;) { - altos_device device = new altos_device(); + AltosDevice device = new AltosDevice(); if (libaltos.altos_list_next(list, device) == 0) break; - System.out.printf("Found device %s %d %s\n", - device.getProduct(), device.getSerial(), device.getPath()); - device_list.add(device); } libaltos.altos_list_finish(list); } - altos_device[] devices = new altos_device[device_list.size()]; + AltosDevice[] devices = new AltosDevice[device_list.size()]; for (int i = 0; i < device_list.size(); i++) devices[i] = device_list.get(i); return devices; diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java index b3a0f9be..eb70877c 100644 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -29,7 +29,7 @@ import altosui.AltosDevice; public class AltosDeviceDialog { static altos_device show (JFrame frame, String product) { - altos_device[] devices = null; + AltosDevice[] devices; devices = AltosDevice.list(product); if (devices != null & devices.length > 0) { Object o = JOptionPane.showInputDialog(frame, -- cgit v1.2.3 From e9153c4f2c71ed965822fcfe5112d2bc38506baf Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 26 Jul 2010 17:04:04 -0700 Subject: Re-enable freetts --- ao-tools/altosui/AltosVoice.java | 20 +++++++++----------- ao-tools/altosui/Makefile | 2 +- ao-tools/altosui/Manifest.txt | 1 + 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java index 0c34795c..e4ea99a2 100644 --- a/ao-tools/altosui/AltosVoice.java +++ b/ao-tools/altosui/AltosVoice.java @@ -17,16 +17,14 @@ package altosui; -/*import com.sun.speech.freetts.Voice; +import com.sun.speech.freetts.Voice; import com.sun.speech.freetts.VoiceManager; -import com.sun.speech.freetts.audio.JavaClipAudioPlayer; */ +import com.sun.speech.freetts.audio.JavaClipAudioPlayer; import java.util.concurrent.LinkedBlockingQueue; public class AltosVoice implements Runnable { -/* VoiceManager voice_manager; Voice voice; -*/ LinkedBlockingQueue phrases; Thread thread; @@ -36,29 +34,29 @@ public class AltosVoice implements Runnable { try { for (;;) { String s = phrases.take(); -/* voice.speak(s); */ + voice.speak(s); } } catch (InterruptedException e) { } } public void speak(String s) { try { -/* if (voice != null) */ + if (voice != null) phrases.put(s); } catch (InterruptedException e) { } } public AltosVoice () { -/* voice_manager = VoiceManager.getInstance(); + voice_manager = VoiceManager.getInstance(); voice = voice_manager.getVoice(voice_name); - if (voice != null) */ { -/* voice.allocate(); */ + if (voice != null) { + voice.allocate(); phrases = new LinkedBlockingQueue (); thread = new Thread(this); thread.start(); speak("Rocket Flight Monitor Ready"); - } /* else { + } else { System.out.printf("Voice manager failed to open %s\n", voice_name); Voice[] voices = voice_manager.getVoices(); System.out.printf("Available voices:\n"); @@ -66,6 +64,6 @@ public class AltosVoice implements Runnable { System.out.println(" " + voices[i].getName() + " (" + voices[i].getDomain() + " domain)"); } - } */ + } } } diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 1c49ba11..4068eebe 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -1,6 +1,6 @@ .SUFFIXES: .java .class -CLASSPATH=..:../libaltos:/usr/share/java/*:/home/keithp/src/freetts/freetts-1.2.2 +CLASSPATH=..:../libaltos:/usr/share/java/*:/Users/keithp/freetts-1.2.2/lib/* CLASSFILES=\ AltosConvert.class \ AltosFile.class \ diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt index 0305fcfb..251ce2a0 100644 --- a/ao-tools/altosui/Manifest.txt +++ b/ao-tools/altosui/Manifest.txt @@ -1 +1,2 @@ Main-Class: altosui.AltosUI +Class-Path: freetts.jar -- cgit v1.2.3 From b51497597868a40df039dd3ca11b35a6258bbbb3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 26 Jul 2010 18:04:10 -0700 Subject: Re-enable Linux support for altosui. This steals code from cc-usbdev for scanning the USB tree and uses the same tty code as on Darwin Signed-off-by: Keith Packard --- ao-tools/altosui/Manifest.txt | 2 +- ao-tools/libaltos/Makefile | 39 +++- ao-tools/libaltos/libaltos.c | 476 +++++++++++++++++++++++++++++++++++------- 3 files changed, 430 insertions(+), 87 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt index 251ce2a0..7dbaafff 100644 --- a/ao-tools/altosui/Manifest.txt +++ b/ao-tools/altosui/Manifest.txt @@ -1,2 +1,2 @@ Main-Class: altosui.AltosUI -Class-Path: freetts.jar +Class-Path: /home/keithp/src/freetts/freetts-1.2.2/lib/freetts.jar diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 5ffbdadf..5cdc0fa7 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -1,3 +1,29 @@ +OS:=$(shell uname) + +ifeq ($(OS),Linux) + +JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include -I. + +OS_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) + +LIBEXT=so + +endif + +ifeq ($(OS),Darwin) + +DARWIN_CFLAGS=\ + -I/System/Library/Frameworks/JavaVM.framework/Headers \ + -I/System/Library/Frameworks/IOKit.framework/Headers \ + -I/System/Library/Frameworks/CoreFoundation.framework/Headers +DARWIN_LIBS=\ + -framework IOKit -framework CoreFoundation + +OS_CFLAGS = $(DARWIN_CFLAGS) -DDARWIN -DPOSIX_TTY +LIBEXT=dylib + +endif + .SUFFIXES: .java .class CLASSPATH=".:jnitest/*:libaltosJNI:/usr/share/java/*" @@ -14,8 +40,6 @@ JNI_SRCS=$(JNI_FILE) \ $(JNI_DIR)/altos_device.java \ $(JNI_DIR)/libaltos.java -LIBEXT=dylib - JAVAFILES=\ $(JNI_SRCS) @@ -28,14 +52,7 @@ all: libaltos.$(LIBEXT) cjnitest $(CLASSFILES) .java.class: javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java -DARWIN_CFLAGS=\ - -I/System/Library/Frameworks/JavaVM.framework/Headers \ - -I/System/Library/Frameworks/IOKit.framework/Headers \ - -I/System/Library/Frameworks/CoreFoundation.framework/Headers -DARWIN_LIBS=\ - -framework IOKit -framework CoreFoundation - -CFLAGS = $(DARWIN_CFLAGS) -I. -O0 -g +CFLAGS=$(OS_CFLAGS) -O0 -g HEADERS=libaltos.h SRCS = libaltos.c $(SWIG_WRAP) @@ -46,7 +63,7 @@ cjnitest: cjnitest.o $(OBJS) cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBS) libaltos.$(LIBEXT): $(OBJS) - gcc -shared -o $@ $(OBJS) $(LIBS) + gcc -shared -o $@ $(CFLAGS) $(OBJS) $(LIBS) clean: rm -f $(CLASSFILES) $(OBJS) libaltos.$(LIBEXT) cjnitest diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 417c8fe5..7d471f38 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -16,10 +16,379 @@ */ #include "libaltos.h" +#include +#include +#include + +static int +match_dev(char *product, int serial, struct altos_device *device) +{ + struct altos_list *list; + int i; + + list = altos_list_start(); + if (!list) + return 0; + while ((i = altos_list_next(list, device)) != 0) { + if (product && strncmp (product, device->product, strlen(product)) != 0) + continue; + if (serial && serial != device->serial) + continue; + break; + } + altos_list_finish(list); + return i; +} + +int +altos_find_by_arg(char *arg, char *default_product, struct altos_device *device) +{ + char *product; + int serial; + char *end; + char *colon; + int ret; + + if (arg) + { + /* check for */ + serial = strtol(arg, &end, 0); + if (end != arg) { + if (*end != '\0') + return 0; + product = NULL; + } else { + /* check for : */ + colon = strchr(arg, ':'); + if (colon) { + product = strndup(arg, colon - arg); + serial = strtol(colon + 1, &end, 0); + if (*end != '\0') + return 0; + } else { + product = arg; + serial = 0; + } + } + } else { + product = NULL; + serial = 0; + } + if (!product && default_product) + ret = match_dev(default_product, serial, device); + if (!ret) + ret = match_dev(product, serial, device); + if (product && product != arg) + free(product); + return ret; +} + +#ifdef LINUX + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +static char * +cc_fullname (char *dir, char *file) +{ + char *new; + int dlen = strlen (dir); + int flen = strlen (file); + int slen = 0; + + if (dir[dlen-1] != '/') + slen = 1; + new = malloc (dlen + slen + flen + 1); + if (!new) + return 0; + strcpy(new, dir); + if (slen) + strcat (new, "/"); + strcat(new, file); + return new; +} + +static char * +cc_basename(char *file) +{ + char *b; + + b = strrchr(file, '/'); + if (!b) + return file; + return b + 1; +} + +static char * +load_string(char *dir, char *file) +{ + char *full = cc_fullname(dir, file); + char line[4096]; + char *r; + FILE *f; + int rlen; + + f = fopen(full, "r"); + free(full); + if (!f) + return NULL; + r = fgets(line, sizeof (line), f); + fclose(f); + if (!r) + return NULL; + rlen = strlen(r); + if (r[rlen-1] == '\n') + r[rlen-1] = '\0'; + return strdup(r); +} + +static int +load_hex(char *dir, char *file) +{ + char *line; + char *end; + long i; + + line = load_string(dir, file); + if (!line) + return -1; + i = strtol(line, &end, 16); + free(line); + if (end == line) + return -1; + return i; +} + +static int +load_dec(char *dir, char *file) +{ + char *line; + char *end; + long i; + + line = load_string(dir, file); + if (!line) + return -1; + i = strtol(line, &end, 10); + free(line); + if (end == line) + return -1; + return i; +} + +static int +dir_filter_tty_colon(const struct dirent *d) +{ + return strncmp(d->d_name, "tty:", 4) == 0; +} + +static int +dir_filter_tty(const struct dirent *d) +{ + return strncmp(d->d_name, "tty", 3) == 0; +} -#define USE_DARWIN +struct altos_usbdev { + char *sys; + char *tty; + char *manufacturer; + char *product; + int serial; /* AltOS always uses simple integer serial numbers */ + int idProduct; + int idVendor; +}; -#ifdef USE_DARWIN +static char * +usb_tty(char *sys) +{ + char *base; + int num_configs; + int config; + struct dirent **namelist; + int interface; + int num_interfaces; + char endpoint_base[20]; + char *endpoint_full; + char *tty_dir; + int ntty; + char *tty; + + base = cc_basename(sys); + num_configs = load_hex(sys, "bNumConfigurations"); + num_interfaces = load_hex(sys, "bNumInterfaces"); + for (config = 1; config <= num_configs; config++) { + for (interface = 0; interface < num_interfaces; interface++) { + sprintf(endpoint_base, "%s:%d.%d", + base, config, interface); + endpoint_full = cc_fullname(sys, endpoint_base); + + /* Check for tty:ttyACMx style names + */ + ntty = scandir(endpoint_full, &namelist, + dir_filter_tty_colon, + alphasort); + if (ntty > 0) { + free(endpoint_full); + tty = cc_fullname("/dev", namelist[0]->d_name + 4); + free(namelist); + return tty; + } + + /* Check for tty/ttyACMx style names + */ + tty_dir = cc_fullname(endpoint_full, "tty"); + free(endpoint_full); + ntty = scandir(tty_dir, &namelist, + dir_filter_tty, + alphasort); + free (tty_dir); + if (ntty > 0) { + tty = cc_fullname("/dev", namelist[0]->d_name); + free(namelist); + return tty; + } + } + } + return NULL; +} + +static struct altos_usbdev * +usb_scan_device(char *sys) +{ + struct altos_usbdev *usbdev; + + usbdev = calloc(1, sizeof (struct altos_usbdev)); + if (!usbdev) + return NULL; + usbdev->sys = strdup(sys); + usbdev->manufacturer = load_string(sys, "manufacturer"); + usbdev->product = load_string(sys, "product"); + usbdev->serial = load_dec(sys, "serial"); + usbdev->idProduct = load_hex(sys, "idProduct"); + usbdev->idVendor = load_hex(sys, "idVendor"); + usbdev->tty = usb_tty(sys); + return usbdev; +} + +static void +usbdev_free(struct altos_usbdev *usbdev) +{ + free(usbdev->sys); + free(usbdev->manufacturer); + free(usbdev->product); + /* this can get used as a return value */ + if (usbdev->tty) + free(usbdev->tty); + free(usbdev); +} + +#define USB_DEVICES "/sys/bus/usb/devices" + +static int +dir_filter_dev(const struct dirent *d) +{ + const char *n = d->d_name; + char c; + + while ((c = *n++)) { + if (isdigit(c)) + continue; + if (c == '-') + continue; + if (c == '.' && n != d->d_name + 1) + continue; + return 0; + } + return 1; +} + +struct altos_list { + struct altos_usbdev **dev; + int current; + int ndev; +}; + +int +altos_init(void) +{ + return 1; +} + +void +altos_fini(void) +{ +} + +struct altos_list * +altos_list_start(void) +{ + int e; + struct dirent **ents; + char *dir; + struct altos_usbdev *dev; + struct altos_list *devs; + int n; + + devs = calloc(1, sizeof (struct altos_list)); + if (!devs) + return NULL; + + n = scandir (USB_DEVICES, &ents, + dir_filter_dev, + alphasort); + if (!n) + return 0; + for (e = 0; e < n; e++) { + dir = cc_fullname(USB_DEVICES, ents[e]->d_name); + dev = usb_scan_device(dir); + free(dir); + if (dev->idVendor == 0xfffe && dev->tty) { + if (devs->dev) + devs->dev = realloc(devs->dev, + devs->ndev + 1 * sizeof (struct usbdev *)); + else + devs->dev = malloc (sizeof (struct usbdev *)); + devs->dev[devs->ndev++] = dev; + } + } + free(ents); + devs->current = 0; + return devs; +} + +int +altos_list_next(struct altos_list *list, struct altos_device *device) +{ + struct altos_usbdev *dev; + if (list->current >= list->ndev) + return 0; + dev = list->dev[list->current]; + strcpy(device->product, dev->product); + strcpy(device->path, dev->tty); + device->serial = dev->serial; + list->current++; + return 1; +} + +void +altos_list_finish(struct altos_list *usbdevs) +{ + int i; + + if (!usbdevs) + return; + for (i = 0; i < usbdevs->ndev; i++) + usbdev_free(usbdevs->dev[i]); + free(usbdevs); +} + +#endif + +#ifdef DARWIN #include #include @@ -30,36 +399,32 @@ #include #include #include -#include -#include -#include -#include struct altos_list { - io_iterator_t iterator; + io_iterator_t iterator; }; static int get_string(io_object_t object, CFStringRef entry, char *result, int result_len) { - CFTypeRef entry_as_string; - Boolean got_string; - - entry_as_string = IORegistryEntrySearchCFProperty (object, - kIOServicePlane, - entry, - kCFAllocatorDefault, - kIORegistryIterateRecursively); - if (entry_as_string) { - got_string = CFStringGetCString(entry_as_string, - result, result_len, - kCFStringEncodingASCII); + CFTypeRef entry_as_string; + Boolean got_string; + + entry_as_string = IORegistryEntrySearchCFProperty (object, + kIOServicePlane, + entry, + kCFAllocatorDefault, + kIORegistryIterateRecursively); + if (entry_as_string) { + got_string = CFStringGetCString(entry_as_string, + result, result_len, + kCFStringEncodingASCII); - CFRelease(entry_as_string); - if (got_string) - return 1; - } - return 0; + CFRelease(entry_as_string); + if (got_string) + return 1; + } + return 0; } int @@ -117,10 +482,19 @@ altos_list_next(struct altos_list *list, struct altos_device *device) void altos_list_finish(struct altos_list *list) { - IOObjectRelease (list->iterator); - free(list); + IOObjectRelease (list->iterator); + free(list); } +#endif + +#ifdef POSIX_TTY + +#include +#include +#include +#include +#include #define USB_BUF_SIZE 64 @@ -133,54 +507,6 @@ struct altos_file { int in_read; }; -void -altos_test(char *path) -{ - int n; - char buf[16]; - int fd; - struct termios term; - - fd = open(path, O_RDWR | O_NOCTTY); - if (fd < 0) { - perror(path); - return; - } - if (ioctl(fd, TIOCEXCL, (char *) 0) < 0) { - perror("TIOCEXCL"); - close (fd); - return; - } - - n = tcgetattr(fd, &term); - if (n < 0) { - perror("tcgetattr"); - close(fd); - return; - } - cfmakeraw(&term); - term.c_cc[VMIN] = 0; - term.c_cc[VTIME] = 1; - n = tcsetattr(fd, TCSAFLUSH, &term); - if (n < 0) { - perror("tcsetattr"); - close(fd); - return; - } - write(fd, "\n?\n", 3); - for (;;) { - n = read(fd, buf, sizeof (buf)); - if (n < 0) { - perror("read"); - break; - } - if (n == 0) - break; - write(1, buf, n); - } - close(fd); -} - struct altos_file * altos_open(struct altos_device *device) { @@ -273,7 +599,7 @@ altos_getchar(struct altos_file *file, int timeout) return file->in_data[file->in_read++]; } -#endif /* USE_DARWIN */ +#endif /* POSIX_TTY */ #ifdef USE_LIBUSB #include -- cgit v1.2.3 From 0a782026f6b19e84ffd44f1ae1b466363474bd30 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 26 Jul 2010 18:10:07 -0700 Subject: Darwin doesn't have strndup. This provides a private version of this GNU extension. Signed-off-by: Keith Packard --- ao-tools/libaltos/libaltos.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 7d471f38..df0d5b2e 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -40,6 +40,26 @@ match_dev(char *product, int serial, struct altos_device *device) return i; } +#ifdef DARWIN +/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */ +static char * +altos_strndup (const char *s, size_t n) +{ + size_t len = strlen (s); + char *ret; + + if (len <= n) + return strdup (s); + ret = malloc(n + 1); + strncpy(ret, s, n); + ret[n] = '\0'; + return ret; +} + +#else +#define altos_strndup strndup +#endif + int altos_find_by_arg(char *arg, char *default_product, struct altos_device *device) { @@ -61,7 +81,7 @@ altos_find_by_arg(char *arg, char *default_product, struct altos_device *device) /* check for : */ colon = strchr(arg, ':'); if (colon) { - product = strndup(arg, colon - arg); + product = altos_strndup(arg, colon - arg); serial = strtol(colon + 1, &end, 0); if (*end != '\0') return 0; -- cgit v1.2.3 From fb8507975c6e081de2e909eca6faaa8f868b609e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 00:08:38 -0700 Subject: libaltos needs -I. on all systems Signed-off-by: Keith Packard --- ao-tools/libaltos/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 5cdc0fa7..7ed45b78 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -2,7 +2,7 @@ OS:=$(shell uname) ifeq ($(OS),Linux) -JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include -I. +JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include OS_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) @@ -52,7 +52,7 @@ all: libaltos.$(LIBEXT) cjnitest $(CLASSFILES) .java.class: javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java -CFLAGS=$(OS_CFLAGS) -O0 -g +CFLAGS=$(OS_CFLAGS) -O0 -g -I. HEADERS=libaltos.h SRCS = libaltos.c $(SWIG_WRAP) -- cgit v1.2.3 From 4e3285575e0c7d029e799258587e965779990099 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 00:09:18 -0700 Subject: libaltos: make clean remove all built files Signed-off-by: Keith Packard --- ao-tools/libaltos/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 7ed45b78..7463a95c 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -66,7 +66,8 @@ libaltos.$(LIBEXT): $(OBJS) gcc -shared -o $@ $(CFLAGS) $(OBJS) $(LIBS) clean: - rm -f $(CLASSFILES) $(OBJS) libaltos.$(LIBEXT) cjnitest + rm -f $(CLASSFILES) $(OBJS) libaltos.$(LIBEXT) cjnitest cjnitest.o + rm -rf swig_bindings libaltosJNI $(JNI_FILE): libaltos.i0 $(HEADERS) mkdir -p $(SWIG_DIR) -- cgit v1.2.3 From a58c44cd904e5429b807e5c23913051ed6484edc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 00:09:41 -0700 Subject: libaltos: build fat 10.5-compatible library Signed-off-by: Keith Packard --- ao-tools/libaltos/Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 7463a95c..0bbd304c 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -13,13 +13,14 @@ endif ifeq ($(OS),Darwin) DARWIN_CFLAGS=\ - -I/System/Library/Frameworks/JavaVM.framework/Headers \ - -I/System/Library/Frameworks/IOKit.framework/Headers \ - -I/System/Library/Frameworks/CoreFoundation.framework/Headers + --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ + -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ + -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ + -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers DARWIN_LIBS=\ -framework IOKit -framework CoreFoundation -OS_CFLAGS = $(DARWIN_CFLAGS) -DDARWIN -DPOSIX_TTY +OS_CFLAGS = $(DARWIN_CFLAGS) -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 LIBEXT=dylib endif @@ -63,7 +64,7 @@ cjnitest: cjnitest.o $(OBJS) cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBS) libaltos.$(LIBEXT): $(OBJS) - gcc -shared -o $@ $(CFLAGS) $(OBJS) $(LIBS) + gcc -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) clean: rm -f $(CLASSFILES) $(OBJS) libaltos.$(LIBEXT) cjnitest cjnitest.o -- cgit v1.2.3 From 2c273710ea9b76ebee4101893f9fe84be8a02354 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 00:11:58 -0700 Subject: Add Mac OS X packaging files for altosui --- .../libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml | 1 + ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml | 1 + ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml | 1 + 3 files changed, 3 insertions(+) create mode 100644 ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml create mode 100644 ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml create mode 100644 ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml (limited to 'ao-tools') diff --git a/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml b/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml new file mode 100644 index 00000000..e19a1e4c --- /dev/null +++ b/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml b/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml new file mode 100644 index 00000000..5d84e5f0 --- /dev/null +++ b/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml @@ -0,0 +1 @@ +org.altusmetrum.altosUi.AltosUI.pkg1.0/Users/keithp/AltosUI.app/Applications/AltosUI.appinstallTo.pathparentrequireAuthorizationinstallTo01altosui-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ \ No newline at end of file diff --git a/ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml b/ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml new file mode 100644 index 00000000..1277db62 --- /dev/null +++ b/ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml @@ -0,0 +1 @@ +AltOS UI/Users/keithp/Documents/AltosUI.pkgorg.altusmetrum01altosui.xmlproperties.title \ No newline at end of file -- cgit v1.2.3 From 3784578a40dcc61f447435cfdf22e13c409cb9c0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 00:16:15 -0700 Subject: Add application icons for Mac OS X --- ao-tools/altosui/AltosUIIcon.icns | Bin 0 -> 129010 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ao-tools/altosui/AltosUIIcon.icns (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUIIcon.icns b/ao-tools/altosui/AltosUIIcon.icns new file mode 100644 index 00000000..fe49f362 Binary files /dev/null and b/ao-tools/altosui/AltosUIIcon.icns differ -- cgit v1.2.3 From 809feb75e2155e84aebfcc431867edcfd9054670 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 01:22:56 -0700 Subject: Clean up altosui build a bit --- ao-tools/Makefile.am | 2 +- ao-tools/altosui/Makefile | 35 +++++++++++++++++++++++++++++++---- ao-tools/altosui/Manifest.txt | 2 +- ao-tools/altosui/voices.txt | 1 - 4 files changed, 33 insertions(+), 7 deletions(-) delete mode 100644 ao-tools/altosui/voices.txt (limited to 'ao-tools') diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 2850e909..54dc777a 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-dumplog ao-bitbang ao-eeprom ao-list ao-load ao-postflight ao-view +SUBDIRS=lib ao-rawload ao-dbg ao-dumplog ao-bitbang ao-eeprom ao-list ao-load ao-postflight ao-view libaltos altosui diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 4068eebe..aa0278a8 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -1,6 +1,6 @@ .SUFFIXES: .java .class -CLASSPATH=..:../libaltos:/usr/share/java/*:/Users/keithp/freetts-1.2.2/lib/* +CLASSPATH=classes:./* CLASSFILES=\ AltosConvert.class \ AltosFile.class \ @@ -18,15 +18,42 @@ CLASSFILES=\ AltosDeviceDialog.class \ AltosVoice.class +FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 +FREETTSLIB=$(FREETTSSRC)/lib +FREETTSJAR= \ + cmudict04.jar \ + cmulex.jar \ + cmu_time_awb.jar \ + cmutimelex.jar \ + cmu_us_kal.jar \ + en_us.jar \ + freetts.jar \ + freetts-jsapi10.jar \ + jsapi.jar + JAVAFLAGS=-Xlint:unchecked -all: $(CLASSFILES) altosui.jar +all: altosui.jar + +$(CLASSFILES): classes/altosui classes/libaltosJNI $(FREETTSJAR) .java.class: javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java altosui.jar: $(CLASSFILES) Manifest.txt - jar cfm $@ altosui/Manifest.txt altosui/*.class libaltosJNI/*.class + cd ./classes && jar cfm ../$@ altosui/Manifest.txt altosui/*.class libaltosJNI/*.class + +classes/altosui: + mkdir -p classes + ln -s .. classes/altosui + +classes/libaltosJNI: + mkdir -p classes + ln -s ../../libaltos/libaltosJNI classes/libaltosJNI + +$(FREETTSJAR): + ln -s $(FREETTSLIB)/$@ . clean: - rm -f *.class + rm -f *.class $(FREETTSJAR) altosui.jar + rm -rf classes diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt index 7dbaafff..251ce2a0 100644 --- a/ao-tools/altosui/Manifest.txt +++ b/ao-tools/altosui/Manifest.txt @@ -1,2 +1,2 @@ Main-Class: altosui.AltosUI -Class-Path: /home/keithp/src/freetts/freetts-1.2.2/lib/freetts.jar +Class-Path: freetts.jar diff --git a/ao-tools/altosui/voices.txt b/ao-tools/altosui/voices.txt deleted file mode 100644 index e8825fc3..00000000 --- a/ao-tools/altosui/voices.txt +++ /dev/null @@ -1 +0,0 @@ -com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory -- cgit v1.2.3 From 734cd15ccff691f851359518ce6118f29dc9f88d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 10:18:09 -0700 Subject: Remove directories as .class file dependencies; it makes them get rebuilt all the time --- ao-tools/altosui/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index aa0278a8..cd123023 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -35,12 +35,12 @@ JAVAFLAGS=-Xlint:unchecked all: altosui.jar -$(CLASSFILES): classes/altosui classes/libaltosJNI $(FREETTSJAR) +$(CLASSFILES): .java.class: javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java -altosui.jar: $(CLASSFILES) Manifest.txt +altosui.jar: classes/altosui classes/libaltosJNI $(FREETTSJAR) $(CLASSFILES) Manifest.txt cd ./classes && jar cfm ../$@ altosui/Manifest.txt altosui/*.class libaltosJNI/*.class classes/altosui: -- cgit v1.2.3 From 8f2f38f2a9fb0c106e2c6b60cdc205292ce329ea Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 10:18:20 -0700 Subject: Java clean ups -- use varargs where possible, remove AltosSerialReader Add methods that format stuff using String.format for voice and serial link, remove AltosSerialReader class and just embed that in the AltosSerial class directly. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 53 +++++++++++++-------------------------- ao-tools/altosui/AltosUI.java | 28 ++++++++------------- ao-tools/altosui/AltosVoice.java | 4 +++ 3 files changed, 32 insertions(+), 53 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 073bfb78..e84f5b63 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -37,7 +37,9 @@ import libaltosJNI.SWIGTYPE_p_altos_list; * line in a queue. Dealing with that queue is left up to other * threads. */ -class AltosSerialReader implements Runnable { + +public class AltosSerial implements Runnable { + SWIGTYPE_p_altos_file altos; LinkedList> monitors; LinkedBlockingQueue reply_queue; @@ -116,13 +118,27 @@ class AltosSerialReader implements Runnable { } } + public void putc(char c) { + libaltos.altos_putchar(altos, c); + } + + public void print(String data) { + for (int i = 0; i < data.length(); i++) + putc(data.charAt(i)); + } + + public void printf(String format, Object ... arguments) { + print(String.format(format, arguments)); + } + public void open(altos_device device) throws FileNotFoundException { close(); altos = libaltos.altos_open(device); input_thread = new Thread(this); input_thread.start(); } - public AltosSerialReader () { + + public AltosSerial() { altos = null; input_thread = null; line = ""; @@ -130,36 +146,3 @@ class AltosSerialReader implements Runnable { reply_queue = new LinkedBlockingQueue (); } } - -public class AltosSerial { - AltosSerialReader reader = null; - - public void close() { - reader.close(); - } - - public void open(altos_device device) throws FileNotFoundException { - reader.open(device); - } - - void init() { - reader = new AltosSerialReader(); - } - - public void add_monitor(LinkedBlockingQueue q) { - reader.add_monitor(q); - } - - public void remove_monitor(LinkedBlockingQueue q) { - reader.remove_monitor(q); - } - - public AltosSerial() { - init(); - } - - public AltosSerial(altos_device device) throws FileNotFoundException { - init(); - open(device); - } -} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 33ed2c90..43aae295 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -221,16 +221,8 @@ public class AltosUI extends JFrame { flightInfoModel[col].addRow(name, value); } - public void info_add_row(int col, String name, String format, Object value) { - flightInfoModel[col].addRow(name, String.format(format, value)); - } - - public void info_add_row(int col, String name, String format, Object v1, Object v2) { - flightInfoModel[col].addRow(name, String.format(format, v1, v2)); - } - - public void info_add_row(int col, String name, String format, Object v1, Object v2, Object v3) { - flightInfoModel[col].addRow(name, String.format(format, v1, v2, v3)); + public void info_add_row(int col, String name, String format, Object... parameters) { + flightInfoModel[col].addRow(name, String.format(format, parameters)); } public void info_add_deg(int col, String name, double v, int pos, int neg) { @@ -367,7 +359,7 @@ public class AltosUI extends JFrame { /* If the rocket isn't on the pad, then report height */ if (state.state > AltosTelemetry.ao_flight_pad) { - voice.speak(String.format("%d meters", (int) (state.height + 0.5))); + voice.speak("%d meters", (int) (state.height + 0.5)); } /* If the rocket is coming down, check to see if it has landed; @@ -383,9 +375,9 @@ public class AltosUI extends JFrame { else voice.speak("rocket may have crashed"); if (state.gps != null) - voice.speak(String.format("bearing %d degrees, range %d meters", - (int) (state.from_pad.bearing + 0.5), - (int) (state.from_pad.distance + 0.5))); + voice.speak("bearing %d degrees, range %d meters", + (int) (state.from_pad.bearing + 0.5), + (int) (state.from_pad.distance + 0.5)); ++reported_landing; } } @@ -403,12 +395,12 @@ public class AltosUI extends JFrame { voice.speak(state.data.state); switch (state.state) { case AltosTelemetry.ao_flight_fast: - voice.speak(String.format("max speed %d meters per second", - (int) (state.max_speed + 0.5))); + voice.speak("max speed %d meters per second", + (int) (state.max_speed + 0.5)); break; case AltosTelemetry.ao_flight_drogue: - voice.speak(String.format("max height %d meters", - (int) (state.max_height + 0.5))); + voice.speak("max height %d meters", + (int) (state.max_height + 0.5)); break; } } diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java index e4ea99a2..c39bfb9b 100644 --- a/ao-tools/altosui/AltosVoice.java +++ b/ao-tools/altosui/AltosVoice.java @@ -47,6 +47,10 @@ public class AltosVoice implements Runnable { } } + public void speak(String format, Object... parameters) { + speak(String.format(format, parameters)); + } + public AltosVoice () { voice_manager = VoiceManager.getInstance(); voice = voice_manager.getVoice(voice_name); -- cgit v1.2.3 From 81bf2042ca39eb106b789e5a08647c3114669358 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 15:29:28 -0700 Subject: Java voice reporting cleanups. Make sure it says something at the end of a log file replay. Make sure it reports max speed after motor burn out, and max height after apogee. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 110 ++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 46 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 43aae295..3dfc8952 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -338,48 +338,57 @@ public class AltosUI extends JFrame { class IdleThread extends Thread { private AltosState state; + int reported_landing; + + public void report(boolean last) { + if (state == null) + return; + + /* reset the landing count once we hear about a new flight */ + if (state.state < AltosTelemetry.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 (state.state > AltosTelemetry.ao_flight_pad) { + voice.speak("%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.ascent && + (last || + System.currentTimeMillis() - state.report_time >= 15000 || + state.state == AltosTelemetry.ao_flight_landed)) + { + if (Math.abs(state.baro_speed) < 20 && state.height < 100) + voice.speak("rocket landed safely"); + else + voice.speak("rocket may have crashed"); + if (state.gps != null) + voice.speak("bearing %d degrees, range %d meters", + (int) (state.from_pad.bearing + 0.5), + (int) (state.from_pad.distance + 0.5)); + ++reported_landing; + } + } public void run () { - int reported_landing = 0; + reported_landing = 0; state = null; try { for (;;) { Thread.sleep(10000); - if (state == null) - continue; - - /* reset the landing count once we hear about a new flight */ - if (state.state < AltosTelemetry.ao_flight_drogue) - reported_landing = 0; - - /* Shut up once the rocket is on the ground */ - if (reported_landing > 2) - continue; - - /* If the rocket isn't on the pad, then report height */ - if (state.state > AltosTelemetry.ao_flight_pad) { - voice.speak("%d meters", (int) (state.height + 0.5)); - } - - /* 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.ascent && - (System.currentTimeMillis() - state.report_time > 10000 || - state.state == AltosTelemetry.ao_flight_landed)) - { - if (Math.abs(state.baro_speed) < 20 && state.height < 100) - voice.speak("rocket landed safely"); - else - voice.speak("rocket may have crashed"); - if (state.gps != null) - voice.speak("bearing %d degrees, range %d meters", - (int) (state.from_pad.bearing + 0.5), - (int) (state.from_pad.distance + 0.5)); - ++reported_landing; - } + report(false); } } catch (InterruptedException ie) { } @@ -393,21 +402,22 @@ public class AltosUI extends JFrame { private void tell(AltosState state, AltosState old_state) { if (old_state == null || old_state.state != state.state) { voice.speak(state.data.state); - switch (state.state) { - case AltosTelemetry.ao_flight_fast: - voice.speak("max speed %d meters per second", + if ((old_state == null || old_state.state <= AltosTelemetry.ao_flight_boost) && + state.state > AltosTelemetry.ao_flight_boost) { + voice.speak("max speed: %d meters per second.", (int) (state.max_speed + 0.5)); - break; - case AltosTelemetry.ao_flight_drogue: - voice.speak("max height %d meters", + } else if ((old_state == null || old_state.state < AltosTelemetry.ao_flight_drogue) && + state.state >= AltosTelemetry.ao_flight_drogue) { + voice.speak("max height: %d meters.", (int) (state.max_height + 0.5)); - break; } } old_state = state; } class DisplayThread extends Thread { + IdleThread idle_thread; + String read() throws InterruptedException { return null; } void close() { } @@ -418,7 +428,8 @@ public class AltosUI extends JFrame { String line; AltosState state = null; AltosState old_state = null; - IdleThread idle_thread = new IdleThread(); + + idle_thread = new IdleThread(); info_reset(); info_finish(); @@ -444,6 +455,11 @@ public class AltosUI extends JFrame { idle_thread.interrupt(); } } + + public void report() { + if (idle_thread != null) + idle_thread.report(true); + } } class DeviceThread extends DisplayThread { @@ -500,8 +516,9 @@ public class AltosUI extends JFrame { while ((c = s.read()) != -1) { if (c == '\r') continue; - if (c == '\n') + if (c == '\n') { return line; + } line = line + (char) c; } return null; @@ -537,12 +554,13 @@ public class AltosUI extends JFrame { replay.close(); } catch (IOException ee) { } + report(); } void update(AltosState state) throws InterruptedException { /* Make it run in realtime after the rocket leaves the pad */ if (state.state > AltosTelemetry.ao_flight_pad) - Thread.sleep((int) (state.time_change * 1000)); + Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); } } @@ -583,7 +601,7 @@ public class AltosUI extends JFrame { } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, filename, - "Cannot open serial port", + "Cannot open telemetry file", JOptionPane.ERROR_MESSAGE); } } -- cgit v1.2.3 From 554a97ef455c801dcab825815f44520f96f4c3f3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jul 2010 19:29:38 -0700 Subject: Force java source encoding to UTF-8 --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 4068eebe..39d1a70c 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -23,7 +23,7 @@ JAVAFLAGS=-Xlint:unchecked all: $(CLASSFILES) altosui.jar .java.class: - javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java + javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java altosui.jar: $(CLASSFILES) Manifest.txt jar cfm $@ altosui/Manifest.txt altosui/*.class libaltosJNI/*.class -- cgit v1.2.3 From e76b9cc32bbcc5176d9bdd6f8d79778024627382 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 12:24:53 -0700 Subject: altosui: Catch errors opening USB devices. Limit list to relevant devices Avoids a segfault when failing to open a device. Limit listed telemetry devices to just TeleDongle units. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDevice.java | 3 ++- ao-tools/altosui/AltosDeviceDialog.java | 4 ++++ ao-tools/altosui/AltosSerial.java | 2 ++ ao-tools/altosui/AltosUI.java | 5 +++-- 4 files changed, 11 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index 0e7d01da..f488174c 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -42,7 +42,8 @@ public class AltosDevice extends altos_device { AltosDevice device = new AltosDevice(); if (libaltos.altos_list_next(list, device) == 0) break; - device_list.add(device); + if (product == null || device.getProduct().startsWith(product)) + device_list.add(device); } libaltos.altos_list_finish(list); } diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java index eb70877c..08921c3d 100644 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -41,6 +41,10 @@ public class AltosDeviceDialog { devices[0]); return (altos_device) o; } else { + JOptionPane.showMessageDialog(frame, + "No AltOS devices available", + "No AltOS devices", + JOptionPane.ERROR_MESSAGE); return null; } } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index e84f5b63..b016c1d6 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -134,6 +134,8 @@ public class AltosSerial implements Runnable { public void open(altos_device device) throws FileNotFoundException { close(); altos = libaltos.altos_open(device); + if (altos == null) + throw new FileNotFoundException(device.getPath()); input_thread = new Thread(this); input_thread.start(); } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 3dfc8952..5c92b9b4 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -493,8 +493,9 @@ public class AltosUI extends JFrame { run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, - device.getPath(), - "Cannot open serial port", + String.format("Cannot open device \"%s\"", + device.getPath()), + "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, -- cgit v1.2.3 From 71da54a5ce255395376a44586782ab8b6f3b289f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 13:01:52 -0700 Subject: Make voice and channel menus work. Stores voice and channel data to preferences. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosPreferences.java | 40 ++++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosSerial.java | 14 +++++++++++- ao-tools/altosui/AltosUI.java | 18 +++++++++++---- ao-tools/altosui/AltosVoice.java | 9 ++++++-- 4 files changed, 74 insertions(+), 7 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosPreferences.java b/ao-tools/altosui/AltosPreferences.java index 0296d935..297e1aae 100644 --- a/ao-tools/altosui/AltosPreferences.java +++ b/ao-tools/altosui/AltosPreferences.java @@ -31,6 +31,12 @@ class AltosPreferences { /* logdir preference name */ final static String logdirPreference = "LOGDIR"; + /* channel preference name */ + final static String channelPreference = "CHANNEL"; + + /* voice preference name */ + final static String voicePreference = "VOICE"; + /* Default logdir is ~/TeleMetrum */ final static String logdirName = "TeleMetrum"; @@ -40,6 +46,12 @@ class AltosPreferences { /* Log directory */ static File logdir; + /* Telemetry channel */ + static int channel; + + /* Voice preference */ + static boolean voice; + public static void init(Component ui) { preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); @@ -55,6 +67,10 @@ class AltosPreferences { if (!logdir.exists()) logdir.mkdirs(); } + + channel = preferences.getInt(channelPreference, 0); + + voice = preferences.getBoolean(voicePreference, true); } static void flush_preferences() { @@ -114,4 +130,28 @@ class AltosPreferences { public static File logdir() { return logdir; } + + public static void set_channel(int new_channel) { + channel = new_channel; + synchronized (preferences) { + preferences.putInt(channelPreference, channel); + flush_preferences(); + } + } + + public static int channel() { + return channel; + } + + public static void set_voice(boolean new_voice) { + voice = new_voice; + synchronized (preferences) { + preferences.putBoolean(voicePreference, voice); + flush_preferences(); + } + } + + public static boolean voice() { + return voice; + } } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index b016c1d6..f12b31b3 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -119,7 +119,8 @@ public class AltosSerial implements Runnable { } public void putc(char c) { - libaltos.altos_putchar(altos, c); + if (altos != null) + libaltos.altos_putchar(altos, c); } public void print(String data) { @@ -138,6 +139,17 @@ public class AltosSerial implements Runnable { throw new FileNotFoundException(device.getPath()); input_thread = new Thread(this); input_thread.start(); + print("\nE 0\nm 1\n"); + try { + Thread.sleep(200); + } catch (InterruptedException e) { + } + flush(); + } + + public void set_channel(int channel) { + if (altos != null) + printf("m 0\nc r %d\nm 1\n", channel); } public AltosSerial() { diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 5c92b9b4..511c3709 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -210,6 +210,7 @@ public class AltosUI extends JFrame { System.exit(0); } }); + voice.speak("Rocket flight monitor ready."); } public void info_reset() { @@ -490,6 +491,7 @@ public class AltosUI extends JFrame { try { serial_line.open(device); DeviceThread thread = new DeviceThread(serial_line); + serial_line.set_channel(AltosPreferences.channel()); run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, @@ -706,9 +708,16 @@ public class AltosUI extends JFrame { menu.setMnemonic(KeyEvent.VK_V); menubar.add(menu); - radioitem = new JRadioButtonMenuItem("Enable Voice"); + radioitem = new JRadioButtonMenuItem("Enable Voice", AltosPreferences.voice()); radioitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + JRadioButtonMenuItem item = (JRadioButtonMenuItem) e.getSource(); + boolean enabled = item.isSelected(); + AltosPreferences.set_voice(enabled); + if (enabled) + voice.speak_always("Enable voice."); + else + voice.speak_always("Disable voice."); } }); menu.add(radioitem); @@ -724,12 +733,13 @@ public class AltosUI extends JFrame { for (int c = 0; c <= 9; c++) { radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c, 434.550 + c * 0.1), - c == 0); + c == AltosPreferences.channel()); radioitem.setActionCommand(String.format("%d", c)); radioitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - System.out.println("Command: " + e.getActionCommand() + " param: " + - e.paramString()); + int new_channel = Integer.parseInt(e.getActionCommand()); + AltosPreferences.set_channel(new_channel); + serial_line.set_channel(new_channel); } }); menu.add(radioitem); diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java index c39bfb9b..ebe9d5a8 100644 --- a/ao-tools/altosui/AltosVoice.java +++ b/ao-tools/altosui/AltosVoice.java @@ -39,7 +39,8 @@ public class AltosVoice implements Runnable { } catch (InterruptedException e) { } } - public void speak(String s) { + + public void speak_always(String s) { try { if (voice != null) phrases.put(s); @@ -47,6 +48,11 @@ public class AltosVoice implements Runnable { } } + public void speak(String s) { + if (AltosPreferences.voice()) + speak_always(s); + } + public void speak(String format, Object... parameters) { speak(String.format(format, parameters)); } @@ -59,7 +65,6 @@ public class AltosVoice implements Runnable { phrases = new LinkedBlockingQueue (); thread = new Thread(this); thread.start(); - speak("Rocket Flight Monitor Ready"); } else { System.out.printf("Voice manager failed to open %s\n", voice_name); Voice[] voices = voice_manager.getVoices(); -- cgit v1.2.3 From 826061eaca88c0dd75051a6006ef6703c91af595 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 13:10:11 -0700 Subject: Add voice test command for help in adjusting volume. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 511c3709..e1697ee1 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -721,6 +721,13 @@ public class AltosUI extends JFrame { } }); menu.add(radioitem); + item = new JMenuItem("Test Voice",KeyEvent.VK_T); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + voice.speak("That's one small step for man; one giant leap for mankind."); + } + }); + menu.add(item); } // Channel menu -- cgit v1.2.3 From 024d077302f91bdb17abe70d3211ab0949dab8b9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 13:29:21 -0700 Subject: Remove debug printf Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 1 - 1 file changed, 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index e1697ee1..ecacffe5 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -474,7 +474,6 @@ public class AltosUI extends JFrame { void close() { serial.close(); serial.remove_monitor(telem); - System.out.println("DisplayThread done"); } public DeviceThread(AltosSerial s) { -- cgit v1.2.3 From 6599e9576c3da9325a1731144c1b8bc4943184c0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 15:41:34 -0700 Subject: altosui: Add eeprom data capture function. No UI yet. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEeprom.java | 264 ++++++++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosFile.java | 23 +++- ao-tools/altosui/AltosSerial.java | 2 +- ao-tools/altosui/AltosUI.java | 1 + ao-tools/altosui/Makefile | 1 + 5 files changed, 283 insertions(+), 8 deletions(-) create mode 100644 ao-tools/altosui/AltosEeprom.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEeprom.java b/ao-tools/altosui/AltosEeprom.java new file mode 100644 index 00000000..54e0bbc4 --- /dev/null +++ b/ao-tools/altosui/AltosEeprom.java @@ -0,0 +1,264 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosSerial; +import altosui.AltosSerialMonitor; +import altosui.AltosTelemetry; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; + +import libaltosJNI.*; + +public class AltosEeprom { + + static final int AO_LOG_FLIGHT = 'F'; + static final int AO_LOG_SENSOR = 'A'; + static final int AO_LOG_TEMP_VOLT = 'T'; + static final int AO_LOG_DEPLOY = 'D'; + static final int AO_LOG_STATE = 'S'; + static final int AO_LOG_GPS_TIME = 'G'; + static final int AO_LOG_GPS_LAT = 'N'; + static final int AO_LOG_GPS_LON = 'W'; + static final int AO_LOG_GPS_ALT = 'H'; + static final int AO_LOG_GPS_SAT = 'V'; + static final int AO_LOG_GPS_DATE = 'Y'; + + static final int ao_flight_startup = 0; + static final int ao_flight_idle = 1; + static final int ao_flight_pad = 2; + static final int ao_flight_boost = 3; + static final int ao_flight_fast = 4; + static final int ao_flight_coast = 5; + static final int ao_flight_drogue = 6; + static final int ao_flight_main = 7; + static final int ao_flight_landed = 8; + static final int ao_flight_invalid = 9; + + static String[] state_names = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid", + }; + + static int[] ParseHex(String line) { + String[] tokens = line.split("\\s+"); + int[] array = new int[tokens.length]; + + for (int i = 0; i < tokens.length; i++) + try { + array[i] = Integer.parseInt(tokens[i], 16); + } catch (NumberFormatException ne) { + return null; + } + return array; + } + + static int checksum(int[] line) { + int csum = 0x5a; + for (int i = 1; i < line.length; i++) + csum += line[i]; + return csum & 0xff; + } + + static void FlushPending(FileWriter file, LinkedList pending) throws IOException { + while (!pending.isEmpty()) { + file.write(pending.remove()); + } + } + + static void CaptureLog(AltosSerial serial_line) throws IOException, InterruptedException { + int serial = 0; + int block; + int addr; + int flight = 0; + int year = 0, month = 0, day = 0; + int state = 0; + boolean done = false; + boolean want_file = false; + boolean any_valid; + FileWriter eeprom_file = null; + AltosFile eeprom_name; + LinkedList eeprom_pending = new LinkedList(); + + serial_line.printf("v\n"); + + /* Pull the serial number out of the version information */ + + for (;;) { + String line = serial_line.get_reply(); + + if (line.startsWith("serial-number")) { + try { + serial = Integer.parseInt(line.substring(13).trim()); + eeprom_pending.add(String.format("%s\n", line)); + } catch (NumberFormatException ne) { + serial = 0; + } + } + + /* signals the end of the version info */ + if (line.startsWith("software-version")) + break; + } + if (serial == 0) + throw new IOException("no serial number found"); + + /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */ + + for (block = 0; !done && block < 511; block++) { + serial_line.printf("e %x\n", block); + any_valid = false; + for (addr = 0; addr < 0x100;) { + String line = serial_line.get_reply(); + int[] values = ParseHex(line); + + if (values == null) { + System.out.printf("invalid line: %s\n", line); + } else if (values[0] != addr) { + System.out.printf("data address out of sync at 0x%x\n", + block * 256 + values[0]); + } else if (checksum(values) != 0) { + System.out.printf("invalid checksum at 0x%x\n", + block * 256 + values[0]); + } else { + any_valid = true; + int cmd = values[1]; + int tick = values[3] + (values[4] << 8); + int a = values[5] + (values[6] << 8); + int b = values[7] + (values[8] << 8); + + if (cmd == AO_LOG_FLIGHT) + flight = b; + + /* Monitor state transitions to update display */ + if (cmd == AO_LOG_STATE && a <= ao_flight_landed) { + System.out.printf ("%s\n", state_names[a]); + if (a > ao_flight_pad) + want_file = true; + state = a; + } + + if (cmd == AO_LOG_GPS_DATE) { + year = 2000 + (a & 0xff); + month = (a >> 8) & 0xff; + day = (b & 0xff); + want_file = true; + } + + if (eeprom_file == null) { + if (serial != 0 && flight != 0 && want_file) { + if (year != 0 && month != 0 && day != 0) + eeprom_name = new AltosFile(year, month, day, serial, flight, "eeprom-new"); + else + eeprom_name = new AltosFile(serial, flight, "eeprom-new"); + + eeprom_file = new FileWriter(eeprom_name); + if (eeprom_file != null) { + FlushPending(eeprom_file, eeprom_pending); + eeprom_pending = null; + } + } + } + + String log_line = String.format("%c %4x %4x %4x\n", + cmd, tick, a, b); + if (eeprom_file != null) + eeprom_file.write(log_line); + else + eeprom_pending.add(log_line); + + if (cmd == AO_LOG_STATE && a == ao_flight_landed) { + done = true; + } + } + addr += 8; + } + if (!any_valid) + done = true; + } + if (eeprom_file == null) { + eeprom_name = new AltosFile(serial,flight,"eeprom-new"); + eeprom_file = new FileWriter(eeprom_name); + if (eeprom_file != null) { + FlushPending(eeprom_file, eeprom_pending); + } + } + if (eeprom_file != null) { + eeprom_file.flush(); + eeprom_file.close(); + } + } + + public static void SaveFlightData (JFrame frame) { + altos_device device = AltosDeviceDialog.show(frame, null); + boolean remote = false; + AltosSerial serial_line = new AltosSerial(); + + if (device == null) + return; + try { + serial_line.open(device); + if (!device.getProduct().startsWith("TeleMetrum")) + remote = true; + + if (remote) { + serial_line.printf("m 0\n"); + serial_line.set_channel(AltosPreferences.channel()); + serial_line.printf("p\n"); + } + CaptureLog(serial_line); + if (remote) + serial_line.printf("~"); + serial_line.close(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + String.format("Cannot open device \"%s\"", + device.getPath()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(frame, + device.getPath(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } catch (InterruptedException ie) { + } + } +} diff --git a/ao-tools/altosui/AltosFile.java b/ao-tools/altosui/AltosFile.java index c7ee8679..7f65381f 100644 --- a/ao-tools/altosui/AltosFile.java +++ b/ao-tools/altosui/AltosFile.java @@ -24,14 +24,23 @@ import altosui.AltosTelemetry; import altosui.AltosPreferences; class AltosFile extends File { - public AltosFile(AltosTelemetry telem) { + + public AltosFile(int year, int month, int day, int serial, int flight, String extension) { super (AltosPreferences.logdir(), String.format("%04d-%02d-%02d-serial-%03d-flight-%03d.%s", - Calendar.getInstance().get(Calendar.YEAR), - Calendar.getInstance().get(Calendar.MONTH), - Calendar.getInstance().get(Calendar.DAY_OF_MONTH), - telem.serial, - telem.flight, - "telem")); + year, month, day, serial, flight, extension)); + } + + public AltosFile(int serial, int flight, String extension) { + this(Calendar.getInstance().get(Calendar.YEAR), + Calendar.getInstance().get(Calendar.MONTH) + 1, + Calendar.getInstance().get(Calendar.DAY_OF_MONTH), + serial, + flight, + extension); + } + + public AltosFile(AltosTelemetry telem) { + this(telem.serial, telem.flight, "telem"); } } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index f12b31b3..a5566ab8 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -139,7 +139,7 @@ public class AltosSerial implements Runnable { throw new FileNotFoundException(device.getPath()); input_thread = new Thread(this); input_thread.start(); - print("\nE 0\nm 1\n"); + print("\nE 0\n"); try { Thread.sleep(200); } catch (InterruptedException e) { diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index ecacffe5..92c3d0a3 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -613,6 +613,7 @@ public class AltosUI extends JFrame { * a TeleDongle over the packet link */ private void SaveFlightData() { + AltosEeprom.SaveFlightData(AltosUI.this); } /* Create the AltosUI menus diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 0613a494..2a91d657 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -3,6 +3,7 @@ CLASSPATH=classes:./* CLASSFILES=\ AltosConvert.class \ + AltosEeprom.class \ AltosFile.class \ AltosGPS.class \ AltosGreatCircle.class \ -- cgit v1.2.3 From ce90f3fe2aa6e23695ccccb36a8e6e614a08ba31 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 17:08:42 -0700 Subject: altosui: Add progress bar for eeprom downloading status This has a progress bar tracking the state and block count while downloading stuff from telemetrum. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEeprom.java | 87 +++++++++++++++-------- ao-tools/altosui/AltosEepromMonitor.java | 118 +++++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 2 +- ao-tools/altosui/Makefile | 1 + 4 files changed, 178 insertions(+), 30 deletions(-) create mode 100644 ao-tools/altosui/AltosEepromMonitor.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEeprom.java b/ao-tools/altosui/AltosEeprom.java index 54e0bbc4..63698407 100644 --- a/ao-tools/altosui/AltosEeprom.java +++ b/ao-tools/altosui/AltosEeprom.java @@ -36,10 +36,11 @@ import altosui.AltosDeviceDialog; import altosui.AltosPreferences; import altosui.AltosLog; import altosui.AltosVoice; +import altosui.AltosEepromMonitor; import libaltosJNI.*; -public class AltosEeprom { +public class AltosEeprom implements Runnable { static final int AO_LOG_FLIGHT = 'F'; static final int AO_LOG_SENSOR = 'A'; @@ -103,9 +104,9 @@ public class AltosEeprom { } } - static void CaptureLog(AltosSerial serial_line) throws IOException, InterruptedException { + static void CaptureLog(JFrame frame, AltosSerial serial_line) throws IOException, InterruptedException { int serial = 0; - int block; + int block, state_block = 0; int addr; int flight = 0; int year = 0, month = 0, day = 0; @@ -116,6 +117,7 @@ public class AltosEeprom { FileWriter eeprom_file = null; AltosFile eeprom_name; LinkedList eeprom_pending = new LinkedList(); + AltosEepromMonitor monitor = new AltosEepromMonitor(frame, ao_flight_boost, ao_flight_landed); serial_line.printf("v\n"); @@ -140,11 +142,14 @@ public class AltosEeprom { if (serial == 0) throw new IOException("no serial number found"); + monitor.set_serial(serial); /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */ + state = 0; state_block = 0; for (block = 0; !done && block < 511; block++) { serial_line.printf("e %x\n", block); any_valid = false; + monitor.set_value(state_names[state], state, block - state_block); for (addr = 0; addr < 0x100;) { String line = serial_line.get_reply(); int[] values = ParseHex(line); @@ -164,14 +169,18 @@ public class AltosEeprom { int a = values[5] + (values[6] << 8); int b = values[7] + (values[8] << 8); - if (cmd == AO_LOG_FLIGHT) + if (cmd == AO_LOG_FLIGHT) { flight = b; + monitor.set_flight(flight); + } /* Monitor state transitions to update display */ if (cmd == AO_LOG_STATE && a <= ao_flight_landed) { System.out.printf ("%s\n", state_names[a]); if (a > ao_flight_pad) want_file = true; + if (a > state) + state_block = block; state = a; } @@ -189,6 +198,7 @@ public class AltosEeprom { else eeprom_name = new AltosFile(serial, flight, "eeprom-new"); + monitor.set_file(eeprom_name.getName()); eeprom_file = new FileWriter(eeprom_name); if (eeprom_file != null) { FlushPending(eeprom_file, eeprom_pending); @@ -224,35 +234,23 @@ public class AltosEeprom { eeprom_file.flush(); eeprom_file.close(); } + monitor.done(); } - public static void SaveFlightData (JFrame frame) { - altos_device device = AltosDeviceDialog.show(frame, null); - boolean remote = false; - AltosSerial serial_line = new AltosSerial(); + JFrame frame; + altos_device device; + AltosSerial serial_line; + boolean remote; + Thread eeprom_thread; - if (device == null) - return; + public void run () { + if (remote) { + serial_line.printf("m 0\n"); + serial_line.set_channel(AltosPreferences.channel()); + serial_line.printf("p\n"); + } try { - serial_line.open(device); - if (!device.getProduct().startsWith("TeleMetrum")) - remote = true; - - if (remote) { - serial_line.printf("m 0\n"); - serial_line.set_channel(AltosPreferences.channel()); - serial_line.printf("p\n"); - } - CaptureLog(serial_line); - if (remote) - serial_line.printf("~"); - serial_line.close(); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(frame, - String.format("Cannot open device \"%s\"", - device.getPath()), - "Cannot open target device", - JOptionPane.ERROR_MESSAGE); + CaptureLog(frame, serial_line); } catch (IOException ee) { JOptionPane.showMessageDialog(frame, device.getPath(), @@ -260,5 +258,36 @@ public class AltosEeprom { JOptionPane.ERROR_MESSAGE); } catch (InterruptedException ie) { } + if (remote) + serial_line.printf("~"); + serial_line.close(); + } + + public AltosEeprom(JFrame given_frame) { + frame = given_frame; + device = AltosDeviceDialog.show(frame, null); + serial_line = new AltosSerial(); + remote = false; + + if (device != null) { + try { + serial_line.open(device); + if (!device.getProduct().startsWith("TeleMetrum")) + remote = true; + eeprom_thread = new Thread(this); + eeprom_thread.start(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + String.format("Cannot open device \"%s\"", + device.getPath()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(frame, + device.getPath(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } + } } } diff --git a/ao-tools/altosui/AltosEepromMonitor.java b/ao-tools/altosui/AltosEepromMonitor.java new file mode 100644 index 00000000..a7b1dd3e --- /dev/null +++ b/ao-tools/altosui/AltosEepromMonitor.java @@ -0,0 +1,118 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosSerial; +import altosui.AltosSerialMonitor; +import altosui.AltosTelemetry; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; + +public class AltosEepromMonitor extends JDialog { + + JPanel panel; + Box box; + JLabel serial_label; + JLabel flight_label; + JLabel file_label; + JProgressBar pbar; + int min_state, max_state; + + public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) { + super (owner, "Download Flight Data"); + + box = Box.createVerticalBox(); + + serial_label = new JLabel("Serial:"); + box.add(serial_label); + flight_label = new JLabel("Flight:"); + box.add(flight_label); + file_label = new JLabel("File:"); + box.add(file_label); + + min_state = in_min_state; + max_state = in_max_state; + pbar = new JProgressBar(); + pbar.setMinimum(0); + pbar.setMaximum((max_state - min_state) * 100); + pbar.setValue(0); + pbar.setString("startup"); + pbar.setStringPainted(true); + box.add(pbar); + + panel = new JPanel(); + panel.add(box); + + add(panel); + + setMinimumSize(new Dimension(600, 0)); + setContentPane(panel); + pack(); + setVisible(true); + } + + public void set_value(String state_name, int in_state, int in_block) { + int block = in_block; + int state = in_state; + + if (block > 100) + block = 100; + if (state < min_state) state = min_state; + if (state >= max_state) state = max_state - 1; + state -= min_state; + + int pos = state * 100 + block; + + System.out.printf ("State %s (%d + %d) = %d\n", + state_name, in_state, in_block, pos); + + pbar.setString(state_name); + pbar.setValue(pos); + } + + public void set_serial(int serial) { + serial_label.setText(String.format("Serial: %d", serial)); + } + + public void set_flight(int flight) { + flight_label.setText(String.format("Flight: %d", flight)); + } + + public void set_file(String file) { + file_label.setText(String.format("File: %s", file)); + } + + public void done() { + setVisible(false); + dispose(); + } +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 92c3d0a3..863d173e 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -613,7 +613,7 @@ public class AltosUI extends JFrame { * a TeleDongle over the packet link */ private void SaveFlightData() { - AltosEeprom.SaveFlightData(AltosUI.this); + new AltosEeprom(AltosUI.this); } /* Create the AltosUI menus diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 2a91d657..2c284aaa 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -4,6 +4,7 @@ CLASSPATH=classes:./* CLASSFILES=\ AltosConvert.class \ AltosEeprom.class \ + AltosEepromMonitor.class \ AltosFile.class \ AltosGPS.class \ AltosGreatCircle.class \ -- cgit v1.2.3 From ea32290704a8ca468f01172166b561833b20c954 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 19:37:02 -0700 Subject: altosui: Fix Save flight data monitor layout, add cancel Use GridBagLayout to improve the appearance of the flight data monitor widget, add a cancel button to stop loading data (useful if the connection is wedged). Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEeprom.java | 37 ++++++----- ao-tools/altosui/AltosEepromMonitor.java | 106 +++++++++++++++++++++++++------ 2 files changed, 108 insertions(+), 35 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEeprom.java b/ao-tools/altosui/AltosEeprom.java index 63698407..6162521f 100644 --- a/ao-tools/altosui/AltosEeprom.java +++ b/ao-tools/altosui/AltosEeprom.java @@ -65,7 +65,7 @@ public class AltosEeprom implements Runnable { static final int ao_flight_landed = 8; static final int ao_flight_invalid = 9; - static String[] state_names = { + static final String[] state_names = { "startup", "idle", "pad", @@ -78,7 +78,7 @@ public class AltosEeprom implements Runnable { "invalid", }; - static int[] ParseHex(String line) { + int[] ParseHex(String line) { String[] tokens = line.split("\\s+"); int[] array = new int[tokens.length]; @@ -91,20 +91,27 @@ public class AltosEeprom implements Runnable { return array; } - static int checksum(int[] line) { + int checksum(int[] line) { int csum = 0x5a; for (int i = 1; i < line.length; i++) csum += line[i]; return csum & 0xff; } - static void FlushPending(FileWriter file, LinkedList pending) throws IOException { + void FlushPending(FileWriter file, LinkedList pending) throws IOException { while (!pending.isEmpty()) { file.write(pending.remove()); } } - static void CaptureLog(JFrame frame, AltosSerial serial_line) throws IOException, InterruptedException { + JFrame frame; + altos_device device; + AltosSerial serial_line; + boolean remote; + Thread eeprom_thread; + AltosEepromMonitor monitor; + + void CaptureLog() throws IOException, InterruptedException { int serial = 0; int block, state_block = 0; int addr; @@ -117,7 +124,6 @@ public class AltosEeprom implements Runnable { FileWriter eeprom_file = null; AltosFile eeprom_name; LinkedList eeprom_pending = new LinkedList(); - AltosEepromMonitor monitor = new AltosEepromMonitor(frame, ao_flight_boost, ao_flight_landed); serial_line.printf("v\n"); @@ -176,7 +182,6 @@ public class AltosEeprom implements Runnable { /* Monitor state transitions to update display */ if (cmd == AO_LOG_STATE && a <= ao_flight_landed) { - System.out.printf ("%s\n", state_names[a]); if (a > ao_flight_pad) want_file = true; if (a > state) @@ -234,23 +239,23 @@ public class AltosEeprom implements Runnable { eeprom_file.flush(); eeprom_file.close(); } - monitor.done(); } - JFrame frame; - altos_device device; - AltosSerial serial_line; - boolean remote; - Thread eeprom_thread; - public void run () { if (remote) { serial_line.printf("m 0\n"); serial_line.set_channel(AltosPreferences.channel()); serial_line.printf("p\n"); } + + monitor = new AltosEepromMonitor(frame, ao_flight_boost, ao_flight_landed); + monitor.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + eeprom_thread.interrupt(); + } + }); try { - CaptureLog(frame, serial_line); + CaptureLog(); } catch (IOException ee) { JOptionPane.showMessageDialog(frame, device.getPath(), @@ -260,12 +265,14 @@ public class AltosEeprom implements Runnable { } if (remote) serial_line.printf("~"); + monitor.done(); serial_line.close(); } public AltosEeprom(JFrame given_frame) { frame = given_frame; device = AltosDeviceDialog.show(frame, null); + serial_line = new AltosSerial(); remote = false; diff --git a/ao-tools/altosui/AltosEepromMonitor.java b/ao-tools/altosui/AltosEepromMonitor.java index a7b1dd3e..9eb3f0d0 100644 --- a/ao-tools/altosui/AltosEepromMonitor.java +++ b/ao-tools/altosui/AltosEepromMonitor.java @@ -39,25 +39,78 @@ import altosui.AltosVoice; public class AltosEepromMonitor extends JDialog { - JPanel panel; + Container pane; Box box; JLabel serial_label; JLabel flight_label; JLabel file_label; + JLabel serial_value; + JLabel flight_value; + JLabel file_value; + JButton cancel; JProgressBar pbar; int min_state, max_state; public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) { - super (owner, "Download Flight Data"); + super (owner, "Download Flight Data", false); - box = Box.createVerticalBox(); + GridBagConstraints c; + Insets il = new Insets(4,0,4,4); + Insets ir = new Insets(4,4,4,0); + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; serial_label = new JLabel("Serial:"); - box.add(serial_label); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 0; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JLabel(""); + pane.add(serial_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; flight_label = new JLabel("Flight:"); - box.add(flight_label); + pane.add(flight_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + flight_value = new JLabel(""); + pane.add(flight_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 2; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; file_label = new JLabel("File:"); - box.add(file_label); + pane.add(file_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 2; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + file_value = new JLabel(""); + pane.add(file_value, c); min_state = in_min_state; max_state = in_max_state; @@ -67,19 +120,35 @@ public class AltosEepromMonitor extends JDialog { pbar.setValue(0); pbar.setString("startup"); pbar.setStringPainted(true); - box.add(pbar); - - panel = new JPanel(); - panel.add(box); - - add(panel); + pbar.setPreferredSize(new Dimension(600, 20)); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 3; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ib = new Insets(4,0,4,0); + c.insets = ib; + pane.add(pbar, c); + + + cancel = new JButton("Cancel"); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 4; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ic = new Insets(4,4,4,4); + c.insets = ic; + pane.add(cancel, c); - setMinimumSize(new Dimension(600, 0)); - setContentPane(panel); pack(); setVisible(true); } + public void addActionListener (ActionListener l) { + cancel.addActionListener(l); + } + public void set_value(String state_name, int in_state, int in_block) { int block = in_block; int state = in_state; @@ -92,23 +161,20 @@ public class AltosEepromMonitor extends JDialog { int pos = state * 100 + block; - System.out.printf ("State %s (%d + %d) = %d\n", - state_name, in_state, in_block, pos); - pbar.setString(state_name); pbar.setValue(pos); } public void set_serial(int serial) { - serial_label.setText(String.format("Serial: %d", serial)); + serial_value.setText(String.format("%d", serial)); } public void set_flight(int flight) { - flight_label.setText(String.format("Flight: %d", flight)); + flight_value.setText(String.format("%d", flight)); } public void set_file(String file) { - file_label.setText(String.format("File: %s", file)); + file_value.setText(String.format("%s", file)); } public void done() { -- cgit v1.2.3 From d2d772164af95a35ea0f5d2413a5be67de9a210f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 20:18:36 -0700 Subject: altosui: Replace device dialog. Center eeprom monitor. This adds a custom dialog for selecting device, which makes it look much nicer on the screen and allows the user to double-click on an entry to select it. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDeviceDialog.java | 131 ++++++++++++++++++++++++++++--- ao-tools/altosui/AltosEepromMonitor.java | 7 +- 2 files changed, 125 insertions(+), 13 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java index 08921c3d..536a8057 100644 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -20,26 +20,34 @@ package altosui; import java.lang.*; import java.util.*; import javax.swing.*; +import java.awt.*; +import java.awt.event.*; import libaltosJNI.libaltos; import libaltosJNI.altos_device; import libaltosJNI.SWIGTYPE_p_altos_file; import libaltosJNI.SWIGTYPE_p_altos_list; import altosui.AltosDevice; -public class AltosDeviceDialog { +public class AltosDeviceDialog extends JDialog implements ActionListener { - static altos_device show (JFrame frame, String product) { + private static AltosDeviceDialog dialog; + private static altos_device value = null; + private JList list; + + public static altos_device show (Component frameComp, String product) { + + Frame frame = JOptionPane.getFrameForComponent(frameComp); AltosDevice[] devices; devices = AltosDevice.list(product); + if (devices != null & devices.length > 0) { - Object o = JOptionPane.showInputDialog(frame, - "Select a device", - "Device Selection", - JOptionPane.PLAIN_MESSAGE, - null, - devices, - devices[0]); - return (altos_device) o; + value = null; + dialog = new AltosDeviceDialog(frame, frameComp, + devices, + devices[0]); + + dialog.setVisible(true); + return value; } else { JOptionPane.showMessageDialog(frame, "No AltOS devices available", @@ -48,4 +56,107 @@ public class AltosDeviceDialog { return null; } } + + private AltosDeviceDialog (Frame frame, Component location, + AltosDevice[] devices, + AltosDevice initial) { + super(frame, "Device Selection", true); + + value = null; + + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(this); + + final JButton selectButton = new JButton("Select"); + selectButton.setActionCommand("select"); + selectButton.addActionListener(this); + getRootPane().setDefaultButton(selectButton); + + list = new JList(devices) { + //Subclass JList to workaround bug 4832765, which can cause the + //scroll pane to not let the user easily scroll up to the beginning + //of the list. An alternative would be to set the unitIncrement + //of the JScrollBar to a fixed value. You wouldn't get the nice + //aligned scrolling, but it should work. + public int getScrollableUnitIncrement(Rectangle visibleRect, + int orientation, + int direction) { + int row; + if (orientation == SwingConstants.VERTICAL && + direction < 0 && (row = getFirstVisibleIndex()) != -1) { + Rectangle r = getCellBounds(row, row); + if ((r.y == visibleRect.y) && (row != 0)) { + Point loc = r.getLocation(); + loc.y--; + int prevIndex = locationToIndex(loc); + Rectangle prevR = getCellBounds(prevIndex, prevIndex); + + if (prevR == null || prevR.y >= r.y) { + return 0; + } + return prevR.height; + } + } + return super.getScrollableUnitIncrement( + visibleRect, orientation, direction); + } + }; + + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.setLayoutOrientation(JList.HORIZONTAL_WRAP); + list.setVisibleRowCount(-1); + list.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + selectButton.doClick(); //emulate button click + } + } + }); + JScrollPane listScroller = new JScrollPane(list); + listScroller.setPreferredSize(new Dimension(400, 80)); + listScroller.setAlignmentX(LEFT_ALIGNMENT); + + //Create a container so that we can add a title around + //the scroll pane. Can't add a title directly to the + //scroll pane because its background would be white. + //Lay out the label and scroll pane from top to bottom. + JPanel listPane = new JPanel(); + listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); + + JLabel label = new JLabel("Select Device"); + label.setLabelFor(list); + listPane.add(label); + listPane.add(Box.createRigidArea(new Dimension(0,5))); + listPane.add(listScroller); + listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); + + //Lay out the buttons from left to right. + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.add(cancelButton); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + buttonPane.add(selectButton); + + //Put everything together, using the content pane's BorderLayout. + Container contentPane = getContentPane(); + contentPane.add(listPane, BorderLayout.CENTER); + contentPane.add(buttonPane, BorderLayout.PAGE_END); + + //Initialize values. + list.setSelectedValue(initial, true); + pack(); + setLocationRelativeTo(location); + } + + //Handle clicks on the Set and Cancel buttons. + public void actionPerformed(ActionEvent e) { + if ("select".equals(e.getActionCommand())) { + System.out.printf("got select action\n"); + AltosDeviceDialog.value = (altos_device)(list.getSelectedValue()); + } + AltosDeviceDialog.dialog.setVisible(false); + } + } diff --git a/ao-tools/altosui/AltosEepromMonitor.java b/ao-tools/altosui/AltosEepromMonitor.java index 9eb3f0d0..e110a354 100644 --- a/ao-tools/altosui/AltosEepromMonitor.java +++ b/ao-tools/altosui/AltosEepromMonitor.java @@ -55,8 +55,8 @@ public class AltosEepromMonitor extends JDialog { super (owner, "Download Flight Data", false); GridBagConstraints c; - Insets il = new Insets(4,0,4,4); - Insets ir = new Insets(4,4,4,0); + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); pane = getContentPane(); pane.setLayout(new GridBagLayout()); @@ -126,7 +126,7 @@ public class AltosEepromMonitor extends JDialog { c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 3; c.gridwidth = GridBagConstraints.REMAINDER; - Insets ib = new Insets(4,0,4,0); + Insets ib = new Insets(4,4,4,4); c.insets = ib; pane.add(pbar, c); @@ -142,6 +142,7 @@ public class AltosEepromMonitor extends JDialog { pane.add(cancel, c); pack(); + setLocationRelativeTo(owner); setVisible(true); } -- cgit v1.2.3 From 5fd225c3a52445ecdc7c04fac5e3d9a0db177c66 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 21:01:41 -0700 Subject: altosui: report rocket ground bearing at landing only if known if state.from_pad is null, then there isn't any data to report. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 863d173e..5c771df2 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -374,7 +374,7 @@ public class AltosUI extends JFrame { voice.speak("rocket landed safely"); else voice.speak("rocket may have crashed"); - if (state.gps != null) + if (state.from_pad != null) voice.speak("bearing %d degrees, range %d meters", (int) (state.from_pad.bearing + 0.5), (int) (state.from_pad.distance + 0.5)); -- cgit v1.2.3 From d0fd53bdab2f480cd43b6d7010c2094f4fccda91 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 Jul 2010 21:49:23 -0700 Subject: Reset GPS ready status when GPS comes unlocked on the pad If GPS becomes unlocked, then report that in the UI and via voice. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosState.java | 15 ++++++++++++++- ao-tools/altosui/AltosUI.java | 12 ++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index 59a1999e..9aa10a08 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -56,8 +56,12 @@ public class AltosState { double pad_lat; double pad_lon; double pad_alt; + + static final int MIN_PAD_SAMPLES = 10; + int npad; - int prev_npad; + int gps_waiting; + boolean gps_ready; AltosGreatCircle from_pad; @@ -134,8 +138,17 @@ public class AltosState { pad_lon = data.gps.lon; pad_alt = data.gps.alt; } + } else { + npad = 0; } } + + gps_waiting = MIN_PAD_SAMPLES - npad; + if (gps_waiting < 0) + gps_waiting = 0; + + gps_ready = gps_waiting == 0; + ascent = (AltosTelemetry.ao_flight_boost <= state && state <= AltosTelemetry.ao_flight_coast); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 5c771df2..4994f093 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -243,17 +243,15 @@ public class AltosUI extends JFrame { flightInfoModel[i].finish(); } - static final int MIN_PAD_SAMPLES = 10; - public void show(AltosState state) { flightStatusModel.set(state); info_reset(); - if (state.npad >= MIN_PAD_SAMPLES) + if (state.gps_ready) info_add_row(0, "Ground state", "%s", "ready"); else info_add_row(0, "Ground state", "wait (%d)", - MIN_PAD_SAMPLES - state.npad); + state.gps_waiting); info_add_row(0, "Rocket state", "%s", state.data.state); info_add_row(0, "Callsign", "%s", state.data.callsign); info_add_row(0, "Rocket serial", "%6d", state.data.serial); @@ -413,6 +411,12 @@ public class AltosUI extends JFrame { (int) (state.max_height + 0.5)); } } + if (old_state == null || old_state.gps_ready != state.gps_ready) { + if (state.gps_ready) + voice.speak("GPS ready"); + else if (old_state != null) + voice.speak("GPS lost"); + } old_state = state; } -- cgit v1.2.3 From e33dbbba94ce42295e9fed9f4ba7e46f9eff1517 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 10:24:09 -0700 Subject: altosui: check for closed serial device before reading Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index a5566ab8..96e8b61f 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -51,6 +51,8 @@ public class AltosSerial implements Runnable { try { for (;;) { + if (altos == null) + break; c = libaltos.altos_getchar(altos, 0); if (Thread.interrupted()) break; -- cgit v1.2.3 From b8bc9994d8bfde6116c8a509e70ddf45fc4decce Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 10:24:59 -0700 Subject: altosui: Remove unnecessary freetts .jar files Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 2c284aaa..a2d70c18 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -29,9 +29,7 @@ FREETTSJAR= \ cmutimelex.jar \ cmu_us_kal.jar \ en_us.jar \ - freetts.jar \ - freetts-jsapi10.jar \ - jsapi.jar + freetts.jar JAVAFLAGS=-Xlint:unchecked -- cgit v1.2.3 From 53c279b9e96da8b69837ae84038a78ca5707f2a5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 10:45:02 -0700 Subject: altosui: Close serial, join reader thread, free altos_file Separating out the close and free actions ensures that the reader thread will not access freed memory or dereference a null pointer while shutting down the connection to the serial device. Otherwise, a race condition exists between the serial close and the thread join. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 10 +++++----- ao-tools/libaltos/libaltos.c | 12 ++++++++++++ ao-tools/libaltos/libaltos.h | 2 ++ 3 files changed, 19 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 96e8b61f..efa63f68 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -51,8 +51,6 @@ public class AltosSerial implements Runnable { try { for (;;) { - if (altos == null) - break; c = libaltos.altos_getchar(altos, 0); if (Thread.interrupted()) break; @@ -106,10 +104,8 @@ public class AltosSerial implements Runnable { } public void close() { - if (altos != null) { + if (altos != null) libaltos.altos_close(altos); - altos = null; - } if (input_thread != null) { try { input_thread.interrupt(); @@ -118,6 +114,10 @@ public class AltosSerial implements Runnable { } input_thread = null; } + if (altos != null) { + libaltos.altos_free(altos); + altos = null; + } } public void putc(char c) { diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index df0d5b2e..00fb2125 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -567,6 +567,14 @@ void altos_close(struct altos_file *file) { close(file->fd); + file->fd = -1; +} + +void +altos_free(struct altos_file *file) +{ + if (file->fd != -1) + close(file->fd); free(file); } @@ -592,6 +600,8 @@ altos_flush(struct altos_file *file) while (file->out_used) { int ret; + if (file->fd < 0) + return -EBADF; ret = write (file->fd, file->out_data, file->out_used); if (ret < 0) return -errno; @@ -610,6 +620,8 @@ altos_getchar(struct altos_file *file, int timeout) int ret; altos_flush(file); + if (file->fd < 0) + return -EBADF; ret = read(file->fd, file->in_data, USB_BUF_SIZE); if (ret < 0) return -errno; diff --git a/ao-tools/libaltos/libaltos.h b/ao-tools/libaltos/libaltos.h index 782f244e..53026e0a 100644 --- a/ao-tools/libaltos/libaltos.h +++ b/ao-tools/libaltos/libaltos.h @@ -42,6 +42,8 @@ altos_open(struct altos_device *device); void altos_close(struct altos_file *file); +void altos_free(struct altos_file *file); + int altos_putchar(struct altos_file *file, char c); -- cgit v1.2.3 From efa0e034a161f4852947cbac06537d6ba4422a0e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 10:48:25 -0700 Subject: altosui: remove debug printf Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDeviceDialog.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java index 536a8057..c60bd7c3 100644 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -152,10 +152,8 @@ public class AltosDeviceDialog extends JDialog implements ActionListener { //Handle clicks on the Set and Cancel buttons. public void actionPerformed(ActionEvent e) { - if ("select".equals(e.getActionCommand())) { - System.out.printf("got select action\n"); + if ("select".equals(e.getActionCommand())) AltosDeviceDialog.value = (altos_device)(list.getSelectedValue()); - } AltosDeviceDialog.dialog.setVisible(false); } -- cgit v1.2.3 From 669c5f52abb972a82ed6efbee7a8c7d20afb5cd0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 10:48:52 -0700 Subject: libaltos: build with java src encoding UTF8 Signed-off-by: Keith Packard --- ao-tools/libaltos/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 0bbd304c..fa5127eb 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -51,7 +51,7 @@ JAVAFLAGS=-Xlint:unchecked all: libaltos.$(LIBEXT) cjnitest $(CLASSFILES) .java.class: - javac -cp "$(CLASSPATH)" $(JAVAFLAGS) $*.java + javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java CFLAGS=$(OS_CFLAGS) -O0 -g -I. -- cgit v1.2.3 From 950f0a8c54e5835ee5d8b0aea360bd8362c21bc5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 11:09:19 -0700 Subject: altosui: construct Darwin application directory This adds the necessary files and build steps to construct AltosUI.app on a Darwin system. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.app/Contents/Info.plist | 38 +++++++++++++++++++++ .../AltosUI.app/Contents/MacOS/JavaApplicationStub | Bin 0 -> 61296 bytes ao-tools/altosui/AltosUI.app/Contents/PkgInfo | 1 + .../Contents/Resources/AltosUIIcon.icns | Bin 0 -> 129010 bytes ao-tools/altosui/AltosUIIcon.icns | Bin 129010 -> 0 bytes ao-tools/altosui/Makefile | 28 ++++++++++++++- 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 ao-tools/altosui/AltosUI.app/Contents/Info.plist create mode 100755 ao-tools/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub create mode 100644 ao-tools/altosui/AltosUI.app/Contents/PkgInfo create mode 100644 ao-tools/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns delete mode 100644 ao-tools/altosui/AltosUIIcon.icns (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.app/Contents/Info.plist b/ao-tools/altosui/AltosUI.app/Contents/Info.plist new file mode 100644 index 00000000..97b1b59c --- /dev/null +++ b/ao-tools/altosui/AltosUI.app/Contents/Info.plist @@ -0,0 +1,38 @@ + + + + + CFBundleName + altosui + CFBundleVersion + 100.0 + CFBundleAllowMixedLocalizations + true + CFBundleExecutable + JavaApplicationStub + CFBundleDevelopmentRegion + English + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleGetInfoString + AltOS UI version 0.7 + CFBundleInfoDictionaryVersion + 6.0 + CFBundleIconFile + AltosUIIcon.icns + Java + + MainClass + altosui.AltosUI + JVMVersion + 1.5+ + ClassPath + + $JAVAROOT/altosui.jar + $JAVAROOT/freetts.jar + + + + diff --git a/ao-tools/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub b/ao-tools/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub new file mode 100755 index 00000000..c661d3e1 Binary files /dev/null and b/ao-tools/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub differ diff --git a/ao-tools/altosui/AltosUI.app/Contents/PkgInfo b/ao-tools/altosui/AltosUI.app/Contents/PkgInfo new file mode 100644 index 00000000..8a43480f --- /dev/null +++ b/ao-tools/altosui/AltosUI.app/Contents/PkgInfo @@ -0,0 +1 @@ +APPLAM.O diff --git a/ao-tools/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns b/ao-tools/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns new file mode 100644 index 00000000..fe49f362 Binary files /dev/null and b/ao-tools/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns differ diff --git a/ao-tools/altosui/AltosUIIcon.icns b/ao-tools/altosui/AltosUIIcon.icns deleted file mode 100644 index fe49f362..00000000 Binary files a/ao-tools/altosui/AltosUIIcon.icns and /dev/null differ diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index a2d70c18..51a85a13 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -33,7 +33,17 @@ FREETTSJAR= \ JAVAFLAGS=-Xlint:unchecked -all: altosui.jar +OS:=$(shell uname) + +ifeq ($(OS),Linux) +ALTOSUI_APP=altosui +endif + +ifeq ($(OS),Darwin) +ALTOSUI_APP=AltosUI.app/Contents/Resources/Java/altosui.jar +endif + +all: altosui.jar $(ALTOSUI_APP) $(CLASSFILES): @@ -54,6 +64,22 @@ classes/libaltosJNI: $(FREETTSJAR): ln -s $(FREETTSLIB)/$@ . +ifeq ($(OS),Darwin) +RESOURCES=altosui.jar $(FREETTSJAR) ../libaltos/libaltos.dylib + +$(ALTOSUI_APP): $(RESOURCES) + mkdir -p AltosUI.app/Contents/Resources/Java + cp $(RESOURCES) AltosUI.app/Contents/Resources/Java + +endif + +ifeq ($(OS),Linux) +altosui: + echo "#!/bin/sh" > $@ + echo "exec java -Djava.library.path=../libaltos -jar altosui.jar" >> $@ +endif + clean: rm -f *.class $(FREETTSJAR) altosui.jar + rm -f AltosUI.app/Contents/Resources/Java/* rm -rf classes -- cgit v1.2.3 From 6f86db5e0360bef26b21336769b7635e3a11e160 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 11:24:47 -0700 Subject: Add Mac OS X packaging bits Signed-off-by: Keith Packard --- .../01altosui-contents.xml | 1 + .../AltOS Package Configuration.pmdoc/01altosui.xml | 1 + .../altosui/AltOS Package Configuration.pmdoc/index.xml | 1 + ao-tools/altosui/altusmetrum.jpg | Bin 0 -> 72868 bytes 4 files changed, 3 insertions(+) create mode 100644 ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml create mode 100644 ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml create mode 100644 ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml create mode 100644 ao-tools/altosui/altusmetrum.jpg (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml b/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml new file mode 100644 index 00000000..18e00fe4 --- /dev/null +++ b/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml b/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml new file mode 100644 index 00000000..09fa7123 --- /dev/null +++ b/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml @@ -0,0 +1 @@ +org.altusmetrum.altosUi.AltosUI.pkg1.0AltosUI.app/Applications/AltosUI.appinstallTo.pathinstallFrom.isRelativeTypeparentrequireAuthorizationinstallTo01altosui-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ \ No newline at end of file diff --git a/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml b/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml new file mode 100644 index 00000000..03d0f59f --- /dev/null +++ b/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml @@ -0,0 +1 @@ +AltOS UI/Users/keithp/altos/ao-tools/altosui/AltosUI.pkgorg.altusmetrumInstall AltOS User Interfacealtusmetrum.jpg01altosui.xmlproperties.titleproperties.customizeOptiondescriptionproperties.userDomainproperties.systemDomain \ No newline at end of file diff --git a/ao-tools/altosui/altusmetrum.jpg b/ao-tools/altosui/altusmetrum.jpg new file mode 100644 index 00000000..04027921 Binary files /dev/null and b/ao-tools/altosui/altusmetrum.jpg differ -- cgit v1.2.3 From 91d75fb3919f606a1956bf8c6423a8012d99a56a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 11:45:12 -0700 Subject: altosui: Switch eeprom extension back to .eeprom --- ao-tools/altosui/AltosEeprom.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEeprom.java b/ao-tools/altosui/AltosEeprom.java index 6162521f..4c537a89 100644 --- a/ao-tools/altosui/AltosEeprom.java +++ b/ao-tools/altosui/AltosEeprom.java @@ -199,9 +199,9 @@ public class AltosEeprom implements Runnable { if (eeprom_file == null) { if (serial != 0 && flight != 0 && want_file) { if (year != 0 && month != 0 && day != 0) - eeprom_name = new AltosFile(year, month, day, serial, flight, "eeprom-new"); + eeprom_name = new AltosFile(year, month, day, serial, flight, "eeprom"); else - eeprom_name = new AltosFile(serial, flight, "eeprom-new"); + eeprom_name = new AltosFile(serial, flight, "eeprom"); monitor.set_file(eeprom_name.getName()); eeprom_file = new FileWriter(eeprom_name); @@ -229,7 +229,7 @@ public class AltosEeprom implements Runnable { done = true; } if (eeprom_file == null) { - eeprom_name = new AltosFile(serial,flight,"eeprom-new"); + eeprom_name = new AltosFile(serial,flight,"eeprom"); eeprom_file = new FileWriter(eeprom_name); if (eeprom_file != null) { FlushPending(eeprom_file, eeprom_pending); -- cgit v1.2.3 From 6fb8546575f6d99676dbb1dce190b0b7cf24b657 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 11:45:56 -0700 Subject: Moved Mac OS packaging to altosui dir --- .../libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml | 1 - ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml | 1 - ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml | 1 - 3 files changed, 3 deletions(-) delete mode 100644 ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml delete mode 100644 ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml delete mode 100644 ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml (limited to 'ao-tools') diff --git a/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml b/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml deleted file mode 100644 index e19a1e4c..00000000 --- a/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui-contents.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml b/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml deleted file mode 100644 index 5d84e5f0..00000000 --- a/ao-tools/libaltos/AltOS Package Configuration.pmdoc/01altosui.xml +++ /dev/null @@ -1 +0,0 @@ -org.altusmetrum.altosUi.AltosUI.pkg1.0/Users/keithp/AltosUI.app/Applications/AltosUI.appinstallTo.pathparentrequireAuthorizationinstallTo01altosui-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ \ No newline at end of file diff --git a/ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml b/ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml deleted file mode 100644 index 1277db62..00000000 --- a/ao-tools/libaltos/AltOS Package Configuration.pmdoc/index.xml +++ /dev/null @@ -1 +0,0 @@ -AltOS UI/Users/keithp/Documents/AltosUI.pkgorg.altusmetrum01altosui.xmlproperties.title \ No newline at end of file -- cgit v1.2.3 From 9ad4984124b6c05114feac4c4ac078dc248ce16a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 11:56:24 -0700 Subject: altosui: remove option to install to alternate volume --- ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml | 2 +- ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml b/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml index 09fa7123..6170931b 100644 --- a/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml +++ b/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml @@ -1 +1 @@ -org.altusmetrum.altosUi.AltosUI.pkg1.0AltosUI.app/Applications/AltosUI.appinstallTo.pathinstallFrom.isRelativeTypeparentrequireAuthorizationinstallTo01altosui-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ \ No newline at end of file +org.altusmetrum.altosUi.AltosUI.pkg0.7AltosUI.app/Applications/AltosUI.appinstallTo.pathinstallFrom.isRelativeTypeversionparentrequireAuthorizationinstallTo01altosui-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ \ No newline at end of file diff --git a/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml b/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml index 03d0f59f..fabe54a6 100644 --- a/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml +++ b/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml @@ -1 +1 @@ -AltOS UI/Users/keithp/altos/ao-tools/altosui/AltosUI.pkgorg.altusmetrumInstall AltOS User Interfacealtusmetrum.jpg01altosui.xmlproperties.titleproperties.customizeOptiondescriptionproperties.userDomainproperties.systemDomain \ No newline at end of file +AltOS UI/Users/keithp/altos/ao-tools/altosui/AltosUI.pkgorg.altusmetrumInstall AltOS User Interfacealtusmetrum.jpg01altosui.xmlproperties.anywhereDomainproperties.titleproperties.customizeOptiondescriptionproperties.userDomainproperties.systemDomain \ No newline at end of file -- cgit v1.2.3 From c71061a37d3d3be2855b61cde33d2371989d7681 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 12:06:06 -0700 Subject: Make altosui test script executable --- ao-tools/altosui/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 51a85a13..790aecda 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -77,6 +77,7 @@ ifeq ($(OS),Linux) altosui: echo "#!/bin/sh" > $@ echo "exec java -Djava.library.path=../libaltos -jar altosui.jar" >> $@ + chmod +x ./altosui endif clean: -- cgit v1.2.3 From 8fc261c2b77bb8aab201a0649a84b5ffa236ce26 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Sat, 31 Jul 2010 10:55:07 -0600 Subject: see if my new freetts package works --- ao-tools/altosui/Manifest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt index 251ce2a0..1f313a13 100644 --- a/ao-tools/altosui/Manifest.txt +++ b/ao-tools/altosui/Manifest.txt @@ -1,2 +1,2 @@ Main-Class: altosui.AltosUI -Class-Path: freetts.jar +Class-Path: /usr/share/java/freetts-1.2.2.jar -- cgit v1.2.3 From e286eb61ad2a90746c1c31f95d26d5edb48738d3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 31 Jul 2010 09:57:49 -0700 Subject: altosui: rename AltosEeprom -> AltosEepromDownload, split out Altos constants Renames the eeprom downloading code and adds a new file to share the flight data constants across the various UI modules. Signed-off-by: Keith Packard --- ao-tools/altosui/Altos.java | 94 ++++++++++ ao-tools/altosui/AltosEeprom.java | 300 ------------------------------ ao-tools/altosui/AltosEepromDownload.java | 278 +++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 17 +- 4 files changed, 381 insertions(+), 308 deletions(-) create mode 100644 ao-tools/altosui/Altos.java delete mode 100644 ao-tools/altosui/AltosEeprom.java create mode 100644 ao-tools/altosui/AltosEepromDownload.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java new file mode 100644 index 00000000..bda4080e --- /dev/null +++ b/ao-tools/altosui/Altos.java @@ -0,0 +1,94 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.util.*; +import java.text.*; + +public class Altos { + /* EEProm command letters */ + static final int AO_LOG_FLIGHT = 'F'; + static final int AO_LOG_SENSOR = 'A'; + static final int AO_LOG_TEMP_VOLT = 'T'; + static final int AO_LOG_DEPLOY = 'D'; + static final int AO_LOG_STATE = 'S'; + static final int AO_LOG_GPS_TIME = 'G'; + static final int AO_LOG_GPS_LAT = 'N'; + static final int AO_LOG_GPS_LON = 'W'; + static final int AO_LOG_GPS_ALT = 'H'; + static final int AO_LOG_GPS_SAT = 'V'; + static final int AO_LOG_GPS_DATE = 'Y'; + + /* Added for 'serial-number' entry in eeprom files */ + static final int AO_LOG_SERIAL_NUMBER = 1000; + + /* Added to flag invalid records */ + static final int AO_LOG_INVALID = -1; + + /* Flight state numbers and names */ + static final int ao_flight_startup = 0; + static final int ao_flight_idle = 1; + static final int ao_flight_pad = 2; + static final int ao_flight_boost = 3; + static final int ao_flight_fast = 4; + static final int ao_flight_coast = 5; + static final int ao_flight_drogue = 6; + static final int ao_flight_main = 7; + static final int ao_flight_landed = 8; + static final int ao_flight_invalid = 9; + + static HashMap string_to_state = new HashMap(); + { + string_to_state.put("startup", ao_flight_startup); + string_to_state.put("idle", ao_flight_idle); + string_to_state.put("pad", ao_flight_pad); + string_to_state.put("boost", ao_flight_boost); + string_to_state.put("fast", ao_flight_fast); + string_to_state.put("coast", ao_flight_coast); + string_to_state.put("drogue", ao_flight_drogue); + string_to_state.put("main", ao_flight_main); + string_to_state.put("landed", ao_flight_landed); + string_to_state.put("invalid", ao_flight_invalid); + } + + static String[] state_to_string = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid", + }; + + static public int state(String state) { + if (string_to_state.containsKey(state)) + return string_to_state.get(state); + return ao_flight_invalid; + } + + static public String state_name(int state) { + if (state < 0 || state_to_string.length <= state) + return "invalid"; + return state_to_string[state]; + } +} diff --git a/ao-tools/altosui/AltosEeprom.java b/ao-tools/altosui/AltosEeprom.java deleted file mode 100644 index 4c537a89..00000000 --- a/ao-tools/altosui/AltosEeprom.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -import altosui.AltosSerial; -import altosui.AltosSerialMonitor; -import altosui.AltosTelemetry; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosEepromMonitor; - -import libaltosJNI.*; - -public class AltosEeprom implements Runnable { - - static final int AO_LOG_FLIGHT = 'F'; - static final int AO_LOG_SENSOR = 'A'; - static final int AO_LOG_TEMP_VOLT = 'T'; - static final int AO_LOG_DEPLOY = 'D'; - static final int AO_LOG_STATE = 'S'; - static final int AO_LOG_GPS_TIME = 'G'; - static final int AO_LOG_GPS_LAT = 'N'; - static final int AO_LOG_GPS_LON = 'W'; - static final int AO_LOG_GPS_ALT = 'H'; - static final int AO_LOG_GPS_SAT = 'V'; - static final int AO_LOG_GPS_DATE = 'Y'; - - static final int ao_flight_startup = 0; - static final int ao_flight_idle = 1; - static final int ao_flight_pad = 2; - static final int ao_flight_boost = 3; - static final int ao_flight_fast = 4; - static final int ao_flight_coast = 5; - static final int ao_flight_drogue = 6; - static final int ao_flight_main = 7; - static final int ao_flight_landed = 8; - static final int ao_flight_invalid = 9; - - static final String[] state_names = { - "startup", - "idle", - "pad", - "boost", - "fast", - "coast", - "drogue", - "main", - "landed", - "invalid", - }; - - int[] ParseHex(String line) { - String[] tokens = line.split("\\s+"); - int[] array = new int[tokens.length]; - - for (int i = 0; i < tokens.length; i++) - try { - array[i] = Integer.parseInt(tokens[i], 16); - } catch (NumberFormatException ne) { - return null; - } - return array; - } - - int checksum(int[] line) { - int csum = 0x5a; - for (int i = 1; i < line.length; i++) - csum += line[i]; - return csum & 0xff; - } - - void FlushPending(FileWriter file, LinkedList pending) throws IOException { - while (!pending.isEmpty()) { - file.write(pending.remove()); - } - } - - JFrame frame; - altos_device device; - AltosSerial serial_line; - boolean remote; - Thread eeprom_thread; - AltosEepromMonitor monitor; - - void CaptureLog() throws IOException, InterruptedException { - int serial = 0; - int block, state_block = 0; - int addr; - int flight = 0; - int year = 0, month = 0, day = 0; - int state = 0; - boolean done = false; - boolean want_file = false; - boolean any_valid; - FileWriter eeprom_file = null; - AltosFile eeprom_name; - LinkedList eeprom_pending = new LinkedList(); - - serial_line.printf("v\n"); - - /* Pull the serial number out of the version information */ - - for (;;) { - String line = serial_line.get_reply(); - - if (line.startsWith("serial-number")) { - try { - serial = Integer.parseInt(line.substring(13).trim()); - eeprom_pending.add(String.format("%s\n", line)); - } catch (NumberFormatException ne) { - serial = 0; - } - } - - /* signals the end of the version info */ - if (line.startsWith("software-version")) - break; - } - if (serial == 0) - throw new IOException("no serial number found"); - - monitor.set_serial(serial); - /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */ - - state = 0; state_block = 0; - for (block = 0; !done && block < 511; block++) { - serial_line.printf("e %x\n", block); - any_valid = false; - monitor.set_value(state_names[state], state, block - state_block); - for (addr = 0; addr < 0x100;) { - String line = serial_line.get_reply(); - int[] values = ParseHex(line); - - if (values == null) { - System.out.printf("invalid line: %s\n", line); - } else if (values[0] != addr) { - System.out.printf("data address out of sync at 0x%x\n", - block * 256 + values[0]); - } else if (checksum(values) != 0) { - System.out.printf("invalid checksum at 0x%x\n", - block * 256 + values[0]); - } else { - any_valid = true; - int cmd = values[1]; - int tick = values[3] + (values[4] << 8); - int a = values[5] + (values[6] << 8); - int b = values[7] + (values[8] << 8); - - if (cmd == AO_LOG_FLIGHT) { - flight = b; - monitor.set_flight(flight); - } - - /* Monitor state transitions to update display */ - if (cmd == AO_LOG_STATE && a <= ao_flight_landed) { - if (a > ao_flight_pad) - want_file = true; - if (a > state) - state_block = block; - state = a; - } - - if (cmd == AO_LOG_GPS_DATE) { - year = 2000 + (a & 0xff); - month = (a >> 8) & 0xff; - day = (b & 0xff); - want_file = true; - } - - if (eeprom_file == null) { - if (serial != 0 && flight != 0 && want_file) { - if (year != 0 && month != 0 && day != 0) - eeprom_name = new AltosFile(year, month, day, serial, flight, "eeprom"); - else - eeprom_name = new AltosFile(serial, flight, "eeprom"); - - monitor.set_file(eeprom_name.getName()); - eeprom_file = new FileWriter(eeprom_name); - if (eeprom_file != null) { - FlushPending(eeprom_file, eeprom_pending); - eeprom_pending = null; - } - } - } - - String log_line = String.format("%c %4x %4x %4x\n", - cmd, tick, a, b); - if (eeprom_file != null) - eeprom_file.write(log_line); - else - eeprom_pending.add(log_line); - - if (cmd == AO_LOG_STATE && a == ao_flight_landed) { - done = true; - } - } - addr += 8; - } - if (!any_valid) - done = true; - } - if (eeprom_file == null) { - eeprom_name = new AltosFile(serial,flight,"eeprom"); - eeprom_file = new FileWriter(eeprom_name); - if (eeprom_file != null) { - FlushPending(eeprom_file, eeprom_pending); - } - } - if (eeprom_file != null) { - eeprom_file.flush(); - eeprom_file.close(); - } - } - - public void run () { - if (remote) { - serial_line.printf("m 0\n"); - serial_line.set_channel(AltosPreferences.channel()); - serial_line.printf("p\n"); - } - - monitor = new AltosEepromMonitor(frame, ao_flight_boost, ao_flight_landed); - monitor.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - eeprom_thread.interrupt(); - } - }); - try { - CaptureLog(); - } catch (IOException ee) { - JOptionPane.showMessageDialog(frame, - device.getPath(), - ee.getLocalizedMessage(), - JOptionPane.ERROR_MESSAGE); - } catch (InterruptedException ie) { - } - if (remote) - serial_line.printf("~"); - monitor.done(); - serial_line.close(); - } - - public AltosEeprom(JFrame given_frame) { - frame = given_frame; - device = AltosDeviceDialog.show(frame, null); - - serial_line = new AltosSerial(); - remote = false; - - if (device != null) { - try { - serial_line.open(device); - if (!device.getProduct().startsWith("TeleMetrum")) - remote = true; - eeprom_thread = new Thread(this); - eeprom_thread.start(); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(frame, - String.format("Cannot open device \"%s\"", - device.getPath()), - "Cannot open target device", - JOptionPane.ERROR_MESSAGE); - } catch (IOException ee) { - JOptionPane.showMessageDialog(frame, - device.getPath(), - ee.getLocalizedMessage(), - JOptionPane.ERROR_MESSAGE); - } - } - } -} diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java new file mode 100644 index 00000000..756b82d1 --- /dev/null +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -0,0 +1,278 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.Altos; +import altosui.AltosSerial; +import altosui.AltosSerialMonitor; +import altosui.AltosTelemetry; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosEepromMonitor; + +import libaltosJNI.*; + +public class AltosEepromDownload implements Runnable { + + static final String[] state_names = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid", + }; + + int[] ParseHex(String line) { + String[] tokens = line.split("\\s+"); + int[] array = new int[tokens.length]; + + for (int i = 0; i < tokens.length; i++) + try { + array[i] = Integer.parseInt(tokens[i], 16); + } catch (NumberFormatException ne) { + return null; + } + return array; + } + + int checksum(int[] line) { + int csum = 0x5a; + for (int i = 1; i < line.length; i++) + csum += line[i]; + return csum & 0xff; + } + + void FlushPending(FileWriter file, LinkedList pending) throws IOException { + while (!pending.isEmpty()) { + file.write(pending.remove()); + } + } + + JFrame frame; + altos_device device; + AltosSerial serial_line; + boolean remote; + Thread eeprom_thread; + AltosEepromMonitor monitor; + + void CaptureLog() throws IOException, InterruptedException { + int serial = 0; + int block, state_block = 0; + int addr; + int flight = 0; + int year = 0, month = 0, day = 0; + int state = 0; + boolean done = false; + boolean want_file = false; + boolean any_valid; + FileWriter eeprom_file = null; + AltosFile eeprom_name; + LinkedList eeprom_pending = new LinkedList(); + + serial_line.printf("v\n"); + + /* Pull the serial number out of the version information */ + + for (;;) { + String line = serial_line.get_reply(); + + if (line.startsWith("serial-number")) { + try { + serial = Integer.parseInt(line.substring(13).trim()); + eeprom_pending.add(String.format("%s\n", line)); + } catch (NumberFormatException ne) { + serial = 0; + } + } + + /* signals the end of the version info */ + if (line.startsWith("software-version")) + break; + } + if (serial == 0) + throw new IOException("no serial number found"); + + monitor.set_serial(serial); + /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */ + + state = 0; state_block = 0; + for (block = 0; !done && block < 511; block++) { + serial_line.printf("e %x\n", block); + any_valid = false; + monitor.set_value(state_names[state], state, block - state_block); + for (addr = 0; addr < 0x100;) { + String line = serial_line.get_reply(); + int[] values = ParseHex(line); + + if (values == null) { + System.out.printf("invalid line: %s\n", line); + } else if (values[0] != addr) { + System.out.printf("data address out of sync at 0x%x\n", + block * 256 + values[0]); + } else if (checksum(values) != 0) { + System.out.printf("invalid checksum at 0x%x\n", + block * 256 + values[0]); + } else { + any_valid = true; + int cmd = values[1]; + int tick = values[3] + (values[4] << 8); + int a = values[5] + (values[6] << 8); + int b = values[7] + (values[8] << 8); + + if (cmd == Altos.AO_LOG_FLIGHT) { + flight = b; + monitor.set_flight(flight); + } + + /* Monitor state transitions to update display */ + if (cmd == Altos.AO_LOG_STATE && a <= Altos.ao_flight_landed) { + if (a > Altos.ao_flight_pad) + want_file = true; + if (a > state) + state_block = block; + state = a; + } + + if (cmd == Altos.AO_LOG_GPS_DATE) { + year = 2000 + (a & 0xff); + month = (a >> 8) & 0xff; + day = (b & 0xff); + want_file = true; + } + + if (eeprom_file == null) { + if (serial != 0 && flight != 0 && want_file) { + if (year != 0 && month != 0 && day != 0) + eeprom_name = new AltosFile(year, month, day, serial, flight, "eeprom"); + else + eeprom_name = new AltosFile(serial, flight, "eeprom"); + + monitor.set_file(eeprom_name.getName()); + eeprom_file = new FileWriter(eeprom_name); + if (eeprom_file != null) { + FlushPending(eeprom_file, eeprom_pending); + eeprom_pending = null; + } + } + } + + String log_line = String.format("%c %4x %4x %4x\n", + cmd, tick, a, b); + if (eeprom_file != null) + eeprom_file.write(log_line); + else + eeprom_pending.add(log_line); + + if (cmd == Altos.AO_LOG_STATE && a == Altos.ao_flight_landed) { + done = true; + } + } + addr += 8; + } + if (!any_valid) + done = true; + } + if (eeprom_file == null) { + eeprom_name = new AltosFile(serial,flight,"eeprom"); + eeprom_file = new FileWriter(eeprom_name); + if (eeprom_file != null) { + FlushPending(eeprom_file, eeprom_pending); + } + } + if (eeprom_file != null) { + eeprom_file.flush(); + eeprom_file.close(); + } + } + + public void run () { + if (remote) { + serial_line.printf("m 0\n"); + serial_line.set_channel(AltosPreferences.channel()); + serial_line.printf("p\n"); + } + + monitor = new AltosEepromMonitor(frame, Altos.ao_flight_boost, Altos.ao_flight_landed); + monitor.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + eeprom_thread.interrupt(); + } + }); + try { + CaptureLog(); + } catch (IOException ee) { + JOptionPane.showMessageDialog(frame, + device.getPath(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } catch (InterruptedException ie) { + } + if (remote) + serial_line.printf("~"); + monitor.done(); + serial_line.close(); + } + + public AltosEepromDownload(JFrame given_frame) { + frame = given_frame; + device = AltosDeviceDialog.show(frame, null); + + serial_line = new AltosSerial(); + remote = false; + + if (device != null) { + try { + serial_line.open(device); + if (!device.getProduct().startsWith("TeleMetrum")) + remote = true; + eeprom_thread = new Thread(this); + eeprom_thread.start(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + String.format("Cannot open device \"%s\"", + device.getPath()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(frame, + device.getPath(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } + } + } +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 4994f093..824e4b5b 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -28,6 +28,7 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import altosui.Altos; import altosui.AltosSerial; import altosui.AltosSerialMonitor; import altosui.AltosTelemetry; @@ -344,7 +345,7 @@ public class AltosUI extends JFrame { return; /* reset the landing count once we hear about a new flight */ - if (state.state < AltosTelemetry.ao_flight_drogue) + if (state.state < Altos.ao_flight_drogue) reported_landing = 0; /* Shut up once the rocket is on the ground */ @@ -353,7 +354,7 @@ public class AltosUI extends JFrame { } /* If the rocket isn't on the pad, then report height */ - if (state.state > AltosTelemetry.ao_flight_pad) { + if (state.state > Altos.ao_flight_pad) { voice.speak("%d meters", (int) (state.height + 0.5)); } else { reported_landing = 0; @@ -366,7 +367,7 @@ public class AltosUI extends JFrame { if (!state.ascent && (last || System.currentTimeMillis() - state.report_time >= 15000 || - state.state == AltosTelemetry.ao_flight_landed)) + state.state == Altos.ao_flight_landed)) { if (Math.abs(state.baro_speed) < 20 && state.height < 100) voice.speak("rocket landed safely"); @@ -401,12 +402,12 @@ public class AltosUI extends JFrame { private void tell(AltosState state, AltosState old_state) { if (old_state == null || old_state.state != state.state) { voice.speak(state.data.state); - if ((old_state == null || old_state.state <= AltosTelemetry.ao_flight_boost) && - state.state > AltosTelemetry.ao_flight_boost) { + if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && + state.state > Altos.ao_flight_boost) { voice.speak("max speed: %d meters per second.", (int) (state.max_speed + 0.5)); - } else if ((old_state == null || old_state.state < AltosTelemetry.ao_flight_drogue) && - state.state >= AltosTelemetry.ao_flight_drogue) { + } else if ((old_state == null || old_state.state < Altos.ao_flight_drogue) && + state.state >= Altos.ao_flight_drogue) { voice.speak("max height: %d meters.", (int) (state.max_height + 0.5)); } @@ -617,7 +618,7 @@ public class AltosUI extends JFrame { * a TeleDongle over the packet link */ private void SaveFlightData() { - new AltosEeprom(AltosUI.this); + new AltosEepromDownload(AltosUI.this); } /* Create the AltosUI menus -- cgit v1.2.3 From 1c3b2fe357d6acf28f48aeddd91693f10381be51 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 31 Jul 2010 10:05:15 -0700 Subject: altosui: Capture config and version info in .eeprom files Instead of only writing the serial number to the .eeprom file, write all of the config values and all of the version reply to the .eeprom file. The config values, in particular, contain the accelerometer calibration data which is needed to correctly compute acceleration from the captured accelerometer data. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromDownload.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 756b82d1..1f4a278f 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -103,7 +103,7 @@ public class AltosEepromDownload implements Runnable { AltosFile eeprom_name; LinkedList eeprom_pending = new LinkedList(); - serial_line.printf("v\n"); + serial_line.printf("\nc s\nv\n"); /* Pull the serial number out of the version information */ @@ -113,12 +113,13 @@ public class AltosEepromDownload implements Runnable { if (line.startsWith("serial-number")) { try { serial = Integer.parseInt(line.substring(13).trim()); - eeprom_pending.add(String.format("%s\n", line)); } catch (NumberFormatException ne) { serial = 0; } } + eeprom_pending.add(String.format("%s\n", line)); + /* signals the end of the version info */ if (line.startsWith("software-version")) break; -- cgit v1.2.3 From 88e0137a60d7a13ddb7781befa76650e13ad44ae Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 31 Jul 2010 10:07:38 -0700 Subject: altosui: Merge gps date and time classes into gps class No reason to split out the date and time information from the other gps info. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosGPS.java | 113 ++++++++++++++++++++++++++++------------- ao-tools/altosui/AltosUI.java | 12 ++--- 2 files changed, 83 insertions(+), 42 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index f8eb5f48..42f4dc83 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -23,37 +23,6 @@ import altosui.AltosParse; public class AltosGPS { - public class AltosGPSTime { - int year; - int month; - int day; - int hour; - int minute; - int second; - - public AltosGPSTime(String date, String time) throws ParseException { - String[] ymd = date.split("-"); - if (ymd.length != 3) - throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); - year = AltosParse.parse_int(ymd[0]); - month = AltosParse.parse_int(ymd[1]); - day = AltosParse.parse_int(ymd[2]); - - String[] hms = time.split(":"); - if (hms.length != 3) - throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); - hour = AltosParse.parse_int(hms[0]); - minute = AltosParse.parse_int(hms[1]); - second = AltosParse.parse_int(hms[2]); - } - - public AltosGPSTime() { - year = month = day = 0; - hour = minute = second = 0; - } - - } - public class AltosGPSSat { int svid; int c_n0; @@ -62,10 +31,15 @@ public class AltosGPS { int nsat; boolean gps_locked; boolean gps_connected; - AltosGPSTime gps_time; double lat; /* degrees (+N -S) */ double lon; /* degrees (+E -W) */ int alt; /* m */ + int year; + int month; + int day; + int hour; + int minute; + int second; int gps_extended; /* has extra data */ double ground_speed; /* m/s */ @@ -77,6 +51,27 @@ public class AltosGPS { AltosGPSSat[] cc_gps_sat; /* tracking data */ + void ParseGPSTime(String date, String time) throws ParseException { + String[] ymd = date.split("-"); + if (ymd.length != 3) + throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); + year = AltosParse.parse_int(ymd[0]); + month = AltosParse.parse_int(ymd[1]); + day = AltosParse.parse_int(ymd[2]); + + String[] hms = time.split(":"); + if (hms.length != 3) + throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); + hour = AltosParse.parse_int(hms[0]); + minute = AltosParse.parse_int(hms[1]); + second = AltosParse.parse_int(hms[2]); + } + + void ClearGPSTime() { + year = month = day = 0; + hour = minute = second = 0; + } + public AltosGPS(String[] words, int i) throws ParseException { AltosParse.word(words[i++], "GPS"); nsat = AltosParse.parse_int(words[i++]); @@ -86,18 +81,17 @@ public class AltosGPS { gps_locked = false; lat = lon = 0; alt = 0; + ClearGPSTime(); if ((words[i]).equals("unlocked")) { gps_connected = true; - gps_time = new AltosGPSTime(); i++; } else if ((words[i]).equals("not-connected")) { - gps_time = new AltosGPSTime(); i++; } else if (words.length >= 40) { gps_locked = true; gps_connected = true; - gps_time = new AltosGPSTime(words[i], words[i+1]); i += 2; + ParseGPSTime(words[i], words[i+1]); i += 2; lat = AltosParse.parse_coord(words[i++]); lon = AltosParse.parse_coord(words[i++]); alt = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "m")); @@ -108,7 +102,6 @@ public class AltosGPS { h_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(herr)")); v_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(verr)")); } else { - gps_time = new AltosGPSTime(); i++; } AltosParse.word(words[i++], "SAT"); @@ -125,4 +118,52 @@ public class AltosGPS { cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]); } } + + public void set_latitude(int in_lat) { + lat = in_lat / 10.0e7; + } + + public void set_longitude(int in_lon) { + lon = in_lon / 10.0e7; + } + + public void set_time(int hour, int minute, int second) { + hour = hour; + minute = minute; + second = second; + } + + public void set_date(int year, int month, int day) { + year = year; + month = month; + day = day; + } + + public void set_flags(int flags) { + flags = flags; + } + + public void set_altitude(int altitude) { + altitude = altitude; + } + + public void add_sat(int svid, int c_n0) { + if (cc_gps_sat == null) { + cc_gps_sat = new AltosGPS.AltosGPSSat[1]; + } else { + AltosGPSSat[] new_gps_sat = new AltosGPS.AltosGPSSat[cc_gps_sat.length + 1]; + for (int i = 0; i < cc_gps_sat.length; i++) + new_gps_sat[i] = cc_gps_sat[i]; + cc_gps_sat = new_gps_sat; + } + AltosGPS.AltosGPSSat sat = new AltosGPS.AltosGPSSat(); + sat.svid = svid; + sat.c_n0 = c_n0; + cc_gps_sat[cc_gps_sat.length - 1] = sat; + } + + public AltosGPS() { + ClearGPSTime(); + cc_gps_sat = null; + } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 824e4b5b..fa5a9ade 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -310,13 +310,13 @@ public class AltosUI extends JFrame { info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt); } info_add_row(1, "GPS date", "%04d-%02d-%02d", - state.gps.gps_time.year, - state.gps.gps_time.month, - state.gps.gps_time.day); + state.gps.year, + state.gps.month, + state.gps.day); info_add_row(1, "GPS time", " %02d:%02d:%02d", - state.gps.gps_time.hour, - state.gps.gps_time.minute, - state.gps.gps_time.second); + state.gps.hour, + state.gps.minute, + state.gps.second); int nsat_vis = 0; int c; -- cgit v1.2.3 From 9c9b35254c693b3ade42b24d1e29eaf31e6ba2aa Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 31 Jul 2010 10:24:56 -0700 Subject: altosui: Clear displayed data rows as needed. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index fa5a9ade..faa20469 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -92,8 +92,11 @@ class AltosFlightInfoTableModel extends AbstractTableModel { public int getRowCount() { return 20; } + int current_row = 0; + int prev_num_rows = 0; + public Object getValueAt(int row, int col) { - if (row >= rows.size()) + if (row >= prev_num_rows) return ""; if (col == 0) return rows.get(row).name; @@ -101,9 +104,6 @@ class AltosFlightInfoTableModel extends AbstractTableModel { return rows.get(row).value; } - int current_row = 0; - int prev_num_rows = 0; - public void resetRow() { current_row = 0; } @@ -115,10 +115,9 @@ class AltosFlightInfoTableModel extends AbstractTableModel { current_row++; } public void finish() { - if (current_row > prev_num_rows) { + if (current_row > prev_num_rows) fireTableRowsInserted(prev_num_rows, current_row - 1); - prev_num_rows = current_row; - } + prev_num_rows = current_row; fireTableDataChanged(); } } -- cgit v1.2.3 From 9e8f7f75442303f9bfa99a0435984f5d36863ae6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 31 Jul 2010 10:34:21 -0700 Subject: altosui: Split status and info panels into separate files This moves some code out of AltosUI.java into separate files Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlightInfoTableModel.java | 81 ++++++++++++++++++++++ ao-tools/altosui/AltosFlightStatusTableModel.java | 61 ++++++++++++++++ ao-tools/altosui/AltosUI.java | 84 +---------------------- ao-tools/altosui/Makefile | 2 + 4 files changed, 146 insertions(+), 82 deletions(-) create mode 100644 ao-tools/altosui/AltosFlightInfoTableModel.java create mode 100644 ao-tools/altosui/AltosFlightStatusTableModel.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlightInfoTableModel.java b/ao-tools/altosui/AltosFlightInfoTableModel.java new file mode 100644 index 00000000..2a22e3e5 --- /dev/null +++ b/ao-tools/altosui/AltosFlightInfoTableModel.java @@ -0,0 +1,81 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlightInfoTableModel extends AbstractTableModel { + private String[] columnNames = {"Field", "Value"}; + + class InfoLine { + String name; + String value; + + public InfoLine(String n, String v) { + name = n; + value = v; + } + } + + private ArrayList rows = new ArrayList(); + + public int getColumnCount() { return columnNames.length; } + public String getColumnName(int col) { return columnNames[col]; } + + public int getRowCount() { return 20; } + + int current_row = 0; + int prev_num_rows = 0; + + public Object getValueAt(int row, int col) { + if (row >= rows.size()) + return ""; + if (col == 0) + return rows.get(row).name; + else + return rows.get(row).value; + } + + public void resetRow() { + current_row = 0; + } + public void addRow(String name, String value) { + if (current_row >= rows.size()) + rows.add(current_row, new InfoLine(name, value)); + else + rows.set(current_row, new InfoLine(name, value)); + current_row++; + } + public void finish() { + if (current_row > prev_num_rows) + fireTableRowsInserted(prev_num_rows, current_row - 1); + while (rows.size() > current_row) + rows.remove(rows.size() - 1); + prev_num_rows = current_row; + fireTableDataChanged(); + } +} diff --git a/ao-tools/altosui/AltosFlightStatusTableModel.java b/ao-tools/altosui/AltosFlightStatusTableModel.java new file mode 100644 index 00000000..174dd42c --- /dev/null +++ b/ao-tools/altosui/AltosFlightStatusTableModel.java @@ -0,0 +1,61 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlightStatusTableModel extends AbstractTableModel { + private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; + private Object[] data = { 0, "idle", 0, 0 }; + + public int getColumnCount() { return columnNames.length; } + public int getRowCount() { return 2; } + public Object getValueAt(int row, int col) { + if (row == 0) + return columnNames[col]; + return data[col]; + } + + public void setValueAt(Object value, int col) { + data[col] = value; + fireTableCellUpdated(1, col); + } + + public void setValueAt(Object value, int row, int col) { + setValueAt(value, col); + } + + public void set(AltosState state) { + setValueAt(String.format("%1.0f", state.height), 0); + setValueAt(state.data.state, 1); + setValueAt(state.data.rssi, 2); + double speed = state.baro_speed; + if (state.ascent) + speed = state.speed; + setValueAt(String.format("%1.0f", speed), 3); + } +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index faa20469..58f39de5 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -37,91 +37,11 @@ import altosui.AltosDeviceDialog; import altosui.AltosPreferences; import altosui.AltosLog; import altosui.AltosVoice; +import altosui.AltosFlightStatusTableModel; +import altosui.AltosFlightInfoTableModel; import libaltosJNI.*; -class AltosFlightStatusTableModel extends AbstractTableModel { - private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; - private Object[] data = { 0, "idle", 0, 0 }; - - public int getColumnCount() { return columnNames.length; } - public int getRowCount() { return 2; } - public Object getValueAt(int row, int col) { - if (row == 0) - return columnNames[col]; - return data[col]; - } - - public void setValueAt(Object value, int col) { - data[col] = value; - fireTableCellUpdated(1, col); - } - - public void setValueAt(Object value, int row, int col) { - setValueAt(value, col); - } - - public void set(AltosState state) { - setValueAt(String.format("%1.0f", state.height), 0); - setValueAt(state.data.state, 1); - setValueAt(state.data.rssi, 2); - double speed = state.baro_speed; - if (state.ascent) - speed = state.speed; - setValueAt(String.format("%1.0f", speed), 3); - } -} - -class AltosFlightInfoTableModel extends AbstractTableModel { - private String[] columnNames = {"Field", "Value"}; - - class InfoLine { - String name; - String value; - - public InfoLine(String n, String v) { - name = n; - value = v; - } - } - - private ArrayList rows = new ArrayList(); - - public int getColumnCount() { return columnNames.length; } - public String getColumnName(int col) { return columnNames[col]; } - - public int getRowCount() { return 20; } - - int current_row = 0; - int prev_num_rows = 0; - - public Object getValueAt(int row, int col) { - if (row >= prev_num_rows) - return ""; - if (col == 0) - return rows.get(row).name; - else - return rows.get(row).value; - } - - public void resetRow() { - current_row = 0; - } - public void addRow(String name, String value) { - if (current_row >= rows.size()) - rows.add(current_row, new InfoLine(name, value)); - else - rows.set(current_row, new InfoLine(name, value)); - current_row++; - } - public void finish() { - if (current_row > prev_num_rows) - fireTableRowsInserted(prev_num_rows, current_row - 1); - prev_num_rows = current_row; - fireTableDataChanged(); - } -} - public class AltosUI extends JFrame { private int channel = -1; diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 790aecda..3b88e1c1 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -6,6 +6,8 @@ CLASSFILES=\ AltosEeprom.class \ AltosEepromMonitor.class \ AltosFile.class \ + AltosFlightInfoTableModel.class \ + AltosFlightStatusTableModel.class \ AltosGPS.class \ AltosGreatCircle.class \ AltosLog.class \ -- cgit v1.2.3 From 85a670b5a904d6750d0f179ae307baeb8fc7cbd2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Aug 2010 13:40:17 -0400 Subject: altosui: Explicitly initialize Altos class Because the Altos class is never instantiated, the static initializers are never called, leaving the string to state mapping empty. Hand-code the call to the initialer instead. Signed-off-by: Keith Packard --- ao-tools/altosui/Altos.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java index bda4080e..6ea7b43c 100644 --- a/ao-tools/altosui/Altos.java +++ b/ao-tools/altosui/Altos.java @@ -54,6 +54,10 @@ public class Altos { static final int ao_flight_invalid = 9; static HashMap string_to_state = new HashMap(); + + static boolean map_initialized = false; + + static void initialize_map() { string_to_state.put("startup", ao_flight_startup); string_to_state.put("idle", ao_flight_idle); @@ -65,6 +69,7 @@ public class Altos { string_to_state.put("main", ao_flight_main); string_to_state.put("landed", ao_flight_landed); string_to_state.put("invalid", ao_flight_invalid); + map_initialized = true; } static String[] state_to_string = { @@ -81,6 +86,8 @@ public class Altos { }; static public int state(String state) { + if (!map_initialized) + initialize_map(); if (string_to_state.containsKey(state)) return string_to_state.get(state); return ao_flight_invalid; -- cgit v1.2.3 From d8bf05f7ad55964c9bce0551e58f4ef6c9f721ad Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Aug 2010 13:50:18 -0400 Subject: altosui: Split flight record out of telemetry class This will permit either telemetry or eeprom data to be used to construct the sequence of flight events for reply or data generation. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConvert.java | 57 +------- ao-tools/altosui/AltosEepromDownload.java | 1 + ao-tools/altosui/AltosEepromMonitor.java | 1 + ao-tools/altosui/AltosEepromReader.java | 120 +++++++++++++++++ ao-tools/altosui/AltosEepromRecord.java | 70 ++++++++++ ao-tools/altosui/AltosGPS.java | 30 +++++ ao-tools/altosui/AltosRecord.java | 208 ++++++++++++++++++++++++++++++ ao-tools/altosui/AltosState.java | 38 +++--- ao-tools/altosui/AltosTelemetry.java | 66 +--------- ao-tools/altosui/AltosUI.java | 93 ++++++++----- ao-tools/altosui/Makefile | 6 +- ao-tools/altosui/Manifest.txt | 2 +- 12 files changed, 517 insertions(+), 175 deletions(-) create mode 100644 ao-tools/altosui/AltosEepromReader.java create mode 100644 ao-tools/altosui/AltosEepromRecord.java create mode 100644 ao-tools/altosui/AltosRecord.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConvert.java b/ao-tools/altosui/AltosConvert.java index 3be0716c..8cc1df27 100644 --- a/ao-tools/altosui/AltosConvert.java +++ b/ao-tools/altosui/AltosConvert.java @@ -62,7 +62,7 @@ public class AltosConvert { * altitudes are measured with respect to the mean sea level */ static double - cc_altitude_to_pressure(double altitude) + altitude_to_pressure(double altitude) { double base_temperature = LAYER0_BASE_TEMPERATURE; double base_pressure = LAYER0_BASE_PRESSURE; @@ -115,7 +115,7 @@ public class AltosConvert { /* outputs the altitude associated with the given pressure. the altitude returned is measured with respect to the mean sea level */ static double - cc_pressure_to_altitude(double pressure) + pressure_to_altitude(double pressure) { double next_base_temperature = LAYER0_BASE_TEMPERATURE; @@ -178,59 +178,6 @@ public class AltosConvert { return altitude; } - /* - * 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 - cc_barometer_to_pressure(double count) - { - return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; - } - - static double - cc_barometer_to_altitude(double baro) - { - double Pa = cc_barometer_to_pressure(baro); - return cc_pressure_to_altitude(Pa); - } - - static final double count_per_mss = 27.0; - - static double - cc_accelerometer_to_acceleration(double accel, double ground_accel) - { - return (ground_accel - accel) / count_per_mss; - } - - /* 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 - cc_thermometer_to_temperature(double thermo) - { - return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; - } - static double cc_battery_to_voltage(double battery) { diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 1f4a278f..f2fcd09e 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -31,6 +31,7 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.Altos; import altosui.AltosSerial; import altosui.AltosSerialMonitor; +import altosui.AltosRecord; import altosui.AltosTelemetry; import altosui.AltosState; import altosui.AltosDeviceDialog; diff --git a/ao-tools/altosui/AltosEepromMonitor.java b/ao-tools/altosui/AltosEepromMonitor.java index e110a354..b88fdd29 100644 --- a/ao-tools/altosui/AltosEepromMonitor.java +++ b/ao-tools/altosui/AltosEepromMonitor.java @@ -30,6 +30,7 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.AltosSerial; import altosui.AltosSerialMonitor; +import altosui.AltosRecord; import altosui.AltosTelemetry; import altosui.AltosState; import altosui.AltosDeviceDialog; diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java new file mode 100644 index 00000000..6fe9bfe4 --- /dev/null +++ b/ao-tools/altosui/AltosEepromReader.java @@ -0,0 +1,120 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosRecord; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosEepromMonitor; + +public class AltosEepromReader { + + 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_basic = seen_flight|seen_sensor|seen_temp_volt|seen_deploy; + + static final int seen_gps_time = 16; + + AltosRecord state; + AltosEepromRecord record; + + int seen; + + int tick; + + boolean done; + + FileInputStream input; + + public AltosRecord read() throws IOException, ParseException { + for (;;) { + if (record == null) { + record = new AltosEepromRecord(AltosRecord.gets(input)); + if (record == null) { + if (done) + return null; + return state; + } + + /* eeprom only records low 16 bits of tick count */ + int tick = record.tick | (state.tick & ~0xffff); + + if (tick < state.tick) { + if (state.tick - tick > 0x8000) + tick += 0x10000; + else + tick = state.tick; + } + + /* Accumulate data in the state record while + * the time stamp is not increasing + */ + + if ((seen & seen_basic) == seen_basic && tick > state.tick) + return new AltosRecord(state); + } + + state.tick = tick; + switch (record.cmd) { + case Altos.AO_LOG_FLIGHT: + state.ground_accel = record.a; + state.flight = record.b; + break; + case Altos.AO_LOG_SENSOR: + state.accel = record.a; + state.pres = record.b; + break; + case Altos.AO_LOG_TEMP_VOLT: + state.temp = record.a; + state.batt = record.b; + break; + case Altos.AO_LOG_DEPLOY: + state.drogue = record.a; + state.main = record.b; + break; + case Altos.AO_LOG_GPS_TIME: + break; + } + record = null; + } + } + + public AltosEepromReader (FileInputStream in_input) { + state = new AltosRecord(); + input = in_input; + seen = 0; + done = false; + } +} diff --git a/ao-tools/altosui/AltosEepromRecord.java b/ao-tools/altosui/AltosEepromRecord.java new file mode 100644 index 00000000..5b359352 --- /dev/null +++ b/ao-tools/altosui/AltosEepromRecord.java @@ -0,0 +1,70 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosSerial; +import altosui.AltosSerialMonitor; +import altosui.AltosRecord; +import altosui.AltosTelemetry; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosEepromMonitor; + +public class AltosEepromRecord { + public int cmd; + public int tick; + public int a; + public int b; + + public AltosEepromRecord (String line) throws ParseException { + if (line == null) { + cmd = Altos.AO_LOG_INVALID; + } else { + String[] tokens = line.split("\\s+"); + + if (tokens[0].equals("serial-number")) { + cmd = Altos.AO_LOG_SERIAL_NUMBER; + tick = 0; + a = Integer.parseInt(tokens[1]); + b = 0; + } else { + if (tokens.length != 4) + throw new ParseException(line, 0); + cmd = tokens[0].codePointAt(0); + tick = Integer.parseInt(tokens[1]); + a = Integer.parseInt(tokens[2]); + b = Integer.parseInt(tokens[3]); + } + } + } + +} diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index 42f4dc83..6b84d7a5 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -166,4 +166,34 @@ public class AltosGPS { ClearGPSTime(); cc_gps_sat = null; } + + public AltosGPS(AltosGPS old) { + nsat = old.nsat; + gps_locked = old.gps_locked; + gps_connected = old.gps_connected; + lat = old.lat; /* degrees (+N -S) */ + lon = old.lon; /* degrees (+E -W) */ + alt = old.alt; /* m */ + year = old.year; + month = old.month; + day = old.day; + hour = old.hour; + minute = old.minute; + second = old.second; + + gps_extended = old.gps_extended; /* has extra data */ + ground_speed = old.ground_speed; /* m/s */ + course = old.course; /* degrees */ + climb_rate = old.climb_rate; /* m/s */ + hdop = old.hdop; /* unitless? */ + h_error = old.h_error; /* m */ + v_error = old.v_error; /* m */ + + AltosGPSSat[] cc_gps_sat; /* tracking data */ + cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length]; + for (int i = 0; i < old.cc_gps_sat.length; i++) { + cc_gps_sat[i].svid = old.cc_gps_sat[i].svid; + cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0; + } + } } diff --git a/ao-tools/altosui/AltosRecord.java b/ao-tools/altosui/AltosRecord.java new file mode 100644 index 00000000..c3e9d211 --- /dev/null +++ b/ao-tools/altosui/AltosRecord.java @@ -0,0 +1,208 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; +import java.util.HashMap; +import java.io.*; +import altosui.AltosConvert; +import altosui.AltosGPS; + +public class AltosRecord { + int version; + String callsign; + int serial; + int flight; + int rssi; + int status; + String state; + int tick; + int accel; + int pres; + int temp; + int batt; + int drogue; + int main; + int flight_accel; + int ground_accel; + int flight_vel; + int flight_pres; + int ground_pres; + int accel_plus_g; + int accel_minus_g; + AltosGPS gps; + + /* + * 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() { + return barometer_to_pressure(pres); + } + + public double ground_pressure() { + return barometer_to_pressure(ground_pres); + } + + public double altitude() { + return AltosConvert.pressure_to_altitude(pressure()); + } + + public double ground_altitude() { + return AltosConvert.pressure_to_altitude(ground_pressure()); + } + + public double height() { + return altitude() - ground_altitude(); + } + + public double battery_voltage() { + return AltosConvert.cc_battery_to_voltage(batt); + } + + public double main_voltage() { + return AltosConvert.cc_ignitor_to_voltage(main); + } + + public double drogue_voltage() { + 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() { + 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() { + return (accel_plus_g - accel) / accel_counts_per_mss(); + } + + public double accel_speed() { + double speed = flight_vel / (accel_counts_per_mss() * 100.0); + return speed; + } + + public int state() { + System.out.printf("state: %s -> %d\n", state, Altos.state(state)); + return Altos.state(state); + } + + public static String gets(FileInputStream s) throws IOException { + int c; + String line = ""; + + while ((c = s.read()) != -1) { + if (c == '\r') + continue; + if (c == '\n') { + return line; + } + line = line + (char) c; + } + return null; + } + + public AltosRecord(AltosRecord 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; + gps = new AltosGPS(old.gps); + } + + public AltosRecord() { + version = 0; + callsign = "N0CALL"; + serial = 0; + flight = 0; + rssi = 0; + status = 0; + state = "startup"; + tick = 0; + accel = 0; + pres = 0; + temp = 0; + batt = 0; + drogue = 0; + main = 0; + flight_accel = 0; + ground_accel = 0; + flight_vel = 0; + flight_pres = 0; + ground_pres = 0; + accel_plus_g = 0; + accel_minus_g = 0; + gps = new AltosGPS(); + } +} diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index 9aa10a08..fc06f839 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -16,16 +16,16 @@ */ /* - * Track flight state from telemetry data stream + * Track flight state from telemetry or eeprom data stream */ package altosui; -import altosui.AltosTelemetry; +import altosui.AltosRecord; import altosui.AltosGPS; public class AltosState { - AltosTelemetry data; + AltosRecord data; /* derived data */ @@ -71,25 +71,23 @@ public class AltosState { double speak_altitude; - void init (AltosTelemetry cur, AltosState prev_state) { + void init (AltosRecord cur, AltosState prev_state) { int i; - AltosTelemetry prev; - double accel_counts_per_mss; + AltosRecord prev; data = cur; - ground_altitude = AltosConvert.cc_barometer_to_altitude(data.ground_pres); - height = AltosConvert.cc_barometer_to_altitude(data.flight_pres) - ground_altitude; + ground_altitude = data.ground_altitude(); + height = data.altitude() - ground_altitude; report_time = System.currentTimeMillis(); - accel_counts_per_mss = ((data.accel_minus_g - data.accel_plus_g) / 2.0) / 9.80665; - acceleration = (data.ground_accel - data.flight_accel) / accel_counts_per_mss; - speed = data.flight_vel / (accel_counts_per_mss * 100.0); - temperature = AltosConvert.cc_thermometer_to_temperature(data.temp); - drogue_sense = AltosConvert.cc_ignitor_to_voltage(data.drogue); - main_sense = AltosConvert.cc_ignitor_to_voltage(data.main); - battery = AltosConvert.cc_battery_to_voltage(data.batt); + acceleration = data.acceleration(); + speed = data.accel_speed(); + temperature = data.temperature(); + drogue_sense = data.drogue_voltage(); + main_sense = data.main_voltage(); + battery = data.battery_voltage(); tick = data.tick; state = data.state(); @@ -125,7 +123,7 @@ public class AltosState { time_change = 0; } - if (state == AltosTelemetry.ao_flight_pad) { + if (state == Altos.ao_flight_pad) { if (data.gps != null && data.gps.gps_locked && data.gps.nsat >= 4) { npad++; if (npad > 1) { @@ -149,8 +147,8 @@ public class AltosState { gps_ready = gps_waiting == 0; - ascent = (AltosTelemetry.ao_flight_boost <= state && - state <= AltosTelemetry.ao_flight_coast); + ascent = (Altos.ao_flight_boost <= state && + state <= Altos.ao_flight_coast); /* Only look at accelerometer data on the way up */ if (ascent && acceleration > max_acceleration) @@ -173,11 +171,11 @@ public class AltosState { } } - public AltosState(AltosTelemetry cur) { + public AltosState(AltosRecord cur) { init(cur, null); } - public AltosState (AltosTelemetry cur, AltosState prev) { + public AltosState (AltosRecord cur, AltosState prev) { init(cur, prev); } } diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index e13b42e2..f495be1d 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -21,6 +21,7 @@ import java.lang.*; import java.text.*; import java.util.HashMap; import altosui.AltosConvert; +import altosui.AltosRecord; import altosui.AltosGPS; /* @@ -51,72 +52,9 @@ import altosui.AltosGPS; * SAT 10 29 30 24 28 5 25 21 20 15 33 1 23 30 24 18 26 10 29 2 26 */ -public class AltosTelemetry { - int version; - String callsign; - int serial; - int flight; - int rssi; - int status; - String state; - int tick; - int accel; - int pres; - int temp; - int batt; - int drogue; - int main; - int flight_accel; - int ground_accel; - int flight_vel; - int flight_pres; - int ground_pres; - int accel_plus_g; - int accel_minus_g; - AltosGPS gps; - - public static final int ao_flight_startup = 0; - public static final int ao_flight_idle = 1; - public static final int ao_flight_pad = 2; - public static final int ao_flight_boost = 3; - public static final int ao_flight_fast = 4; - public static final int ao_flight_coast = 5; - public static final int ao_flight_drogue = 6; - public static final int ao_flight_main = 7; - public static final int ao_flight_landed = 8; - public static final int ao_flight_invalid = 9; - - static HashMap states = new HashMap(); - { - states.put("startup", ao_flight_startup); - states.put("idle", ao_flight_idle); - states.put("pad", ao_flight_pad); - states.put("boost", ao_flight_boost); - states.put("fast", ao_flight_fast); - states.put("coast", ao_flight_coast); - states.put("drogue", ao_flight_drogue); - states.put("main", ao_flight_main); - states.put("landed", ao_flight_landed); - states.put("invalid", ao_flight_invalid); - } - - public int state() { - if (states.containsKey(state)) - return states.get(state); - return ao_flight_invalid; - } - - public double altitude() { - return AltosConvert.cc_pressure_to_altitude(AltosConvert.cc_barometer_to_pressure(pres)); - } - - public double pad_altitude() { - return AltosConvert.cc_pressure_to_altitude(AltosConvert.cc_barometer_to_pressure(ground_pres)); - } - +public class AltosTelemetry extends AltosRecord { public AltosTelemetry(String line) throws ParseException { String[] words = line.split("\\s+"); - int i = 0; AltosParse.word (words[i++], "VERSION"); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 58f39de5..40663882 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -31,6 +31,7 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.Altos; import altosui.AltosSerial; import altosui.AltosSerialMonitor; +import altosui.AltosRecord; import altosui.AltosTelemetry; import altosui.AltosState; import altosui.AltosDeviceDialog; @@ -343,7 +344,9 @@ public class AltosUI extends JFrame { class DisplayThread extends Thread { IdleThread idle_thread; - String read() throws InterruptedException { return null; } + String name; + + AltosRecord read() throws InterruptedException, ParseException { return null; } void close() { } @@ -360,18 +363,19 @@ public class AltosUI extends JFrame { info_finish(); idle_thread.start(); try { - while ((line = read()) != null) { + for (;;) { try { - AltosTelemetry t = new AltosTelemetry(line); + AltosRecord record = read(); + if (record == null) + break; old_state = state; - state = new AltosState(t, state); + state = new AltosState(record, state); update(state); show(state); tell(state, old_state); idle_thread.notice(state); } catch (ParseException pp) { - System.out.printf("Parse error on %s\n", line); - System.out.println("exception " + pp); + System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); } } } catch (InterruptedException ee) { @@ -387,11 +391,20 @@ public class AltosUI extends JFrame { } } - class DeviceThread extends DisplayThread { + class TelemetryThread extends DisplayThread { + + String readline() throws InterruptedException { return null; } + + AltosRecord read() throws InterruptedException, ParseException { + return new AltosTelemetry(readline()); + } + } + + class DeviceThread extends TelemetryThread { AltosSerial serial; LinkedBlockingQueue telem; - String read() throws InterruptedException { + String readline() throws InterruptedException { return telem.take(); } @@ -404,6 +417,7 @@ public class AltosUI extends JFrame { serial = s; telem = new LinkedBlockingQueue(); serial.add_monitor(telem); + name = "telemetry"; } } @@ -435,40 +449,26 @@ public class AltosUI extends JFrame { stop_display(); } - String readline(FileInputStream s) throws IOException { - int c; - String line = ""; - - while ((c = s.read()) != -1) { - if (c == '\r') - continue; - if (c == '\n') { - return line; - } - line = line + (char) c; - } - return null; - } - /* * Open an existing telemetry file and replay it in realtime */ - class ReplayThread extends DisplayThread { + class ReplayTelemetryThread extends TelemetryThread { FileInputStream replay; - String filename; - ReplayThread(FileInputStream in, String name) { + ReplayTelemetryThread(FileInputStream in, String in_name) { replay = in; - filename = name; + name = in_name; } - String read() { + String readline() { try { - return readline(replay); + String line = AltosRecord.gets(replay); + System.out.printf("telemetry line %s\n", line); + return line; } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, - filename, + name, "error reading", JOptionPane.ERROR_MESSAGE); } @@ -485,11 +485,32 @@ public class AltosUI extends JFrame { void update(AltosState state) throws InterruptedException { /* Make it run in realtime after the rocket leaves the pad */ - if (state.state > AltosTelemetry.ao_flight_pad) + if (state.state > Altos.ao_flight_pad) Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); } } + class ReplayEepromThread extends DisplayThread { + FileInputStream replay; + + AltosRecord read () { + return null; + } + + void close () { + try { + replay.close(); + } catch (IOException ee) { + } + report(); + } + + ReplayEepromThread(FileInputStream in, String in_name) { + replay = in; + name = in_name; + } + } + Thread display_thread; private void stop_display() { @@ -510,8 +531,8 @@ public class AltosUI extends JFrame { private void Replay() { JFileChooser logfile_chooser = new JFileChooser(); - logfile_chooser.setDialogTitle("Select Telemetry File"); - logfile_chooser.setFileFilter(new FileNameExtensionFilter("Telemetry file", "telem")); + logfile_chooser.setDialogTitle("Select Flight Record File"); + logfile_chooser.setFileFilter(new FileNameExtensionFilter("Flight data file", "eeprom", "telem")); logfile_chooser.setCurrentDirectory(AltosPreferences.logdir()); int returnVal = logfile_chooser.showOpenDialog(AltosUI.this); @@ -522,7 +543,11 @@ public class AltosUI extends JFrame { String filename = file.getName(); try { FileInputStream replay = new FileInputStream(file); - ReplayThread thread = new ReplayThread(replay, filename); + DisplayThread thread; + if (filename.endsWith("eeprom")) + thread = new ReplayEepromThread(replay, filename); + else + thread = new ReplayTelemetryThread(replay, filename); run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 3b88e1c1..3f55db0b 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -2,9 +2,12 @@ CLASSPATH=classes:./* CLASSFILES=\ + Altos.class \ AltosConvert.class \ - AltosEeprom.class \ + AltosEepromDownload.class \ AltosEepromMonitor.class \ + AltosEepromReader.class \ + AltosEepromRecord.class \ AltosFile.class \ AltosFlightInfoTableModel.class \ AltosFlightStatusTableModel.class \ @@ -13,6 +16,7 @@ CLASSFILES=\ AltosLog.class \ AltosParse.class \ AltosPreferences.class \ + AltosRecord.class \ AltosSerialMonitor.class \ AltosSerial.class \ AltosState.class \ diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt index 251ce2a0..504d0de3 100644 --- a/ao-tools/altosui/Manifest.txt +++ b/ao-tools/altosui/Manifest.txt @@ -1,2 +1,2 @@ Main-Class: altosui.AltosUI -Class-Path: freetts.jar +Class-Path: /usr/share/java/freetts.jar -- cgit v1.2.3 From aed55ef1ce45b0f6e6fefeebf50be97607b31d65 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 5 Aug 2010 15:00:15 -0400 Subject: working on java packaging details --- ao-tools/altosui/Makefile | 33 +++++++++++++++++---------------- ao-tools/altosui/Manifest.txt | 2 +- debian/altos.desktop | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 790aecda..bae42c9a 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -1,6 +1,6 @@ .SUFFIXES: .java .class -CLASSPATH=classes:./* +CLASSPATH=classes:./*:/usr/share/java/* CLASSFILES=\ AltosConvert.class \ AltosEeprom.class \ @@ -20,16 +20,17 @@ CLASSFILES=\ AltosDeviceDialog.class \ AltosVoice.class -FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 -FREETTSLIB=$(FREETTSSRC)/lib -FREETTSJAR= \ - cmudict04.jar \ - cmulex.jar \ - cmu_time_awb.jar \ - cmutimelex.jar \ - cmu_us_kal.jar \ - en_us.jar \ - freetts.jar +#FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 +#FREETTSLIB=$(FREETTSSRC)/lib +#FREETTSJAR=/usr/share/java/freetts.jar +#FREETTSJAR= \ +# cmudict04.jar \ +# cmulex.jar \ +# cmu_time_awb.jar \ +# cmutimelex.jar \ +# cmu_us_kal.jar \ +# en_us.jar \ +# freetts.jar JAVAFLAGS=-Xlint:unchecked @@ -55,14 +56,14 @@ altosui.jar: classes/altosui classes/libaltosJNI $(FREETTSJAR) $(CLASSFILES) Man classes/altosui: mkdir -p classes - ln -s .. classes/altosui + ln -sf .. classes/altosui classes/libaltosJNI: mkdir -p classes - ln -s ../../libaltos/libaltosJNI classes/libaltosJNI + ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI -$(FREETTSJAR): - ln -s $(FREETTSLIB)/$@ . +#$(FREETTSJAR): +# ln -s $(FREETTSLIB)/$@ . ifeq ($(OS),Darwin) RESOURCES=altosui.jar $(FREETTSJAR) ../libaltos/libaltos.dylib @@ -81,6 +82,6 @@ altosui: endif clean: - rm -f *.class $(FREETTSJAR) altosui.jar + rm -f *.class altosui.jar rm -f AltosUI.app/Contents/Resources/Java/* rm -rf classes diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt index 1f313a13..504d0de3 100644 --- a/ao-tools/altosui/Manifest.txt +++ b/ao-tools/altosui/Manifest.txt @@ -1,2 +1,2 @@ Main-Class: altosui.AltosUI -Class-Path: /usr/share/java/freetts-1.2.2.jar +Class-Path: /usr/share/java/freetts.jar diff --git a/debian/altos.desktop b/debian/altos.desktop index 106e34a0..4281ad3a 100644 --- a/debian/altos.desktop +++ b/debian/altos.desktop @@ -7,4 +7,4 @@ Icon=/usr/share/pixmaps/altusmetrum.xpm Exec=/usr/bin/ao-view %f Terminal=false MimeType=text/plain; -Categories=Science; +Categories=Education;Science; -- cgit v1.2.3 From 0e917f3ff822616adb147517ac961422e5fedbfd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Aug 2010 22:49:53 -0400 Subject: altosui: Compute flight state from eeprom data This lets eeprom files be used to replay flights. Signed-off-by: Keith Packard --- ao-tools/altosui/Altos.java | 20 ++- ao-tools/altosui/AltosEepromReader.java | 178 +++++++++++++++++++--- ao-tools/altosui/AltosEepromRecord.java | 56 ++++++- ao-tools/altosui/AltosFlightStatusTableModel.java | 2 +- ao-tools/altosui/AltosGPS.java | 31 ++-- ao-tools/altosui/AltosRecord.java | 11 +- ao-tools/altosui/AltosState.java | 13 +- ao-tools/altosui/AltosTelemetry.java | 2 +- ao-tools/altosui/AltosUI.java | 34 +++-- 9 files changed, 277 insertions(+), 70 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java index 6ea7b43c..53359e23 100644 --- a/ao-tools/altosui/Altos.java +++ b/ao-tools/altosui/Altos.java @@ -35,8 +35,18 @@ public class Altos { static final int AO_LOG_GPS_SAT = 'V'; static final int AO_LOG_GPS_DATE = 'Y'; - /* Added for 'serial-number' entry in eeprom files */ - static final int AO_LOG_SERIAL_NUMBER = 1000; + /* Added for header fields in eeprom files */ + static final int AO_LOG_CONFIG_VERSION = 1000; + static final int AO_LOG_MAIN_DEPLOY = 1001; + static final int AO_LOG_APOGEE_DELAY = 1002; + static final int AO_LOG_RADIO_CHANNEL = 1003; + static final int AO_LOG_CALLSIGN = 1004; + static final int AO_LOG_ACCEL_CAL = 1005; + static final int AO_LOG_RADIO_CAL = 1006; + static final int AO_LOG_MANUFACTURER = 1007; + static final int AO_LOG_PRODUCT = 1008; + static final int AO_LOG_SERIAL_NUMBER = 1009; + static final int AO_LOG_SOFTWARE_VERSION = 1010; /* Added to flag invalid records */ static final int AO_LOG_INVALID = -1; @@ -98,4 +108,10 @@ public class Altos { return "invalid"; return state_to_string[state]; } + + 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_NUM_SAT_SHIFT = 0; + static final int AO_GPS_NUM_SAT_MASK = 0xf; } diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 6fe9bfe4..7a8ff5b0 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -36,75 +36,181 @@ import altosui.AltosLog; import altosui.AltosVoice; import altosui.AltosEepromMonitor; +class AltosOrderedRecord extends AltosEepromRecord implements Comparable { + + int index; + + public AltosOrderedRecord(String line, int in_index, int prev_tick) + throws ParseException { + super(line); + int new_tick = tick | (prev_tick & ~0xffff); + if (new_tick < prev_tick) { + if (prev_tick - new_tick > 0x8000) + new_tick += 0x10000; + } + tick = new_tick; + index = in_index; + } + + public int compareTo(AltosOrderedRecord o) { + int tick_diff = tick - o.tick; + if (tick_diff != 0) + return tick_diff; + return index - o.index; + } +} + public class AltosEepromReader { 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|seen_temp_volt|seen_deploy; - static final int seen_gps_time = 16; - AltosRecord state; - AltosEepromRecord record; + AltosOrderedRecord record; + + TreeSet records; + + Iterator record_iterator; int seen; - int tick; + int index; + + boolean last_reported; + + double ground_pres; + double ground_accel; + + int n_pad_samples; - boolean done; + int gps_tick; FileInputStream input; public AltosRecord read() throws IOException, ParseException { for (;;) { if (record == null) { - record = new AltosEepromRecord(AltosRecord.gets(input)); - if (record == null) { - if (done) + if (!record_iterator.hasNext()) { + if (last_reported) return null; + last_reported = true; return state; } + record = record_iterator.next(); - /* eeprom only records low 16 bits of tick count */ - int tick = record.tick | (state.tick & ~0xffff); - - if (tick < state.tick) { - if (state.tick - tick > 0x8000) - tick += 0x10000; - else - tick = state.tick; - } - - /* Accumulate data in the state record while - * the time stamp is not increasing - */ - - if ((seen & seen_basic) == seen_basic && tick > state.tick) + if ((seen & seen_basic) == seen_basic && record.tick != state.tick) return new AltosRecord(state); } - state.tick = tick; + state.tick = record.tick; switch (record.cmd) { case Altos.AO_LOG_FLIGHT: state.ground_accel = record.a; state.flight = record.b; + seen |= seen_flight; break; case Altos.AO_LOG_SENSOR: state.accel = record.a; state.pres = record.b; + if (state.state < Altos.ao_flight_boost) { + n_pad_samples++; + ground_pres += state.pres; + state.ground_pres = (int) (ground_pres / n_pad_samples); + state.flight_pres = state.ground_pres; + System.out.printf("ground pressure %d altitude %f\n", + record.b, state.altitude()); + ground_accel += state.accel; + state.ground_accel = (int) (ground_accel / n_pad_samples); + state.flight_accel = state.ground_accel; + } else { + state.flight_pres = (state.flight_pres * 15 + state.pres) / 16; + state.flight_accel = (state.flight_accel * 15 + state.accel) / 16; + state.flight_vel += (state.accel_plus_g - state.accel); + } + seen |= seen_sensor; break; case Altos.AO_LOG_TEMP_VOLT: state.temp = record.a; state.batt = record.b; + seen |= seen_temp_volt; break; case Altos.AO_LOG_DEPLOY: state.drogue = record.a; state.main = record.b; + seen |= seen_deploy; + break; + case Altos.AO_LOG_STATE: + System.out.printf("state %d\n", record.a); + state.state = record.a; break; case Altos.AO_LOG_GPS_TIME: + gps_tick = state.tick; + state.gps = new AltosGPS(); + state.gps.hour = (record.a & 0xff); + state.gps.minute = (record.a >> 8); + state.gps.second = (record.b & 0xff); + int flags = (record.b >> 8); + state.gps.connected = (flags & Altos.AO_GPS_RUNNING) != 0; + state.gps.locked = (flags & Altos.AO_GPS_VALID) != 0; + state.gps.date_valid = (flags & Altos.AO_GPS_DATE_VALID) != 0; + state.gps.nsat = (flags & Altos.AO_GPS_NUM_SAT_MASK) >> + Altos.AO_GPS_NUM_SAT_SHIFT; + break; + case Altos.AO_LOG_GPS_LAT: + int lat32 = record.a | (record.b << 16); + state.gps.lat = (double) lat32 / 1e7; + break; + case Altos.AO_LOG_GPS_LON: + int lon32 = record.a | (record.b << 16); + state.gps.lon = (double) lon32 / 1e7; + break; + case Altos.AO_LOG_GPS_ALT: + state.gps.alt = record.a; + break; + case Altos.AO_LOG_GPS_SAT: + if (state.tick == gps_tick) { + int svid = record.a; + int c_n0 = record.b >> 8; + state.gps.add_sat(svid, c_n0); + } + break; + case Altos.AO_LOG_GPS_DATE: + state.gps.year = record.a & 0xff; + state.gps.month = record.a >> 8; + state.gps.day = record.b & 0xff; + break; + + case Altos.AO_LOG_CONFIG_VERSION: + break; + case Altos.AO_LOG_MAIN_DEPLOY: + break; + case Altos.AO_LOG_APOGEE_DELAY: + break; + case Altos.AO_LOG_RADIO_CHANNEL: + break; + case Altos.AO_LOG_CALLSIGN: + state.callsign = record.data; + break; + case Altos.AO_LOG_ACCEL_CAL: + state.accel_plus_g = record.a; + state.accel_minus_g = record.b; + break; + case Altos.AO_LOG_RADIO_CAL: + break; + case Altos.AO_LOG_MANUFACTURER: + break; + case Altos.AO_LOG_PRODUCT: + break; + case Altos.AO_LOG_SERIAL_NUMBER: + break; + case Altos.AO_LOG_SOFTWARE_VERSION: break; } record = null; @@ -113,8 +219,30 @@ public class AltosEepromReader { public AltosEepromReader (FileInputStream in_input) { state = new AltosRecord(); + state.state = Altos.ao_flight_pad; + state.accel_plus_g = 15758; + state.accel_minus_g = 16294; input = in_input; seen = 0; - done = false; + records = new TreeSet(); + + int index = 0; + int tick = 0; + + try { + for (;;) { + String line = AltosRecord.gets(input); + if (line == null) + break; + AltosOrderedRecord record = new AltosOrderedRecord(line, index++, tick); + if (record == null) + break; + tick = record.tick; + records.add(record); + } + } catch (IOException io) { + } catch (ParseException pe) { + } + record_iterator = records.iterator(); } } diff --git a/ao-tools/altosui/AltosEepromRecord.java b/ao-tools/altosui/AltosEepromRecord.java index 5b359352..86ac1fd2 100644 --- a/ao-tools/altosui/AltosEepromRecord.java +++ b/ao-tools/altosui/AltosEepromRecord.java @@ -44,25 +44,65 @@ public class AltosEepromRecord { public int tick; public int a; public int b; + String data; + public boolean tick_valid; public AltosEepromRecord (String line) throws ParseException { + tick_valid = false; + tick = 0; + a = 0; + b = 0; + data = null; if (line == null) { cmd = Altos.AO_LOG_INVALID; } else { String[] tokens = line.split("\\s+"); - if (tokens[0].equals("serial-number")) { - cmd = Altos.AO_LOG_SERIAL_NUMBER; - tick = 0; - a = Integer.parseInt(tokens[1]); - b = 0; - } else { + if (tokens[0].length() == 1) { if (tokens.length != 4) throw new ParseException(line, 0); cmd = tokens[0].codePointAt(0); - tick = Integer.parseInt(tokens[1]); + 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 = Altos.AO_LOG_CONFIG_VERSION; + data = tokens[2]; + } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { + cmd = Altos.AO_LOG_MAIN_DEPLOY; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { + cmd = Altos.AO_LOG_APOGEE_DELAY; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { + cmd = Altos.AO_LOG_RADIO_CHANNEL; a = Integer.parseInt(tokens[2]); - b = Integer.parseInt(tokens[3]); + } else if (tokens[0].equals("Callsign:")) { + cmd = Altos.AO_LOG_CALLSIGN; + data = tokens[1].replaceAll("\"",""); + } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { + cmd = Altos.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 = Altos.AO_LOG_RADIO_CAL; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("manufacturer")) { + cmd = Altos.AO_LOG_MANUFACTURER; + data = tokens[1]; + } else if (tokens[0].equals("product")) { + cmd = Altos.AO_LOG_PRODUCT; + data = tokens[1]; + } else if (tokens[0].equals("serial-number")) { + cmd = Altos.AO_LOG_SERIAL_NUMBER; + a = Integer.parseInt(tokens[1]); + } else if (tokens[0].equals("software-version")) { + cmd = Altos.AO_LOG_SOFTWARE_VERSION; + data = tokens[1]; + } else { + cmd = Altos.AO_LOG_INVALID; + data = line; } } } diff --git a/ao-tools/altosui/AltosFlightStatusTableModel.java b/ao-tools/altosui/AltosFlightStatusTableModel.java index 174dd42c..4c24b6ac 100644 --- a/ao-tools/altosui/AltosFlightStatusTableModel.java +++ b/ao-tools/altosui/AltosFlightStatusTableModel.java @@ -51,7 +51,7 @@ public class AltosFlightStatusTableModel extends AbstractTableModel { public void set(AltosState state) { setValueAt(String.format("%1.0f", state.height), 0); - setValueAt(state.data.state, 1); + setValueAt(state.data.state(), 1); setValueAt(state.data.rssi, 2); double speed = state.baro_speed; if (state.ascent) diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index 6b84d7a5..b3ee67e8 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -29,8 +29,9 @@ public class AltosGPS { } int nsat; - boolean gps_locked; - boolean gps_connected; + boolean locked; + boolean connected; + boolean date_valid; double lat; /* degrees (+N -S) */ double lon; /* degrees (+E -W) */ int alt; /* m */ @@ -77,19 +78,19 @@ public class AltosGPS { nsat = AltosParse.parse_int(words[i++]); AltosParse.word(words[i++], "sat"); - gps_connected = false; - gps_locked = false; + connected = false; + locked = false; lat = lon = 0; alt = 0; ClearGPSTime(); if ((words[i]).equals("unlocked")) { - gps_connected = true; + connected = true; i++; } else if ((words[i]).equals("not-connected")) { i++; } else if (words.length >= 40) { - gps_locked = true; - gps_connected = true; + locked = true; + connected = true; ParseGPSTime(words[i], words[i+1]); i += 2; lat = AltosParse.parse_coord(words[i++]); @@ -169,8 +170,8 @@ public class AltosGPS { public AltosGPS(AltosGPS old) { nsat = old.nsat; - gps_locked = old.gps_locked; - gps_connected = old.gps_connected; + locked = old.locked; + connected = old.connected; lat = old.lat; /* degrees (+N -S) */ lon = old.lon; /* degrees (+E -W) */ alt = old.alt; /* m */ @@ -189,11 +190,13 @@ public class AltosGPS { h_error = old.h_error; /* m */ v_error = old.v_error; /* m */ - AltosGPSSat[] cc_gps_sat; /* tracking data */ - cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length]; - for (int i = 0; i < old.cc_gps_sat.length; i++) { - cc_gps_sat[i].svid = old.cc_gps_sat[i].svid; - cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0; + if (old.cc_gps_sat != null) { + cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length]; + for (int i = 0; i < old.cc_gps_sat.length; i++) { + cc_gps_sat[i] = new AltosGPSSat(); + cc_gps_sat[i].svid = old.cc_gps_sat[i].svid; + cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0; + } } } } diff --git a/ao-tools/altosui/AltosRecord.java b/ao-tools/altosui/AltosRecord.java index c3e9d211..3440d935 100644 --- a/ao-tools/altosui/AltosRecord.java +++ b/ao-tools/altosui/AltosRecord.java @@ -31,7 +31,7 @@ public class AltosRecord { int flight; int rssi; int status; - String state; + int state; int tick; int accel; int pres; @@ -72,7 +72,7 @@ public class AltosRecord { } public double pressure() { - return barometer_to_pressure(pres); + return barometer_to_pressure(flight_pres); } public double ground_pressure() { @@ -136,9 +136,8 @@ public class AltosRecord { return speed; } - public int state() { - System.out.printf("state: %s -> %d\n", state, Altos.state(state)); - return Altos.state(state); + public String state() { + return Altos.state_name(state); } public static String gets(FileInputStream s) throws IOException { @@ -188,7 +187,7 @@ public class AltosRecord { flight = 0; rssi = 0; status = 0; - state = "startup"; + state = Altos.ao_flight_startup; tick = 0; accel = 0; pres = 0; diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index fc06f839..deeb4c77 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -89,7 +89,7 @@ public class AltosState { main_sense = data.main_voltage(); battery = data.battery_voltage(); tick = data.tick; - state = data.state(); + state = data.state; if (prev_state != null) { @@ -124,7 +124,12 @@ public class AltosState { } if (state == Altos.ao_flight_pad) { - if (data.gps != null && data.gps.gps_locked && data.gps.nsat >= 4) { + if (data.gps == null) + System.out.printf("on pad, gps null\n"); + else + System.out.printf ("on pad gps lat %f lon %f locked %d nsat %d\n", + data.gps.lat, data.gps.lon, data.gps.locked ? 1 : 0, data.gps.nsat); + if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) { npad++; if (npad > 1) { /* filter pad position */ @@ -159,9 +164,9 @@ public class AltosState { if (height > max_height) max_height = height; if (data.gps != null) { - if (gps == null || !gps.gps_locked || data.gps.gps_locked) + if (gps == null || !gps.locked || data.gps.locked) gps = data.gps; - if (npad > 0 && gps.gps_locked) + if (npad > 0 && gps.locked) from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); } if (npad > 0) { diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index f495be1d..af29b8c0 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -76,7 +76,7 @@ public class AltosTelemetry extends AltosRecord { status = AltosParse.parse_hex(words[i++]); AltosParse.word(words[i++], "STATE"); - state = words[i++]; + state = Altos.state(words[i++]); tick = AltosParse.parse_int(words[i++]); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 40663882..2cb0c479 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -173,7 +173,7 @@ public class AltosUI extends JFrame { else info_add_row(0, "Ground state", "wait (%d)", state.gps_waiting); - info_add_row(0, "Rocket state", "%s", state.data.state); + info_add_row(0, "Rocket state", "%s", state.data.state()); info_add_row(0, "Callsign", "%s", state.data.callsign); info_add_row(0, "Rocket serial", "%6d", state.data.serial); info_add_row(0, "Rocket flight", "%6d", state.data.flight); @@ -193,9 +193,9 @@ public class AltosUI extends JFrame { if (state.gps == null) { info_add_row(1, "GPS", "not available"); } else { - if (state.data.gps.gps_locked) + if (state.data.gps.locked) info_add_row(1, "GPS", " locked"); - else if (state.data.gps.gps_connected) + else if (state.data.gps.connected) info_add_row(1, "GPS", " unlocked"); else info_add_row(1, "GPS", " missing"); @@ -321,7 +321,7 @@ public class AltosUI extends JFrame { private void tell(AltosState state, AltosState old_state) { if (old_state == null || old_state.state != state.state) { - voice.speak(state.data.state); + voice.speak(state.data.state()); if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && state.state > Altos.ao_flight_boost) { voice.speak("max speed: %d meters per second.", @@ -493,7 +493,23 @@ public class AltosUI extends JFrame { class ReplayEepromThread extends DisplayThread { FileInputStream replay; - AltosRecord read () { + AltosEepromReader reader; + + ReplayEepromThread(FileInputStream in, String in_name) { + replay = in; + name = in_name; + reader = new AltosEepromReader (in); + } + + AltosRecord read () throws ParseException { + try { + return reader.read(); + } catch (IOException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + name, + "error reading", + JOptionPane.ERROR_MESSAGE); + } return null; } @@ -504,10 +520,10 @@ public class AltosUI extends JFrame { } report(); } - - ReplayEepromThread(FileInputStream in, String in_name) { - replay = in; - name = in_name; + void update(AltosState state) throws InterruptedException { + /* Make it run in realtime after the rocket leaves the pad */ + if (state.state > Altos.ao_flight_pad) + Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); } } -- cgit v1.2.3 From b7699a5907e64bc7547fcc27e73f4a35bbaabfff Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 6 Aug 2010 13:09:21 -0400 Subject: altosui: Add comments to Eeprom reader --- ao-tools/altosui/AltosEepromReader.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 7a8ff5b0..9b928abb 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -36,6 +36,10 @@ import altosui.AltosLog; import altosui.AltosVoice; import altosui.AltosEepromMonitor; +/* + * 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 { int index; @@ -217,6 +221,13 @@ public class AltosEepromReader { } } + /* + * 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 AltosEepromReader (FileInputStream in_input) { state = new AltosRecord(); state.state = Altos.ao_flight_pad; -- cgit v1.2.3 From f317f1324b69b4241f4bb192e164b33d712d5a43 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 7 Aug 2010 00:42:25 -0400 Subject: altosui: Start adding code to write csv files from eeprom/telem files This is a start to code which can write out a csv file full of flight data from either an eeprom or telem input file. It's not hooked up, but the restructuring necessary is finished and the output is started. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 115 +++++++++++++++++++++++++++++ ao-tools/altosui/AltosEepromReader.java | 68 +++++++++++++++-- ao-tools/altosui/AltosReader.java | 28 +++++++ ao-tools/altosui/AltosRecord.java | 2 + ao-tools/altosui/AltosTelemetryReader.java | 71 ++++++++++++++++++ ao-tools/altosui/AltosUI.java | 81 ++++++-------------- ao-tools/altosui/Makefile | 2 + 7 files changed, 301 insertions(+), 66 deletions(-) create mode 100644 ao-tools/altosui/AltosCSV.java create mode 100644 ao-tools/altosui/AltosReader.java create mode 100644 ao-tools/altosui/AltosTelemetryReader.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java new file mode 100644 index 00000000..24936758 --- /dev/null +++ b/ao-tools/altosui/AltosCSV.java @@ -0,0 +1,115 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import altosui.AltosRecord; + +public class AltosCSV { + File name; + PrintStream out; + boolean header_written; + + static final int ALTOS_CSV_VERSION = 1; + + /* Version 1 format: + * + * General info + * version number + * serial number + * flight number + * callsign + * time (seconds since boost) + * + * Flight status + * state + * state name + * + * Basic sensors + * acceleration (m/s²) + * pressure (mBar) + * altitude (m) + * accelerometer speed (m/s) + * barometer speed (m/s) + * temp (°C) + * battery (V) + * drogue (V) + * main (V) + * + * GPS data + * connected (1/0) + * locked (1/0) + * nsat (used for solution) + * latitude (°) + * longitude (°) + * altitude (m) + * year (e.g. 2010) + * month (1-12) + * day (1-31) + * hour (0-23) + * minute (0-59) + * second (0-59) + * + * GPS Sat data + * hdop + * C/N0 data for all 32 valid SDIDs + */ + + void write_general_header() { + out.printf("version serial flight call time"); + } + + void write_general(AltosRecord record) { + out.printf("%s,%d,%d,%s,%d", + record.version, record.serial, record.flight, record.callsign, record.tick); + } + + void write_flight_header() { + out.printf("state state_name"); + } + + void write_flight(AltosRecord record) { + out.printf("%d,%s", record.state, record.state()); + } + + void write_header() { + out.printf("# "); write_general_header(); + out.printf(" "); write_flight_header(); + out.printf ("\n"); + } + + public void write(AltosRecord record) { + if (!header_written) { + write_header(); + header_written = true; + } + write_general(record); out.printf(","); + write_flight(record); + out.printf ("\n"); + } + + public PrintStream out() { + return out; + } + + public AltosCSV(File in_name) throws FileNotFoundException { + name = in_name; + out = new PrintStream(name); + } +} diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 9b928abb..c29fd90b 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -64,7 +64,7 @@ class AltosOrderedRecord extends AltosEepromRecord implements Comparable iterator = records.iterator(); + while (iterator.hasNext()) { + AltosOrderedRecord record = iterator.next(); + switch (record.cmd) { + case Altos.AO_LOG_CONFIG_VERSION: + out.printf("# Config version: %s\n", record.data); + break; + case Altos.AO_LOG_MAIN_DEPLOY: + out.printf("# Main deploy: %s\n", record.a); + break; + case Altos.AO_LOG_APOGEE_DELAY: + out.printf("# Apogee delay: %s\n", record.a); + break; + case Altos.AO_LOG_RADIO_CHANNEL: + out.printf("# Radio channel: %s\n", record.a); + break; + case Altos.AO_LOG_CALLSIGN: + out.printf("# Callsign: %s\n", record.data); + break; + case Altos.AO_LOG_ACCEL_CAL: + out.printf ("# Accel cal: %d %d\n", record.a, record.b); + break; + case Altos.AO_LOG_RADIO_CAL: + out.printf ("# Radio cal: %d %d\n", record.a); + break; + case Altos.AO_LOG_MANUFACTURER: + out.printf ("# Manufacturer: %s\n", record.data); + break; + case Altos.AO_LOG_PRODUCT: + out.printf ("# Product: %s\n", record.data); + break; + case Altos.AO_LOG_SERIAL_NUMBER: + out.printf ("# Serial number: %d\n", record.a); + break; + case Altos.AO_LOG_SOFTWARE_VERSION: + out.printf ("# Software version: %s\n", record.data); + break; + } + } + } + /* * Read the whole file, dumping records into a RB tree so * we can enumerate them in time order -- the eeprom data @@ -228,12 +275,11 @@ public class AltosEepromReader { * matching the first packet out of the GPS unit but not * written until the final GPS packet has been received. */ - public AltosEepromReader (FileInputStream in_input) { + public AltosEepromReader (FileInputStream input) { state = new AltosRecord(); state.state = Altos.ao_flight_pad; state.accel_plus_g = 15758; state.accel_minus_g = 16294; - input = in_input; seen = 0; records = new TreeSet(); @@ -249,11 +295,21 @@ public class AltosEepromReader { if (record == null) break; tick = record.tick; + if (!saw_boost && record.cmd == Altos.AO_LOG_STATE && + record.a == Altos.ao_flight_boost) + { + saw_boost = true; + boost_tick = state.tick; + } records.add(record); } } catch (IOException io) { } catch (ParseException pe) { } record_iterator = records.iterator(); + try { + input.close(); + } catch (IOException ie) { + } } } diff --git a/ao-tools/altosui/AltosReader.java b/ao-tools/altosui/AltosReader.java new file mode 100644 index 00000000..81779e2b --- /dev/null +++ b/ao-tools/altosui/AltosReader.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.io.*; +import java.util.*; +import java.text.*; + +import altosui.AltosRecord; + +public class AltosReader { + public AltosRecord read() throws IOException, ParseException { return null; } +} diff --git a/ao-tools/altosui/AltosRecord.java b/ao-tools/altosui/AltosRecord.java index 3440d935..b670ee37 100644 --- a/ao-tools/altosui/AltosRecord.java +++ b/ao-tools/altosui/AltosRecord.java @@ -48,6 +48,8 @@ public class AltosRecord { int accel_minus_g; AltosGPS gps; + double time; /* seconds since boost */ + /* * Values for our MP3H6115A pressure sensor * diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java new file mode 100644 index 00000000..f1f6788c --- /dev/null +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -0,0 +1,71 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.io.*; +import java.util.*; +import java.text.*; +import altosui.AltosTelemetry; + +public class AltosTelemetryReader extends AltosReader { + LinkedList records; + + Iterator record_iterator; + + int boost_tick; + + public AltosRecord read() throws IOException, ParseException { + AltosRecord r; + if (!record_iterator.hasNext()) + return null; + + r = record_iterator.next(); + r.time = (r.tick - boost_tick) / 100.0; + return r; + } + + public AltosTelemetryReader (FileInputStream input) { + boolean saw_boost = false; + + records = new LinkedList (); + + try { + for (;;) { + String line = AltosRecord.gets(input); + if (line == null) + break; + AltosTelemetry record = new AltosTelemetry(line); + if (record == null) + break; + if (!saw_boost && record.state >= Altos.ao_flight_boost) + { + saw_boost = true; + boost_tick = record.tick; + } + records.add(record); + } + } catch (IOException io) { + } catch (ParseException pe) { + } + record_iterator = records.iterator(); + try { + input.close(); + } catch (IOException ie) { + } + } +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 2cb0c479..7d5ac93a 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -391,21 +391,12 @@ public class AltosUI extends JFrame { } } - class TelemetryThread extends DisplayThread { - - String readline() throws InterruptedException { return null; } - - AltosRecord read() throws InterruptedException, ParseException { - return new AltosTelemetry(readline()); - } - } - - class DeviceThread extends TelemetryThread { + class DeviceThread extends DisplayThread { AltosSerial serial; LinkedBlockingQueue telem; - String readline() throws InterruptedException { - return telem.take(); + AltosRecord read() throws InterruptedException, ParseException { + return new AltosTelemetry(telem.take()); } void close() { @@ -453,36 +444,30 @@ public class AltosUI extends JFrame { * Open an existing telemetry file and replay it in realtime */ - class ReplayTelemetryThread extends TelemetryThread { - FileInputStream replay; - - ReplayTelemetryThread(FileInputStream in, String in_name) { - replay = in; - name = in_name; - } + class ReplayThread extends DisplayThread { + AltosReader reader; + String name; - String readline() { + public AltosRecord read() { try { - String line = AltosRecord.gets(replay); - System.out.printf("telemetry line %s\n", line); - return line; - } catch (IOException ee) { + return reader.read(); + } catch (IOException ie) { JOptionPane.showMessageDialog(AltosUI.this, name, "error reading", JOptionPane.ERROR_MESSAGE); + } catch (ParseException pe) { } return null; } - void close () { - try { - replay.close(); - } catch (IOException ee) { - } + public void close () { report(); } + public ReplayThread(AltosReader in_reader, String in_name) { + reader = in_reader; + } void update(AltosState state) throws InterruptedException { /* Make it run in realtime after the rocket leaves the pad */ if (state.state > Altos.ao_flight_pad) @@ -490,40 +475,16 @@ public class AltosUI extends JFrame { } } - class ReplayEepromThread extends DisplayThread { - FileInputStream replay; - - AltosEepromReader reader; - - ReplayEepromThread(FileInputStream in, String in_name) { - replay = in; - name = in_name; - reader = new AltosEepromReader (in); + class ReplayTelemetryThread extends ReplayThread { + ReplayTelemetryThread(FileInputStream in, String in_name) { + super(new AltosTelemetryReader(in), in_name); } - AltosRecord read () throws ParseException { - try { - return reader.read(); - } catch (IOException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - name, - "error reading", - JOptionPane.ERROR_MESSAGE); - } - return null; - } + } - void close () { - try { - replay.close(); - } catch (IOException ee) { - } - report(); - } - void update(AltosState state) throws InterruptedException { - /* Make it run in realtime after the rocket leaves the pad */ - if (state.state > Altos.ao_flight_pad) - Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); + class ReplayEepromThread extends ReplayThread { + ReplayEepromThread(FileInputStream in, String in_name) { + super(new AltosEepromReader(in), in_name); } } diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 3f55db0b..8c9e9642 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -4,6 +4,7 @@ CLASSPATH=classes:./* CLASSFILES=\ Altos.class \ AltosConvert.class \ + AltosCSV.class \ AltosEepromDownload.class \ AltosEepromMonitor.class \ AltosEepromReader.class \ @@ -21,6 +22,7 @@ CLASSFILES=\ AltosSerial.class \ AltosState.class \ AltosTelemetry.class \ + AltosTelemetryReader.class \ AltosUI.class \ AltosDevice.class \ AltosDeviceDialog.class \ -- cgit v1.2.3 From 294d9c7db21eaf1e71504dbcca5040371abcce55 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 7 Aug 2010 22:30:55 -0400 Subject: ao-dumplog: add --channel option (for use with -R option) Sets the channel when downloading data with the -R option. Signed-off-by: Keith Packard --- ao-tools/ao-dumplog/ao-dumplog.c | 9 +++++++-- ao-tools/lib/cc-usb.c | 5 +++-- ao-tools/lib/cc-usb.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c index 440a02b5..57c43290 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.c +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -30,12 +30,13 @@ static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, { .name = "remote", .has_arg = 1, .val = 'R' }, + { .name = "channel", .has_arg = 1, .val = 'C' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty ] [--device ] [-R]\n", program); + fprintf(stderr, "usage: %s [--tty ] [--device ] [--remote] [--channel ]\n", program); exit(1); } @@ -75,6 +76,7 @@ main (int argc, char **argv) FILE *out; char *filename; int serial_number = 0; + int channel = 0; int flight = 0; char cmd; int tick, a, b; @@ -100,6 +102,9 @@ main (int argc, char **argv) case 'R': remote = 1; break; + case 'C': + channel = atoi(optarg); + break; default: usage(argv[0]); break; @@ -119,7 +124,7 @@ main (int argc, char **argv) if (!cc) exit(1); if (remote) - cc_usb_open_remote(cc); + cc_usb_open_remote(cc, channel); /* send a 'version' command followed by a 'log' command */ cc_usb_printf(cc, "v\n"); out = NULL; diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index 53a50741..1580c6d9 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -375,10 +375,11 @@ cc_usb_reset(struct cc_usb *cc) } void -cc_usb_open_remote(struct cc_usb *cc) +cc_usb_open_remote(struct cc_usb *cc, int channel) { if (!cc->remote) { - cc_usb_printf(cc, "\np\nE 0\n"); + printf ("channel %d\n", channel); + cc_usb_printf(cc, "\nc r %d\np\nE 0\n", channel); do { cc->in_count = cc->in_pos = 0; _cc_usb_sync(cc, 100); diff --git a/ao-tools/lib/cc-usb.h b/ao-tools/lib/cc-usb.h index 627f1b5d..d3539281 100644 --- a/ao-tools/lib/cc-usb.h +++ b/ao-tools/lib/cc-usb.h @@ -63,7 +63,7 @@ void cc_usb_printf(struct cc_usb *cc, char *format, ...); void -cc_usb_open_remote(struct cc_usb *cc); +cc_usb_open_remote(struct cc_usb *cc, int channel); void cc_usb_close_remote(struct cc_usb *cc); -- cgit v1.2.3 From d14c96663a1027164fa30ed89b53f5a9d3fdb82b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 17 Aug 2010 18:19:43 -0700 Subject: libaltos: integrate Windows support. This adds Windows support for discovery and I/O. The API to the library is mostly unchanged, except that it now exports product and vendor USB IDs as Win7 doesn't expose the product name anywhere that we've been able to find, so we'll be updating the firmware to use unique idProduct values for each product. Signed-off-by: Keith Packard --- ao-tools/libaltos/Makefile | 53 ++++- ao-tools/libaltos/cjnitest.c | 21 +- ao-tools/libaltos/libaltos.c | 501 +++++++++++++++++++++++-------------------- ao-tools/libaltos/libaltos.h | 68 ++++-- 4 files changed, 383 insertions(+), 260 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index fa5127eb..a251e54e 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -1,27 +1,56 @@ OS:=$(shell uname) +# +# Linux +# ifeq ($(OS),Linux) JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include OS_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) -LIBEXT=so +OS_LDFLAGS= + +LIBNAME=libaltos.so +EXEEXT= endif +# +# Darwin (Mac OS X) +# ifeq ($(OS),Darwin) -DARWIN_CFLAGS=\ +OS_CFLAGS=\ + -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers -DARWIN_LIBS=\ + +OS_LDFLAGS =\ -framework IOKit -framework CoreFoundation -OS_CFLAGS = $(DARWIN_CFLAGS) -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 -LIBEXT=dylib +LIBNAME=libaltos.dylib +EXEEXT= + +endif + +# +# Windows +# +ifneq (,$(findstring MINGW,$(OS))) + +CC=gcc + +OS_CFLAGS = -DWINDOWS -mconsole + +OS_LDFLAGS = -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lole32 \ + -ladvapi32 -lcomctl32 -mconsole -Wl,--add-stdcall-alias + +LIBNAME=altos.dll + +EXEEXT=.exe endif @@ -48,26 +77,30 @@ CLASSFILES = $(JAVAFILES:%.java=%.class) JAVAFLAGS=-Xlint:unchecked -all: libaltos.$(LIBEXT) cjnitest $(CLASSFILES) +CJNITEST=cjnitest$(EXEEXT) + +all: $(LIBNAME) $(CJNITEST) $(CLASSFILES) .java.class: javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java CFLAGS=$(OS_CFLAGS) -O0 -g -I. +LDFLAGS=$(OS_LDFLAGS) + HEADERS=libaltos.h SRCS = libaltos.c $(SWIG_WRAP) OBJS = $(SRCS:%.c=%.o) LIBS = $(DARWIN_LIBS) -cjnitest: cjnitest.o $(OBJS) +$(CJNITEST): cjnitest.o $(OBJS) cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBS) -libaltos.$(LIBEXT): $(OBJS) - gcc -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) +$(LIBNAME): $(OBJS) + gcc -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) clean: - rm -f $(CLASSFILES) $(OBJS) libaltos.$(LIBEXT) cjnitest cjnitest.o + rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o rm -rf swig_bindings libaltosJNI $(JNI_FILE): libaltos.i0 $(HEADERS) diff --git a/ao-tools/libaltos/cjnitest.c b/ao-tools/libaltos/cjnitest.c index cd3898ed..93d1f376 100644 --- a/ao-tools/libaltos/cjnitest.c +++ b/ao-tools/libaltos/cjnitest.c @@ -1,6 +1,15 @@ #include #include "libaltos.h" +static void +altos_puts(struct altos_file *file, char *string) +{ + char c; + + while ((c = *string++)) + altos_putchar(file, c); +} + main () { struct altos_device device; @@ -12,12 +21,20 @@ main () struct altos_file *file; int c; + printf ("%04x:%04x %-20s %4d %s\n", device.vendor, device.product, + device.name, device.serial, device.path); + file = altos_open(&device); - altos_putchar(file, '?'); altos_putchar(file, '\n'); altos_flush(file); + if (!file) { + printf("altos_open failed\n"); + continue; + } + altos_puts(file,"v\nc s\n"); while ((c = altos_getchar(file, 100)) >= 0) { putchar (c); } - printf ("getchar returns %d\n", c); + if (c != LIBALTOS_TIMEOUT) + printf ("getchar returns %d\n", c); altos_close(file); } altos_list_finish(list); diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 00fb2125..3e8485e4 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -15,29 +15,21 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#define BUILD_DLL #include "libaltos.h" #include #include #include -static int -match_dev(char *product, int serial, struct altos_device *device) +PUBLIC int +altos_init(void) { - struct altos_list *list; - int i; + return LIBALTOS_SUCCESS; +} - list = altos_list_start(); - if (!list) - return 0; - while ((i = altos_list_next(list, device)) != 0) { - if (product && strncmp (product, device->product, strlen(product)) != 0) - continue; - if (serial && serial != device->serial) - continue; - break; - } - altos_list_finish(list); - return i; +PUBLIC void +altos_fini(void) +{ } #ifdef DARWIN @@ -60,48 +52,9 @@ altos_strndup (const char *s, size_t n) #define altos_strndup strndup #endif -int -altos_find_by_arg(char *arg, char *default_product, struct altos_device *device) -{ - char *product; - int serial; - char *end; - char *colon; - int ret; - - if (arg) - { - /* check for */ - serial = strtol(arg, &end, 0); - if (end != arg) { - if (*end != '\0') - return 0; - product = NULL; - } else { - /* check for : */ - colon = strchr(arg, ':'); - if (colon) { - product = altos_strndup(arg, colon - arg); - serial = strtol(colon + 1, &end, 0); - if (*end != '\0') - return 0; - } else { - product = arg; - serial = 0; - } - } - } else { - product = NULL; - serial = 0; - } - if (!product && default_product) - ret = match_dev(default_product, serial, device); - if (!ret) - ret = match_dev(product, serial, device); - if (product && product != arg) - free(product); - return ret; -} +/* + * Scan for Altus Metrum devices by looking through /sys + */ #ifdef LINUX @@ -216,7 +169,7 @@ struct altos_usbdev { char *sys; char *tty; char *manufacturer; - char *product; + char *product_name; int serial; /* AltOS always uses simple integer serial numbers */ int idProduct; int idVendor; @@ -286,7 +239,7 @@ usb_scan_device(char *sys) return NULL; usbdev->sys = strdup(sys); usbdev->manufacturer = load_string(sys, "manufacturer"); - usbdev->product = load_string(sys, "product"); + usbdev->product_name = load_string(sys, "product"); usbdev->serial = load_dec(sys, "serial"); usbdev->idProduct = load_hex(sys, "idProduct"); usbdev->idVendor = load_hex(sys, "idVendor"); @@ -299,7 +252,7 @@ usbdev_free(struct altos_usbdev *usbdev) { free(usbdev->sys); free(usbdev->manufacturer); - free(usbdev->product); + free(usbdev->product_name); /* this can get used as a return value */ if (usbdev->tty) free(usbdev->tty); @@ -332,17 +285,6 @@ struct altos_list { int ndev; }; -int -altos_init(void) -{ - return 1; -} - -void -altos_fini(void) -{ -} - struct altos_list * altos_list_start(void) { @@ -366,7 +308,7 @@ altos_list_start(void) dir = cc_fullname(USB_DEVICES, ents[e]->d_name); dev = usb_scan_device(dir); free(dir); - if (dev->idVendor == 0xfffe && dev->tty) { + if (USB_IS_ALTUSMETRUM(dev->idVendor, dev->idProduct)) { if (devs->dev) devs->dev = realloc(devs->dev, devs->ndev + 1 * sizeof (struct usbdev *)); @@ -387,7 +329,9 @@ altos_list_next(struct altos_list *list, struct altos_device *device) if (list->current >= list->ndev) return 0; dev = list->dev[list->current]; - strcpy(device->product, dev->product); + strcpy(device->name, dev->product_name); + device->vendor = dev->idVendor; + device->product = dev->idProduct; strcpy(device->path, dev->tty); device->serial = dev->serial; list->current++; @@ -447,17 +391,6 @@ get_string(io_object_t object, CFStringRef entry, char *result, int result_len) return 0; } -int -altos_init(void) -{ - return 1; -} - -void -altos_fini(void) -{ -} - struct altos_list * altos_list_start(void) { @@ -566,15 +499,16 @@ altos_open(struct altos_device *device) void altos_close(struct altos_file *file) { - close(file->fd); - file->fd = -1; + if (file->fd != -1) { + close(file->fd); + file->fd = -1; + } } void altos_free(struct altos_file *file) { - if (file->fd != -1) - close(file->fd); + altos_close(file); free(file); } @@ -613,6 +547,8 @@ altos_flush(struct altos_file *file) } } +#include + int altos_getchar(struct altos_file *file, int timeout) { @@ -622,9 +558,18 @@ altos_getchar(struct altos_file *file, int timeout) altos_flush(file); if (file->fd < 0) return -EBADF; + if (timeout) { + struct pollfd fd; + int ret; + fd.fd = file->fd; + fd.events = POLLIN; + ret = poll(&fd, 1, timeout); + if (ret == 0) + return LIBALTOS_TIMEOUT; + } ret = read(file->fd, file->in_data, USB_BUF_SIZE); if (ret < 0) - return -errno; + return LIBALTOS_ERROR; file->in_read = 0; file->in_used = ret; } @@ -633,143 +578,255 @@ altos_getchar(struct altos_file *file, int timeout) #endif /* POSIX_TTY */ -#ifdef USE_LIBUSB -#include -#include -#include -#include +#ifdef WINDOWS -libusb_context *usb_context; +#include +#include -int altos_init(void) -{ - int ret; - ret = libusb_init(&usb_context); - if (ret) - return ret; - libusb_set_debug(usb_context, 3); - return 0; -} +struct altos_list { + HDEVINFO dev_info; + int index; +}; -void altos_fini(void) -{ - libusb_exit(usb_context); - usb_context = NULL; -} +#define USB_BUF_SIZE 64 -static libusb_device **list; -static ssize_t num, current; +struct altos_file { + HANDLE handle; + unsigned char out_data[USB_BUF_SIZE]; + int out_used; + unsigned char in_data[USB_BUF_SIZE]; + int in_used; + int in_read; +}; -int altos_list_start(void) + +PUBLIC struct altos_list * +altos_list_start(void) { - if (list) - altos_list_finish(); - current = 0; - num = libusb_get_device_list(usb_context, &list); - if (num == 0) { - current = num = 0; - list = NULL; - return 0; + struct altos_list *list = calloc(1, sizeof (struct altos_list)); + + if (!list) + return NULL; + list->dev_info = SetupDiGetClassDevs(NULL, "USB", NULL, + DIGCF_ALLCLASSES|DIGCF_PRESENT); + if (list->dev_info == INVALID_HANDLE_VALUE) { + printf("SetupDiGetClassDevs failed %d\n", GetLastError()); + free(list); + return NULL; } - return 1; + list->index = 0; + return list; } -int altos_list_next(struct altos_device *device) -{ - while (current < num) { - struct libusb_device_descriptor descriptor; - libusb_device *usb_device = list[current++]; - - if (libusb_get_device_descriptor(usb_device, &descriptor) == 0) { - if (descriptor.idVendor == 0xfffe) - { - libusb_device_handle *handle; - if (libusb_open(usb_device, &handle) == 0) { - char serial_number[256]; - libusb_get_string_descriptor_ascii(handle, descriptor.iProduct, - device->product, - sizeof(device->product)); - libusb_get_string_descriptor_ascii(handle, descriptor.iSerialNumber, - serial_number, - sizeof (serial_number)); - libusb_close(handle); - device->serial = atoi(serial_number); - device->device = usb_device; - return 1; - } - } +PUBLIC int +altos_list_next(struct altos_list *list, struct altos_device *device) +{ + SP_DEVINFO_DATA dev_info_data; + char port[128]; + DWORD port_len; + char location[256]; + char symbolic[256]; + DWORD symbolic_len; + HKEY dev_key; + int vid, pid; + int serial; + HRESULT result; + DWORD location_type; + DWORD location_len; + + dev_info_data.cbSize = sizeof (SP_DEVINFO_DATA); + while(SetupDiEnumDeviceInfo(list->dev_info, list->index, + &dev_info_data)) + { + list->index++; + + dev_key = SetupDiOpenDevRegKey(list->dev_info, &dev_info_data, + DICS_FLAG_GLOBAL, 0, DIREG_DEV, + KEY_READ); + if (dev_key == INVALID_HANDLE_VALUE) { + printf("cannot open device registry key\n"); + continue; } + + /* Fetch symbolic name for this device and parse out + * the vid/pid/serial info */ + symbolic_len = sizeof(symbolic); + result = RegQueryValueEx(dev_key, "SymbolicName", NULL, NULL, + symbolic, &symbolic_len); + if (result != 0) { + printf("cannot find SymbolicName value\n"); + RegCloseKey(dev_key); + continue; + } + vid = pid = serial = 0; + sscanf(symbolic + sizeof("\\??\\USB#VID_") - 1, + "%04X", &vid); + sscanf(symbolic + sizeof("\\??\\USB#VID_XXXX&PID_") - 1, + "%04X", &pid); + sscanf(symbolic + sizeof("\\??\\USB#VID_XXXX&PID_XXXX#") - 1, + "%d", &serial); + if (!USB_IS_ALTUSMETRUM(vid, pid)) { + printf("Not Altus Metrum symbolic name: %s\n", + symbolic); + RegCloseKey(dev_key); + continue; + } + + /* Fetch the com port name */ + port_len = sizeof (port); + result = RegQueryValueEx(dev_key, "PortName", NULL, NULL, + port, &port_len); + RegCloseKey(dev_key); + if (result != 0) { + printf("failed to get PortName\n"); + continue; + } + + /* Fetch the 'location information' which is the device name, + * at least on XP */ + location_len = sizeof (location); + if(!SetupDiGetDeviceRegistryProperty(list->dev_info, + &dev_info_data, + SPDRP_LOCATION_INFORMATION, + &location_type, + (BYTE *)location, + sizeof(location), + &location_len)) + { + printf("Failed to get location\n"); + continue; + } + device->vendor = vid; + device->product = pid; + device->serial = serial; + + if (strcasestr(location, "tele")) + strcpy(device->name, location); + else + strcpy(device->name, ""); + + strcpy(device->path, port); + printf ("product: %04x:%04x (%s) path: %s serial %d\n", + device->vendor, device->product, device->name, + device->path, device->serial); + return 1; } + result = GetLastError(); + if (result != ERROR_NO_MORE_ITEMS) + printf ("SetupDiEnumDeviceInfo failed error %d\n", result); return 0; } -void altos_list_finish(void) +PUBLIC void +altos_list_finish(struct altos_list *list) +{ + SetupDiDestroyDeviceInfoList(list->dev_info); + free(list); +} + +static int +altos_fill(struct altos_file *file, int timeout) { - if (list) { - libusb_free_device_list(list, 1); - list = NULL; + DWORD result; + DWORD got; + COMMTIMEOUTS timeouts; + + if (file->in_read < file->in_used) + return LIBALTOS_SUCCESS; + file->in_read = file->in_used = 0; + + if (timeout) { + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; + timeouts.ReadTotalTimeoutConstant = timeout; + } else { + timeouts.ReadIntervalTimeout = 0; + timeouts.ReadTotalTimeoutMultiplier = 0; + timeouts.ReadTotalTimeoutConstant = 0; + } + timeouts.WriteTotalTimeoutMultiplier = 0; + timeouts.WriteTotalTimeoutConstant = 0; + + if (!SetCommTimeouts(file->handle, &timeouts)) { + printf("SetCommTimeouts failed %d\n", GetLastError()); } + + if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, NULL)) { + result = GetLastError(); + printf ("read failed %d\n", result); + return LIBALTOS_ERROR; + got = 0; + } + if (got) + return LIBALTOS_SUCCESS; + return LIBALTOS_TIMEOUT; } -#define USB_BUF_SIZE 64 +PUBLIC int +altos_flush(struct altos_file *file) +{ + DWORD put; + char *data = file->out_data; + char used = file->out_used; + DWORD result; -struct altos_file { - struct libusb_device *device; - struct libusb_device_handle *handle; - int out_ep; - int out_size; - int in_ep; - int in_size; - unsigned char out_data[USB_BUF_SIZE]; - int out_used; - unsigned char in_data[USB_BUF_SIZE]; - int in_used; - int in_read; -}; + while (used) { + if (!WriteFile(file->handle, data, used, &put, NULL)) { + result = GetLastError(); + printf ("write failed %d\n", result); + return LIBALTOS_ERROR; + } + data += put; + used -= put; + } + file->out_used = 0; + return LIBALTOS_SUCCESS; +} -struct altos_file * +PUBLIC struct altos_file * altos_open(struct altos_device *device) { - struct altos_file *file; - struct libusb_device_handle *handle; - if (libusb_open(device->device, &handle) == 0) { - int ret; + struct altos_file *file = calloc (sizeof (struct altos_file), 1); + char full_name[64]; - ret = libusb_claim_interface(handle, 1); -#if 0 - if (ret) { - libusb_close(handle); - return NULL; - } -#endif - ret = libusb_detach_kernel_driver(handle, 1); -#if 0 - if (ret) { - libusb_close(handle); - return NULL; - } -#endif + if (!file) + return NULL; - file = calloc(sizeof (struct altos_file), 1); - file->device = libusb_ref_device(device->device); - file->handle = handle; - /* XXX should get these from the endpoint descriptors */ - file->out_ep = 4 | LIBUSB_ENDPOINT_OUT; - file->out_size = 64; - file->in_ep = 5 | LIBUSB_ENDPOINT_IN; - file->in_size = 64; + strcpy(full_name, "\\\\.\\"); + strcat(full_name, device->path); + file->handle = CreateFile(full_name, GENERIC_READ|GENERIC_WRITE, + 0, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + if (file->handle == INVALID_HANDLE_VALUE) { + free(file); + return NULL; + } - return file; + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; + timeouts.ReadTotalTimeoutConstant = 100; + timeouts.WriteTotalTimeoutMultiplier = 0; + timeouts.WriteTotalTimeoutConstant = 10000; + if (!SetCommTimeouts(file->handle, &timeouts)) { + printf("SetCommTimeouts failed %d\n", GetLastError()); } - return NULL; + + return file; } -void +PUBLIC void altos_close(struct altos_file *file) { - libusb_close(file->handle); - libusb_unref_device(file->device); - file->handle = NULL; + if (file->handle != INVALID_HANDLE_VALUE) { + CloseHandle(file->handle); + file->handle = INVALID_HANDLE_VALUE; + } +} + +PUBLIC void +altos_free(struct altos_file *file) +{ + altos_close(file); free(file); } @@ -778,60 +835,32 @@ altos_putchar(struct altos_file *file, char c) { int ret; - if (file->out_used == file->out_size) { + if (file->out_used == USB_BUF_SIZE) { ret = altos_flush(file); if (ret) return ret; } file->out_data[file->out_used++] = c; - if (file->out_used == file->out_size) + if (file->out_used == USB_BUF_SIZE) return altos_flush(file); - return 0; -} - -int -altos_flush(struct altos_file *file) -{ - while (file->out_used) { - int transferred; - int ret; - - ret = libusb_bulk_transfer(file->handle, - file->out_ep, - file->out_data, - file->out_used, - &transferred, - 0); - if (ret) - return ret; - if (transferred) { - memmove(file->out_data, file->out_data + transferred, - file->out_used - transferred); - file->out_used -= transferred; - } - } + return LIBALTOS_SUCCESS; } int altos_getchar(struct altos_file *file, int timeout) { + int ret; while (file->in_read == file->in_used) { - int ret; - int transferred; - - altos_flush(file); - ret = libusb_bulk_transfer(file->handle, - file->in_ep, - file->in_data, - file->in_size, - &transferred, - (unsigned int) timeout); + ret = altos_flush(file); + if (ret) + return ret; + if (file->handle == INVALID_HANDLE_VALUE) + return LIBALTOS_ERROR; + ret = altos_fill(file, timeout); if (ret) return ret; - file->in_read = 0; - file->in_used = transferred; } return file->in_data[file->in_read++]; } -#endif /* USE_LIBUSB */ +#endif diff --git a/ao-tools/libaltos/libaltos.h b/ao-tools/libaltos/libaltos.h index 53026e0a..fe2c483c 100644 --- a/ao-tools/libaltos/libaltos.h +++ b/ao-tools/libaltos/libaltos.h @@ -18,39 +18,83 @@ #ifndef _LIBALTOS_H_ #define _LIBALTOS_H_ +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# ifndef BUILD_STATIC +# ifdef BUILD_DLL +# define PUBLIC __declspec(dllexport) +# else +# define PUBLIC __declspec(dllimport) +# endif +# endif /* BUILD_STATIC */ +#endif + +#ifndef PUBLIC +# define PUBLIC +#endif + +#define USB_VENDOR_FSF 0xfffe +#define USB_VENDOR_ALTUSMETRUM USB_VENDOR_FSF +#define USB_PRODUCT_ALTUSMETRUM 0x000a +#define USB_PRODUCT_TELEMETRUM 0x000b +#define USB_PRODUCT_TELEDONGLE 0x000c +#define USB_PRODUCT_TELETERRA 0x000d +#define USB_PRODUCT_ALTUSMETRUM_MIN 0x000a +#define USB_PRODUCT_ALTUSMETRUM_MAX 0x0013 + +#define USB_IS_ALTUSMETRUM(v,p) ((v) == USB_VENDOR_ALTUSMETRUM && \ + (USB_PRODUCT_ALTUSMETRUM_MIN <= (p) && \ + (p) <= USB_PRODUCT_ALTUSMETRUM_MAX)) + struct altos_device { //%immutable; - char product[256]; + int vendor; + int product; int serial; + char name[256]; char path[256]; //%mutable; }; -int altos_init(void); +#define LIBALTOS_SUCCESS 0 +#define LIBALTOS_ERROR -1 +#define LIBALTOS_TIMEOUT -2 + +/* Returns 0 for success, < 0 on error */ +PUBLIC int +altos_init(void); -void altos_fini(void); +PUBLIC void +altos_fini(void); -struct altos_list * +PUBLIC struct altos_list * altos_list_start(void); -int altos_list_next(struct altos_list *list, struct altos_device *device); +/* Returns 1 for success, zero on end of list */ +PUBLIC int +altos_list_next(struct altos_list *list, struct altos_device *device); -void altos_list_finish(struct altos_list *list); +PUBLIC void +altos_list_finish(struct altos_list *list); -struct altos_file * +PUBLIC struct altos_file * altos_open(struct altos_device *device); -void altos_close(struct altos_file *file); +PUBLIC void +altos_close(struct altos_file *file); -void altos_free(struct altos_file *file); +PUBLIC void +altos_free(struct altos_file *file); -int +/* Returns < 0 for error */ +PUBLIC int altos_putchar(struct altos_file *file, char c); -int +/* Returns < 0 for error */ +PUBLIC int altos_flush(struct altos_file *file); -int +/* Returns < 0 for error or timeout. timeout of 0 == wait forever */ +PUBLIC int altos_getchar(struct altos_file *file, int timeout); #endif /* _LIBALTOS_H_ */ -- cgit v1.2.3 From 22800dc094797e1e0ad99124198809d0360f7556 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 17 Aug 2010 18:22:28 -0700 Subject: altosui: Select devices by USB vendor/product ID. Because Win7 doesn't expose the product name, we're swtiching to using the USB idProduct/idVendor values. This patch adds support for selecting devices by those new IDs. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDevice.java | 72 ++++++++++++++++++++++++++++--- ao-tools/altosui/AltosDeviceDialog.java | 8 ++-- ao-tools/altosui/AltosEepromDownload.java | 7 +-- ao-tools/altosui/AltosUI.java | 2 +- 4 files changed, 75 insertions(+), 14 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index f488174c..3daf0742 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -22,16 +22,76 @@ import libaltosJNI.*; public class AltosDevice extends altos_device { + static boolean initialized = false; + static { + try { + System.loadLibrary("altos"); + libaltos.altos_init(); + initialized = true; + } catch (UnsatisfiedLinkError e) { + System.err.println("Native library failed to load.\n" + e); + } + } + public final static int TeleMetrum = libaltosConstants.USB_PRODUCT_TELEMETRUM; + public final static int TeleDongle = libaltosConstants.USB_PRODUCT_TELEDONGLE; + public final static int TeleTerra = libaltosConstants.USB_PRODUCT_TELETERRA; + public final static int Any = 0x10000; + public final static int BaseStation = 0x10000 + 1; + public String toString() { + String name = getName(); + if (name == null) + name = "Altus Metrum"; return String.format("%-20.20s %4d %s", - getProduct(), getSerial(), getPath()); + getName(), getSerial(), getPath()); } - static { - System.loadLibrary("altos"); - libaltos.altos_init(); + public boolean isAltusMetrum() { + if (getVendor() != libaltosConstants.USB_VENDOR_ALTUSMETRUM) + return false; + if (getProduct() < libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MIN) + return false; + if (getProduct() > libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MAX) + return false; + return true; } - static AltosDevice[] list(String product) { + + public boolean matchProduct(int want_product) { + + if (want_product == Any) + return true; + + if (want_product == BaseStation) + return matchProduct(TeleDongle) || matchProduct(TeleTerra); + + if (!isAltusMetrum()) + return false; + + int have_product = getProduct(); + + if (want_product == have_product) + return true; + + if (have_product != libaltosConstants.USB_PRODUCT_ALTUSMETRUM) + return false; + + String name = getName(); + + if (name == null) + return false; + if (want_product == libaltosConstants.USB_PRODUCT_TELEMETRUM) + return name.startsWith("TeleMetrum"); + if (want_product == libaltosConstants.USB_PRODUCT_TELEDONGLE) + return name.startsWith("TeleDongle"); + if (want_product == libaltosConstants.USB_PRODUCT_TELETERRA) + return name.startsWith("TeleTerra"); + return false; + } + + static AltosDevice[] list(int product) { + if (!initialized) + return null; + SWIGTYPE_p_altos_list list = libaltos.altos_list_start(); ArrayList device_list = new ArrayList(); @@ -42,7 +102,7 @@ public class AltosDevice extends altos_device { AltosDevice device = new AltosDevice(); if (libaltos.altos_list_next(list, device) == 0) break; - if (product == null || device.getProduct().startsWith(product)) + if (device.matchProduct(product)) device_list.add(device); } libaltos.altos_list_finish(list); diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java index c60bd7c3..3df4c6eb 100644 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -31,16 +31,16 @@ import altosui.AltosDevice; public class AltosDeviceDialog extends JDialog implements ActionListener { private static AltosDeviceDialog dialog; - private static altos_device value = null; + private static AltosDevice value = null; private JList list; - public static altos_device show (Component frameComp, String product) { + public static AltosDevice show (Component frameComp, int product) { Frame frame = JOptionPane.getFrameForComponent(frameComp); AltosDevice[] devices; devices = AltosDevice.list(product); - if (devices != null & devices.length > 0) { + if (devices != null && devices.length > 0) { value = null; dialog = new AltosDeviceDialog(frame, frameComp, devices, @@ -153,7 +153,7 @@ public class AltosDeviceDialog extends JDialog implements ActionListener { //Handle clicks on the Set and Cancel buttons. public void actionPerformed(ActionEvent e) { if ("select".equals(e.getActionCommand())) - AltosDeviceDialog.value = (altos_device)(list.getSelectedValue()); + AltosDeviceDialog.value = (AltosDevice)(list.getSelectedValue()); AltosDeviceDialog.dialog.setVisible(false); } diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index f2fcd09e..c2a8d25e 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -84,7 +84,7 @@ public class AltosEepromDownload implements Runnable { } JFrame frame; - altos_device device; + AltosDevice device; AltosSerial serial_line; boolean remote; Thread eeprom_thread; @@ -251,7 +251,7 @@ public class AltosEepromDownload implements Runnable { public AltosEepromDownload(JFrame given_frame) { frame = given_frame; - device = AltosDeviceDialog.show(frame, null); + device = AltosDeviceDialog.show(frame, AltosDevice.Any); serial_line = new AltosSerial(); remote = false; @@ -259,7 +259,8 @@ public class AltosEepromDownload implements Runnable { if (device != null) { try { serial_line.open(device); - if (!device.getProduct().startsWith("TeleMetrum")) + String name = device.getName(); + if (!device.matchProduct(AltosDevice.TeleMetrum)) remote = true; eeprom_thread = new Thread(this); eeprom_thread.start(); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 7d5ac93a..b96e16a6 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -413,7 +413,7 @@ public class AltosUI extends JFrame { } private void ConnectToDevice() { - altos_device device = AltosDeviceDialog.show(AltosUI.this, "TeleDongle"); + AltosDevice device = AltosDeviceDialog.show(AltosUI.this, AltosDevice.BaseStation); if (device != null) { try { -- cgit v1.2.3 From e1463d8e265dfd42c824d90088cd2a51b4cf8131 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 21 Aug 2010 17:57:31 -0700 Subject: altosui: Make teledongle callsign configurable Teledongle uses the callsign in packet mode; this provides a way to set that. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosPreferences.java | 19 ++++++++++++++++ ao-tools/altosui/AltosSerial.java | 5 +++++ ao-tools/altosui/AltosUI.java | 40 ++++++++++++++++++++++++++-------- 3 files changed, 55 insertions(+), 9 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosPreferences.java b/ao-tools/altosui/AltosPreferences.java index 297e1aae..690f8f1e 100644 --- a/ao-tools/altosui/AltosPreferences.java +++ b/ao-tools/altosui/AltosPreferences.java @@ -37,6 +37,9 @@ class AltosPreferences { /* voice preference name */ final static String voicePreference = "VOICE"; + /* callsign preference name */ + final static String callsignPreference = "CALLSIGN"; + /* Default logdir is ~/TeleMetrum */ final static String logdirName = "TeleMetrum"; @@ -52,6 +55,8 @@ class AltosPreferences { /* Voice preference */ static boolean voice; + static String callsign; + public static void init(Component ui) { preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); @@ -71,6 +76,8 @@ class AltosPreferences { channel = preferences.getInt(channelPreference, 0); voice = preferences.getBoolean(voicePreference, true); + + callsign = preferences.get(callsignPreference,"N0CALL"); } static void flush_preferences() { @@ -154,4 +161,16 @@ class AltosPreferences { public static boolean voice() { return voice; } + + public static void set_callsign(String new_callsign) { + callsign = new_callsign; + synchronized(preferences) { + preferences.put(callsignPreference, callsign); + flush_preferences(); + } + } + + public static String callsign() { + return callsign; + } } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index efa63f68..ba00b55e 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -154,6 +154,11 @@ public class AltosSerial implements Runnable { printf("m 0\nc r %d\nm 1\n", channel); } + public void set_callsign(String callsign) { + if (altos != null) + printf ("c c %s\n", callsign); + } + public AltosSerial() { altos = null; input_thread = null; diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index b96e16a6..33ce274a 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -420,6 +420,7 @@ public class AltosUI extends JFrame { serial_line.open(device); DeviceThread thread = new DeviceThread(serial_line); serial_line.set_channel(AltosPreferences.channel()); + serial_line.set_callsign(AltosPreferences.callsign()); run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, @@ -440,6 +441,18 @@ public class AltosUI extends JFrame { stop_display(); } + void ConfigureCallsign() { + String result; + result = JOptionPane.showInputDialog(AltosUI.this, + "Configure Callsign", + AltosPreferences.callsign()); + if (result != null) { + AltosPreferences.set_callsign(result); + if (serial_line != null) + serial_line.set_callsign(result); + } + } + /* * Open an existing telemetry file and replay it in realtime */ @@ -556,6 +569,22 @@ public class AltosUI extends JFrame { menu.setMnemonic(KeyEvent.VK_F); menubar.add(menu); + item = new JMenuItem("Replay File",KeyEvent.VK_R); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Replay(); + } + }); + menu.add(item); + + item = new JMenuItem("Save Flight Data",KeyEvent.VK_S); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + SaveFlightData(); + } + }); + menu.add(item); + item = new JMenuItem("Quit",KeyEvent.VK_Q); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); @@ -591,20 +620,13 @@ public class AltosUI extends JFrame { menu.addSeparator(); - item = new JMenuItem("Save Flight Data",KeyEvent.VK_S); + item = new JMenuItem("Set Callsign",KeyEvent.VK_S); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - SaveFlightData(); + ConfigureCallsign(); } }); - menu.add(item); - item = new JMenuItem("Replay",KeyEvent.VK_R); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - Replay(); - } - }); menu.add(item); } // Log menu -- cgit v1.2.3 From 953bc3438b10b21f3d65d292356c4ab2de23cddd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 22 Aug 2010 23:05:20 -0700 Subject: altosui: Add TeleMetrum configuration This presents a dialog with all of the user-settable options in the TeleMetrum set for editing. Combo boxes are used for everything except the callsign. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosChannelMenu.java | 70 ++++++ ao-tools/altosui/AltosConfig.java | 264 ++++++++++++++++++++ ao-tools/altosui/AltosConfigUI.java | 423 +++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 33 +-- ao-tools/altosui/Makefile | 5 +- 5 files changed, 779 insertions(+), 16 deletions(-) create mode 100644 ao-tools/altosui/AltosChannelMenu.java create mode 100644 ao-tools/altosui/AltosConfig.java create mode 100644 ao-tools/altosui/AltosConfigUI.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosChannelMenu.java b/ao-tools/altosui/AltosChannelMenu.java new file mode 100644 index 00000000..504c13c6 --- /dev/null +++ b/ao-tools/altosui/AltosChannelMenu.java @@ -0,0 +1,70 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosChannelMenu extends JMenu implements ActionListener { + ButtonGroup group; + int channel; + LinkedList listeners; + + public void addActionListener(ActionListener l) { + listeners.add(l); + } + + public void actionPerformed(ActionEvent e) { + channel = Integer.parseInt(e.getActionCommand()); + + ListIterator i = listeners.listIterator(); + + ActionEvent newe = new ActionEvent(this, channel, e.getActionCommand()); + while (i.hasNext()) { + ActionListener listener = i.next(); + listener.actionPerformed(newe); + } + } + + public AltosChannelMenu(int current_channel) { + super("Channel", true); + group = new ButtonGroup(); + + channel = current_channel; + + listeners = new LinkedList(); + for (int c = 0; c <= 9; c++) { + JRadioButtonMenuItem radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c, + 434.550 + c * 0.1), + c == channel); + radioitem.setActionCommand(String.format("%d", c)); + radioitem.addActionListener(this); + add(radioitem); + group.add(radioitem); + } + } + +} diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java new file mode 100644 index 00000000..ac73e7c5 --- /dev/null +++ b/ao-tools/altosui/AltosConfig.java @@ -0,0 +1,264 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.Altos; +import altosui.AltosSerial; +import altosui.AltosSerialMonitor; +import altosui.AltosRecord; +import altosui.AltosTelemetry; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosFlightStatusTableModel; +import altosui.AltosFlightInfoTableModel; +import altosui.AltosConfigUI; + +import libaltosJNI.*; + +public class AltosConfig implements Runnable, ActionListener { + + class int_ref { + int value; + + public int get() { + return value; + } + public void set(int i) { + value = i; + } + public int_ref(int i) { + value = i; + } + } + + class string_ref { + String value; + + public String get() { + return value; + } + public void set(String i) { + value = i; + } + public string_ref(String i) { + value = i; + } + } + + JFrame owner; + AltosDevice device; + AltosSerial serial_line; + boolean remote; + Thread config_thread; + int_ref serial; + int_ref main_deploy; + int_ref apogee_delay; + int_ref radio_channel; + string_ref version; + string_ref product; + string_ref callsign; + AltosConfigUI config_ui; + + + boolean get_int(String line, String label, int_ref x) { + if (line.startsWith(label)) { + try { + String tail = line.substring(label.length()).trim(); + String[] tokens = tail.split("\\s+"); + if (tokens.length > 0) { + int i = Integer.parseInt(tokens[0]); + x.set(i); + return true; + } + } catch (NumberFormatException ne) { + } + } + return false; + } + + boolean get_string(String line, String label, string_ref s) { + if (line.startsWith(label)) { + String quoted = line.substring(label.length()).trim(); + + if (quoted.startsWith("\"")) + quoted = quoted.substring(1); + if (quoted.endsWith("\"")) + quoted = quoted.substring(0,quoted.length()-1); + s.set(quoted); + return true; + } else { + return false; + } + } + + void start_serial() throws InterruptedException { + if (remote) { + serial_line.printf("m 0\n"); + serial_line.set_channel(AltosPreferences.channel()); + serial_line.set_callsign(AltosPreferences.callsign()); + serial_line.printf("p\n"); + } + } + + void stop_serial() throws InterruptedException { + if (remote) { + serial_line.printf("~\n"); + serial_line.flush(); + } + } + + void get_data() throws InterruptedException { + try { + start_serial(); + serial_line.printf("c s\nv\n"); + for (;;) { + String line = serial_line.get_reply(); + get_int(line, "serial-number", serial); + get_int(line, "Main deploy:", main_deploy); + get_int(line, "Apogee delay:", apogee_delay); + get_int(line, "Radio channel:", radio_channel); + get_string(line, "Callsign:", callsign); + get_string(line,"software-version", version); + get_string(line,"product", product); + + /* signals the end of the version info */ + if (line.startsWith("software-version")) + break; + } + } finally { + stop_serial(); + } + } + + void init_ui () { + config_ui = new AltosConfigUI(owner); + config_ui.addActionListener(this); + set_ui(); + } + + void set_ui() { + try { + if (serial_line != null) + get_data(); + config_ui.set_serial(serial.get()); + config_ui.set_product(product.get()); + config_ui.set_version(version.get()); + config_ui.set_main_deploy(main_deploy.get()); + config_ui.set_apogee_delay(apogee_delay.get()); + config_ui.set_radio_channel(radio_channel.get()); + config_ui.set_callsign(callsign.get()); + config_ui.set_clean(); + } catch (InterruptedException ie) { + } + } + + void run_dialog() { + } + + void save_data() { + main_deploy.set(config_ui.main_deploy()); + apogee_delay.set(config_ui.apogee_delay()); + radio_channel.set(config_ui.radio_channel()); + callsign.set(config_ui.callsign()); + try { + start_serial(); + serial_line.printf("c m %d\n", main_deploy.get()); + serial_line.printf("c d %d\n", apogee_delay.get()); + serial_line.printf("c r %d\n", radio_channel.get()); + serial_line.printf("c c %s\n", callsign.get()); + serial_line.printf("c w\n"); + } catch (InterruptedException ie) { + } finally { + try { + stop_serial(); + } catch (InterruptedException ie) { + } + } + } + + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + if (cmd.equals("save")) { + save_data(); + set_ui(); + } else if (cmd.equals("reset")) { + set_ui(); + } else if (cmd.equals("close")) { + if (serial_line != null) + serial_line.close(); + } + } + + public void run () { + try { + init_ui(); + config_ui.make_visible(); +// } catch (InterruptedException ie) { + } finally { + } + } + + public AltosConfig(JFrame given_owner) { + owner = given_owner; + + serial = new int_ref(0); + main_deploy = new int_ref(250); + apogee_delay = new int_ref(0); + radio_channel = new int_ref(0); + callsign = new string_ref("N0CALL"); + version = new string_ref("unknown"); + product = new string_ref("unknown"); + + device = AltosDeviceDialog.show(owner, AltosDevice.Any); + serial_line = new AltosSerial(); + if (device != null) { + try { + serial_line.open(device); + if (!device.matchProduct(AltosDevice.TeleMetrum)) + remote = true; + config_thread = new Thread(this); + config_thread.start(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(owner, + String.format("Cannot open device \"%s\"", + device.getPath()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(owner, + device.getPath(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } + } + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java new file mode 100644 index 00000000..1d8c579a --- /dev/null +++ b/ao-tools/altosui/AltosConfigUI.java @@ -0,0 +1,423 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import javax.swing.event.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.Altos; +import altosui.AltosSerial; +import altosui.AltosSerialMonitor; +import altosui.AltosRecord; +import altosui.AltosTelemetry; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosFlightStatusTableModel; +import altosui.AltosFlightInfoTableModel; + +import libaltosJNI.*; + +public class AltosConfigUI extends JDialog implements ActionListener, ItemListener, DocumentListener { + + Container pane; + Box box; + JLabel product_label; + JLabel version_label; + JLabel serial_label; + JLabel main_deploy_label; + JLabel apogee_delay_label; + JLabel radio_channel_label; + JLabel callsign_label; + + public boolean dirty; + + JFrame owner; + JLabel product_value; + JLabel version_value; + JLabel serial_value; + JComboBox main_deploy_value; + JComboBox apogee_delay_value; + JComboBox radio_channel_value; + JTextField callsign_value; + + JButton save; + JButton reset; + JButton close; + + ActionListener listener; + + static String[] main_deploy_values = { + "100", "150", "200", "250", "300", "350", + "400", "450", "500" + }; + + static String[] apogee_delay_values = { + "0", "1", "2", "3", "4", "5" + }; + + static String[] radio_channel_values = new String[10]; + { + for (int i = 0; i <= 9; i++) + radio_channel_values[i] = String.format("Channel %1d (%7.3fMHz)", + i, 434.550 + i * 0.1); + } + + /* A window listener to catch closing events and tell the config code */ + class ConfigListener extends WindowAdapter { + AltosConfigUI ui; + + public ConfigListener(AltosConfigUI this_ui) { + ui = this_ui; + } + + public void windowClosing(WindowEvent e) { + ui.actionPerformed(new ActionEvent(e.getSource(), + ActionEvent.ACTION_PERFORMED, + "close")); + } + } + + /* Build the UI using a grid bag */ + public AltosConfigUI(JFrame in_owner) { + super (in_owner, "Configure TeleMetrum", false); + + owner = in_owner; + GridBagConstraints c; + + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + /* Product */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + product_label = new JLabel("Product:"); + pane.add(product_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 0; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + product_value = new JLabel(""); + pane.add(product_value, c); + + /* Version */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 1; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + version_label = new JLabel("Software version:"); + pane.add(version_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 1; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + version_value = new JLabel(""); + pane.add(version_value, c); + + /* Serial */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 2; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 2; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JLabel(""); + pane.add(serial_value, c); + + /* Main deploy */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 3; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 3; + main_deploy_label = new JLabel("Main Deploy Altitude(m):"); + pane.add(main_deploy_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 3; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + main_deploy_value = new JComboBox(main_deploy_values); + main_deploy_value.setEditable(true); + main_deploy_value.addItemListener(this); + pane.add(main_deploy_value, c); + + /* Apogee delay */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 4; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + apogee_delay_label = new JLabel("Apogee Delay(s):"); + pane.add(apogee_delay_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 4; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + apogee_delay_value = new JComboBox(apogee_delay_values); + apogee_delay_value.setEditable(true); + apogee_delay_value.addItemListener(this); + pane.add(apogee_delay_value, c); + + /* Radio channel */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 5; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_channel_label = new JLabel("Radio Channel:"); + pane.add(radio_channel_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 5; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_channel_value = new JComboBox(radio_channel_values); + radio_channel_value.setEditable(false); + radio_channel_value.addItemListener(this); + pane.add(radio_channel_value, c); + + /* Callsign */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 6; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + callsign_label = new JLabel("Callsign:"); + pane.add(callsign_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 6; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + callsign_value = new JTextField("N0CALL"); + callsign_value.getDocument().addDocumentListener(this); + pane.add(callsign_value, c); + + /* Buttons */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 7; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + save = new JButton("Save"); + pane.add(save, c); + save.addActionListener(this); + save.setActionCommand("save"); + + c = new GridBagConstraints(); + c.gridx = 2; c.gridy = 7; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + reset = new JButton("Reset"); + pane.add(reset, c); + reset.addActionListener(this); + reset.setActionCommand("reset"); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 7; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_END; + c.insets = il; + close = new JButton("Close"); + pane.add(close, c); + close.addActionListener(this); + close.setActionCommand("close"); + + addWindowListener(new ConfigListener(this)); + } + + /* Once the initial values are set, the config code will show the dialog */ + public void make_visible() { + pack(); + setLocationRelativeTo(owner); + setVisible(true); + } + + /* If any values have been changed, confirm before closing */ + public boolean check_dirty() { + if (dirty) { + Object[] options = { "Close anyway", "Keep editing" }; + int i; + i = JOptionPane.showOptionDialog(this, + "Configuration modified, close anyway?", + "Configuration Modified", + JOptionPane.DEFAULT_OPTION, + JOptionPane.WARNING_MESSAGE, + null, options, options[1]); + if (i != 0) + return false; + } + return true; + } + + /* Listen for events from our buttons */ + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + + if (cmd.equals("close")) + if (!check_dirty()) + return; + listener.actionPerformed(e); + if (cmd.equals("close")) { + setVisible(false); + dispose(); + } + dirty = false; + } + + /* ItemListener interface method */ + public void itemStateChanged(ItemEvent e) { + dirty = true; + } + + /* DocumentListener interface methods */ + public void changedUpdate(DocumentEvent e) { + dirty = true; + } + + public void insertUpdate(DocumentEvent e) { + dirty = true; + } + + public void removeUpdate(DocumentEvent e) { + dirty = true; + } + + /* Let the config code hook on a listener */ + public void addActionListener(ActionListener l) { + listener = l; + } + + /* set and get all of the dialog values */ + public void set_product(String product) { + product_value.setText(product); + } + + public void set_version(String version) { + version_value.setText(version); + } + + public void set_serial(int serial) { + serial_value.setText(String.format("%d", serial)); + } + + public void set_main_deploy(int new_main_deploy) { + main_deploy_value.setSelectedItem(Integer.toString(new_main_deploy)); + } + + public int main_deploy() { + return Integer.parseInt(main_deploy_value.getSelectedItem().toString()); + } + + public void set_apogee_delay(int new_apogee_delay) { + apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay)); + } + + public int apogee_delay() { + return Integer.parseInt(apogee_delay_value.getSelectedItem().toString()); + } + + public void set_radio_channel(int new_radio_channel) { + radio_channel_value.setSelectedIndex(new_radio_channel); + } + + public int radio_channel() { + return radio_channel_value.getSelectedIndex(); + } + + public void set_callsign(String new_callsign) { + callsign_value.setText(new_callsign); + } + + public String callsign() { + return callsign_value.getText(); + } + + public void set_clean() { + dirty = false; + } + + } \ No newline at end of file diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 33ce274a..49d1f11a 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -40,6 +40,7 @@ import altosui.AltosLog; import altosui.AltosVoice; import altosui.AltosFlightStatusTableModel; import altosui.AltosFlightInfoTableModel; +import altosui.AltosChannelMenu; import libaltosJNI.*; @@ -453,6 +454,9 @@ public class AltosUI extends JFrame { } } + void ConfigureTeleMetrum() { + new AltosConfig(AltosUI.this); + } /* * Open an existing telemetry file and replay it in realtime */ @@ -628,6 +632,15 @@ public class AltosUI extends JFrame { }); menu.add(item); + + item = new JMenuItem("Configure TeleMetrum device",KeyEvent.VK_T); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ConfigureTeleMetrum(); + } + }); + + menu.add(item); } // Log menu { @@ -680,26 +693,16 @@ public class AltosUI extends JFrame { // Channel menu { - menu = new JMenu("Channel", true); - menu.setMnemonic(KeyEvent.VK_C); - menubar.add(menu); - ButtonGroup group = new ButtonGroup(); - - for (int c = 0; c <= 9; c++) { - radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c, - 434.550 + c * 0.1), - c == AltosPreferences.channel()); - radioitem.setActionCommand(String.format("%d", c)); - radioitem.addActionListener(new ActionListener() { + menu = new AltosChannelMenu(AltosPreferences.channel()); + menu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int new_channel = Integer.parseInt(e.getActionCommand()); AltosPreferences.set_channel(new_channel); serial_line.set_channel(new_channel); } - }); - menu.add(radioitem); - group.add(radioitem); - } + }); + menu.setMnemonic(KeyEvent.VK_C); + menubar.add(menu); } this.setJMenuBar(menubar); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 8c9e9642..541b89e3 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -3,6 +3,9 @@ CLASSPATH=classes:./* CLASSFILES=\ Altos.class \ + AltosChannelMenu.class \ + AltosConfig.class \ + AltosConfigUI.class \ AltosConvert.class \ AltosCSV.class \ AltosEepromDownload.class \ @@ -39,7 +42,7 @@ FREETTSJAR= \ en_us.jar \ freetts.jar -JAVAFLAGS=-Xlint:unchecked +JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation OS:=$(shell uname) -- cgit v1.2.3 From 0e17853c08f77debef3e8cf82e9cdb6a5079fc9b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 22 Aug 2010 23:06:15 -0700 Subject: altosui: Set callsign when fetching eeprom data over the air The updated firmware places the callsign in each packet to comply with regulations, this ensures that TeleDongle has the current callsign configured. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromDownload.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index c2a8d25e..02a71118 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -225,6 +225,7 @@ public class AltosEepromDownload implements Runnable { if (remote) { serial_line.printf("m 0\n"); serial_line.set_channel(AltosPreferences.channel()); + serial_line.set_callsign(AltosPreferences.callsign()); serial_line.printf("p\n"); } @@ -259,7 +260,6 @@ public class AltosEepromDownload implements Runnable { if (device != null) { try { serial_line.open(device); - String name = device.getName(); if (!device.matchProduct(AltosDevice.TeleMetrum)) remote = true; eeprom_thread = new Thread(this); -- cgit v1.2.3 From 2007288da8a83e3aa925e11cc196f1c65aab2e5c Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 5 Aug 2010 15:00:15 -0400 Subject: working on java packaging details --- ao-tools/altosui/Makefile | 33 +++++++++++++++++---------------- debian/altos.desktop | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 541b89e3..63359fbb 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -1,6 +1,6 @@ .SUFFIXES: .java .class -CLASSPATH=classes:./* +CLASSPATH=classes:./*:/usr/share/java/* CLASSFILES=\ Altos.class \ AltosChannelMenu.class \ @@ -31,16 +31,17 @@ CLASSFILES=\ AltosDeviceDialog.class \ AltosVoice.class -FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 -FREETTSLIB=$(FREETTSSRC)/lib -FREETTSJAR= \ - cmudict04.jar \ - cmulex.jar \ - cmu_time_awb.jar \ - cmutimelex.jar \ - cmu_us_kal.jar \ - en_us.jar \ - freetts.jar +#FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 +#FREETTSLIB=$(FREETTSSRC)/lib +#FREETTSJAR=/usr/share/java/freetts.jar +#FREETTSJAR= \ +# cmudict04.jar \ +# cmulex.jar \ +# cmu_time_awb.jar \ +# cmutimelex.jar \ +# cmu_us_kal.jar \ +# en_us.jar \ +# freetts.jar JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation @@ -66,14 +67,14 @@ altosui.jar: classes/altosui classes/libaltosJNI $(FREETTSJAR) $(CLASSFILES) Man classes/altosui: mkdir -p classes - ln -s .. classes/altosui + ln -sf .. classes/altosui classes/libaltosJNI: mkdir -p classes - ln -s ../../libaltos/libaltosJNI classes/libaltosJNI + ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI -$(FREETTSJAR): - ln -s $(FREETTSLIB)/$@ . +#$(FREETTSJAR): +# ln -s $(FREETTSLIB)/$@ . ifeq ($(OS),Darwin) RESOURCES=altosui.jar $(FREETTSJAR) ../libaltos/libaltos.dylib @@ -92,6 +93,6 @@ altosui: endif clean: - rm -f *.class $(FREETTSJAR) altosui.jar + rm -f *.class altosui.jar rm -f AltosUI.app/Contents/Resources/Java/* rm -rf classes diff --git a/debian/altos.desktop b/debian/altos.desktop index ae9bdc63..4281ad3a 100644 --- a/debian/altos.desktop +++ b/debian/altos.desktop @@ -7,4 +7,4 @@ Icon=/usr/share/pixmaps/altusmetrum.xpm Exec=/usr/bin/ao-view %f Terminal=false MimeType=text/plain; -Categories=Viewer;Network; +Categories=Education;Science; -- cgit v1.2.3 From 7f8d7978606abe544b1b9b6065c5480ed813b8ec Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 11:53:19 -0700 Subject: altosui: Add .ihx file reading code and stub out flashing UI Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlash.java | 78 ++++++++++++ ao-tools/altosui/AltosHexfile.java | 248 +++++++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 14 +++ ao-tools/altosui/Makefile | 2 + 4 files changed, 342 insertions(+) create mode 100644 ao-tools/altosui/AltosFlash.java create mode 100644 ao-tools/altosui/AltosHexfile.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java new file mode 100644 index 00000000..ac9e81df --- /dev/null +++ b/ao-tools/altosui/AltosFlash.java @@ -0,0 +1,78 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosHexfile; + +public class AltosFlash implements Runnable { + File file; + FileInputStream input; + Thread thread; + AltosHexfile image; + JFrame frame; + + public void run() { + try { + image = new AltosHexfile(input); + System.out.printf("read file start %d length %d\n", + image.address, image.data.length); + } catch (IOException e) { + JOptionPane.showMessageDialog(frame, + file, + e.getMessage(), + JOptionPane.ERROR_MESSAGE); + } + } + + public AltosFlash(JFrame in_frame) { + frame = in_frame; + + JFileChooser hexfile_chooser = new JFileChooser(); + + hexfile_chooser.setDialogTitle("Select Flash Image"); + hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx")); + int returnVal = hexfile_chooser.showOpenDialog(frame); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + file = hexfile_chooser.getSelectedFile(); + if (file != null) { + try { + input = new FileInputStream(file); + thread = new Thread(this); + thread.start(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + file, + "Cannot open flash file", + JOptionPane.ERROR_MESSAGE); + } + } + } + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosHexfile.java b/ao-tools/altosui/AltosHexfile.java new file mode 100644 index 00000000..c7078877 --- /dev/null +++ b/ao-tools/altosui/AltosHexfile.java @@ -0,0 +1,248 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.LinkedList; +import java.util.Iterator; +import java.util.Arrays; + +class HexFileInputStream extends PushbackInputStream { + public int line; + + public HexFileInputStream(FileInputStream o) { + super(new BufferedInputStream(o)); + line = 1; + } + + public int read() throws IOException { + int c = super.read(); + if (c == '\n') + line++; + return c; + } + + public void unread(int c) throws IOException { + if (c == '\n') + line--; + if (c != -1) + super.unread(c); + } +} + +class HexRecord implements Comparable { + public int address; + public int type; + public byte checksum; + public byte[] data; + + static final int NORMAL = 0; + static final int EOF = 1; + static final int EXTENDED_ADDRESS = 2; + + enum read_state { + marker, + length, + address, + type, + data, + checksum, + newline, + white, + done, + } + + boolean ishex(int c) { + if ('0' <= c && c <= '9') + return true; + if ('a' <= c && c <= 'f') + return true; + if ('A' <= c && c <= 'F') + return true; + return false; + } + + boolean isspace(int c) { + switch (c) { + case ' ': + case '\t': + return true; + } + return false; + } + + int fromhex(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - 'a' + 10; + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + return -1; + } + + public byte checksum() { + byte got = 0; + + got += data.length; + got += (address >> 8) & 0xff; + got += (address ) & 0xff; + got += type; + for (int i = 0; i < data.length; i++) + got += data[i]; + return (byte) (-got); + } + + public int compareTo(Object other) { + HexRecord o = (HexRecord) other; + return address - o.address; + } + + public String toString() { + return String.format("%04x: %02x (%d)", address, type, data.length); + } + + public HexRecord(HexFileInputStream input) throws IOException { + read_state state = read_state.marker; + int nhexbytes = 0; + int hex = 0; + int ndata = 0; + byte got_checksum; + + while (state != read_state.done) { + int c = input.read(); + if (c < 0 && state != read_state.white) + throw new IOException(String.format("%d: Unexpected EOF", input.line)); + if (c == ' ') + continue; + switch (state) { + case marker: + if (c != ':') + throw new IOException("Missing ':'"); + state = read_state.length; + nhexbytes = 2; + hex = 0; + break; + case length: + case address: + case type: + case data: + case checksum: + if(!ishex(c)) + throw new IOException(String.format("Non-hex char '%c'", c)); + hex = hex << 4 | fromhex(c); + --nhexbytes; + if (nhexbytes != 0) + break; + + switch (state) { + case length: + data = new byte[hex]; + state = read_state.address; + nhexbytes = 4; + break; + case address: + address = hex; + state = read_state.type; + nhexbytes = 2; + break; + case type: + type = hex; + if (data.length > 0) + state = read_state.data; + else + state = read_state.checksum; + nhexbytes = 2; + ndata = 0; + break; + case data: + data[ndata] = (byte) hex; + ndata++; + nhexbytes = 2; + if (ndata == data.length) + state = read_state.checksum; + break; + case checksum: + checksum = (byte) hex; + state = read_state.newline; + break; + default: + break; + } + hex = 0; + break; + case newline: + if (c != '\n' && c != '\r') + throw new IOException("Missing newline"); + state = read_state.white; + break; + case white: + if (!isspace(c)) { + input.unread(c); + state = read_state.done; + } + break; + case done: + break; + } + } + got_checksum = checksum(); + if (got_checksum != checksum) + throw new IOException(String.format("Invalid checksum (read 0x%02x computed 0x%02x)\n", + checksum, got_checksum)); + } +} + +public class AltosHexfile { + public int address; + public byte[] data; + + public AltosHexfile(FileInputStream file) throws IOException { + HexFileInputStream input = new HexFileInputStream(file); + LinkedList record_list = new LinkedList(); + boolean done = false; + + while (!done) { + HexRecord record = new HexRecord(input); + + if (record.type == HexRecord.EOF) + done = true; + else + record_list.add(record); + } + HexRecord[] records = record_list.toArray(new HexRecord[0]); + Arrays.sort(records); + if (records.length > 0) { + int base = records[0].address; + int bound = records[records.length-1].address + + records[records.length-1].data.length; + + data = new byte[bound - base]; + address = base; + Arrays.fill(data, (byte) 0xff); + + /* Paint the records into the new array */ + for (int i = 0; i < records.length; i++) { + for (int j = 0; j < records[i].data.length; j++) + data[records[i].address - base + j] = records[i].data[j]; + } + } + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 49d1f11a..565866ea 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -41,6 +41,7 @@ import altosui.AltosVoice; import altosui.AltosFlightStatusTableModel; import altosui.AltosFlightInfoTableModel; import altosui.AltosChannelMenu; +import altosui.AltosFlash; import libaltosJNI.*; @@ -457,6 +458,11 @@ public class AltosUI extends JFrame { void ConfigureTeleMetrum() { new AltosConfig(AltosUI.this); } + + void FlashImage() { + new AltosFlash(AltosUI.this); + } + /* * Open an existing telemetry file and replay it in realtime */ @@ -589,6 +595,14 @@ public class AltosUI extends JFrame { }); menu.add(item); + item = new JMenuItem("Flash Image",KeyEvent.VK_F); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + FlashImage(); + } + }); + menu.add(item); + item = new JMenuItem("Quit",KeyEvent.VK_Q); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 541b89e3..ebe59644 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -13,10 +13,12 @@ CLASSFILES=\ AltosEepromReader.class \ AltosEepromRecord.class \ AltosFile.class \ + AltosFlash.class \ AltosFlightInfoTableModel.class \ AltosFlightStatusTableModel.class \ AltosGPS.class \ AltosGreatCircle.class \ + AltosHexfile.class \ AltosLog.class \ AltosParse.class \ AltosPreferences.class \ -- cgit v1.2.3 From ebeb13688a9a5442c838641ede6ba0dc92c9a1a4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 14:32:58 -0700 Subject: altosui: Add debug dongle API, split flash UI out Create an API to talk through the debug port on another AltOS device. Split the flash UI out from the flash implementation so that a command line flash utility can be written. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfigUI.java | 5 +- ao-tools/altosui/AltosDebug.java | 231 +++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosFlash.java | 60 ++++----- ao-tools/altosui/AltosFlashUI.java | 92 +++++++++++++ ao-tools/altosui/AltosHexfile.java | 6 + ao-tools/altosui/AltosRomconfig.java | 110 ++++++++++++++++ ao-tools/altosui/AltosRomconfigUI.java | 160 +++++++++++++++++++++++ ao-tools/altosui/AltosSerial.java | 4 + ao-tools/altosui/AltosUI.java | 4 +- ao-tools/altosui/Makefile | 4 + 10 files changed, 640 insertions(+), 36 deletions(-) create mode 100644 ao-tools/altosui/AltosDebug.java create mode 100644 ao-tools/altosui/AltosFlashUI.java create mode 100644 ao-tools/altosui/AltosRomconfig.java create mode 100644 ao-tools/altosui/AltosRomconfigUI.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index 1d8c579a..6825b9a9 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -44,7 +44,10 @@ import altosui.AltosFlightInfoTableModel; import libaltosJNI.*; -public class AltosConfigUI extends JDialog implements ActionListener, ItemListener, DocumentListener { +public class AltosConfigUI + extends JDialog + implements ActionListener, ItemListener, DocumentListener +{ Container pane; Box box; diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java new file mode 100644 index 00000000..7bd3a5cd --- /dev/null +++ b/ao-tools/altosui/AltosDebug.java @@ -0,0 +1,231 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.LinkedList; +import java.util.Iterator; +import altosui.AltosSerial; +import altosui.AltosRomconfig; + +public class AltosDebug extends AltosSerial { + + static final byte WR_CONFIG = 0x1d; + static final byte RD_CONFIG = 0x24; + static final byte CONFIG_TIMERS_OFF = (1 << 3); + static final byte CONFIG_DMA_PAUSE = (1 << 2); + static final byte CONFIG_TIMER_SUSPEND = (1 << 1); + static final byte SET_FLASH_INFO_PAGE = (1 << 0); + + static final byte GET_PC = 0x28; + static final byte READ_STATUS = 0x34; + static final byte STATUS_CHIP_ERASE_DONE = (byte) (1 << 7); + static final byte STATUS_PCON_IDLE = (1 << 6); + static final byte STATUS_CPU_HALTED = (1 << 5); + static final byte STATUS_POWER_MODE_0 = (1 << 4); + static final byte STATUS_HALT_STATUS = (1 << 3); + static final byte STATUS_DEBUG_LOCKED = (1 << 2); + static final byte STATUS_OSCILLATOR_STABLE = (1 << 1); + static final byte STATUS_STACK_OVERFLOW = (1 << 0); + + static final byte SET_HW_BRKPNT = 0x3b; + static byte HW_BRKPNT_N(byte n) { return (byte) ((n) << 3); } + static final byte HW_BRKPNT_N_MASK = (0x3 << 3); + static final byte HW_BRKPNT_ENABLE = (1 << 2); + + static final byte HALT = 0x44; + static final byte RESUME = 0x4c; + static byte DEBUG_INSTR(byte n) { return (byte) (0x54|(n)); } + static final byte STEP_INSTR = 0x5c; + static byte STEP_REPLACE(byte n) { return (byte) (0x64|(n)); } + static final byte GET_CHIP_ID = 0x68; + + + static boolean ishex(int c) { + if ('0' <= c && c <= '9') + return true; + if ('a' <= c && c <= 'f') + return true; + if ('A' <= c && c <= 'F') + return true; + return false; + } + + static boolean ishex(String s) { + for (int i = 0; i < s.length(); i++) + if (!ishex(s.charAt(i))) + return false; + return true; + } + static boolean isspace(int c) { + switch (c) { + case ' ': + case '\t': + return true; + } + return false; + } + + static int fromhex(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - 'a' + 10; + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + return -1; + } + + boolean debug_mode; + + void ensure_debug_mode() { + if (!debug_mode) { + printf("D\n"); + debug_mode = true; + } + } + + /* + * Write target memory + */ + public void write_memory(int address, byte[] bytes) { + ensure_debug_mode(); + printf("O %x %x\n", bytes.length, address); + for (int i = 0; i < bytes.length; i++) + printf("%02x", bytes[i]); + } + + /* + * Read target memory + */ + public byte[] read_memory(int address, int length) + throws IOException, InterruptedException { + byte[] data = new byte[length]; + + flush_reply(); + ensure_debug_mode(); + printf("I %x %x\n", length, address); + int i = 0; + while (i < length) { + String line = get_reply().trim(); + if (!ishex(line) || line.length() % 2 != 0) + throw new IOException( + String.format + ("Invalid reply \"%s\"", line)); + int this_time = line.length() / 2; + for (int j = 0; j < this_time; j++) + data[j] = (byte) ((fromhex(line.charAt(j*2)) << 4) + + fromhex(line.charAt(j*2+1))); + i += this_time; + } + + return data; + } + + /* + * Write raw bytes to the debug link using the 'P' command + */ + public void write_bytes(byte[] bytes) throws IOException { + int i = 0; + ensure_debug_mode(); + while (i < bytes.length) { + int this_time = bytes.length - i; + if (this_time > 8) + this_time = 0; + printf("P"); + for (int j = 0; j < this_time; j++) + printf(" %02x", bytes[i+j]); + printf("\n"); + i += this_time; + } + } + + public void write_byte(byte b) throws IOException { + byte[] bytes = { b }; + write_bytes(bytes); + } + + /* + * Read raw bytes from the debug link using the 'G' command + */ + public byte[] read_bytes(int length) + throws IOException, InterruptedException { + + flush_reply(); + ensure_debug_mode(); + printf("G %x\n", length); + int i = 0; + byte[] data = new byte[length]; + while (i < length) { + String line = get_reply().trim(); + String tokens[] = line.split("\\s+"); + for (int j = 0; j < tokens.length; j++) { + if (!ishex(tokens[j]) || + tokens[j].length() != 2) + throw new IOException( + String.format + ("Invalid read_bytes reply \"%s\"", line)); + try { + data[i + j] = (byte) Integer.parseInt(tokens[j], 16); + } catch (NumberFormatException ne) { + throw new IOException( + String.format + ("Invalid read_bytes reply \"%s\"", line)); + } + } + i += tokens.length; + } + return data; + } + + public byte read_status() throws IOException, InterruptedException { + write_byte(READ_STATUS); + return read_bytes(2)[0]; + } + + public boolean check_connection() throws IOException, InterruptedException { + byte reply = read_status(); + System.out.printf("status %x\n", reply); + if ((reply & STATUS_CHIP_ERASE_DONE) == 0) + return false; + if ((reply & STATUS_PCON_IDLE) != 0) + return false; + if ((reply & STATUS_POWER_MODE_0) == 0) + return false; + return true; + } + + public AltosRomconfig romconfig() { + try { + byte[] bytes = read_memory(0xa0, 10); + return new AltosRomconfig(bytes, 0); + } catch (IOException ie) { + } catch (InterruptedException ie) { + } + return new AltosRomconfig(); + } + + /* + * Reset target + */ + public void reset() { + printf ("R\n"); + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index ac9e81df..bab60c1f 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -30,49 +30,43 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.AltosHexfile; -public class AltosFlash implements Runnable { +public class AltosFlash { File file; FileInputStream input; Thread thread; AltosHexfile image; JFrame frame; + AltosDevice debug_dongle; + AltosDebug debug; + AltosRomconfig rom_config; - public void run() { - try { - image = new AltosHexfile(input); - System.out.printf("read file start %d length %d\n", - image.address, image.data.length); - } catch (IOException e) { - JOptionPane.showMessageDialog(frame, - file, - e.getMessage(), - JOptionPane.ERROR_MESSAGE); - } + public void flash() throws IOException, FileNotFoundException, InterruptedException { + if (!check_rom_config()) + throw new IOException("Invalid rom config settings"); + rom_config.write(image); } - public AltosFlash(JFrame in_frame) { - frame = in_frame; + public boolean check_rom_config() { + if (rom_config == null) + rom_config = debug.romconfig(); + return rom_config != null && rom_config.valid(); + } - JFileChooser hexfile_chooser = new JFileChooser(); + public void set_romconfig (AltosRomconfig romconfig) { + rom_config = romconfig; + } - hexfile_chooser.setDialogTitle("Select Flash Image"); - hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx")); - int returnVal = hexfile_chooser.showOpenDialog(frame); + public void open() throws IOException, FileNotFoundException, InterruptedException { + input = new FileInputStream(file); + image = new AltosHexfile(input); + debug.open(debug_dongle); + if (!debug.check_connection()) + throw new IOException("Debug port not connected"); + } - if (returnVal == JFileChooser.APPROVE_OPTION) { - file = hexfile_chooser.getSelectedFile(); - if (file != null) { - try { - input = new FileInputStream(file); - thread = new Thread(this); - thread.start(); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(frame, - file, - "Cannot open flash file", - JOptionPane.ERROR_MESSAGE); - } - } - } + public AltosFlash(File in_file, AltosDevice in_debug_dongle) { + file = in_file; + debug_dongle = in_debug_dongle; + debug = new AltosDebug(); } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java new file mode 100644 index 00000000..5cae4756 --- /dev/null +++ b/ao-tools/altosui/AltosFlashUI.java @@ -0,0 +1,92 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosHexfile; +import altosui.AltosFlash; + +public class AltosFlashUI implements Runnable { + File file; + Thread thread; + JFrame frame; + AltosDevice debug_dongle; + AltosFlash flash; + + public void run() { + flash = new AltosFlash(file, debug_dongle); + try { + flash.open(); + if (!flash.check_rom_config()) { + AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); + romconfig_ui.showDialog(); + AltosRomconfig romconfig = romconfig_ui.romconfig(); + if (romconfig == null) + return; + flash.set_romconfig(romconfig); + } + flash.flash(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + "Cannot open image", + file.toString(), + JOptionPane.ERROR_MESSAGE); + return; + } catch (IOException e) { + JOptionPane.showMessageDialog(frame, + e.getMessage(), + file.toString(), + JOptionPane.ERROR_MESSAGE); + return; + } catch (InterruptedException ie) { + } + } + + public AltosFlashUI(JFrame in_frame) { + frame = in_frame; + + debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.Any); + + if (debug_dongle == null) + return; + + JFileChooser hexfile_chooser = new JFileChooser(); + + hexfile_chooser.setDialogTitle("Select Flash Image"); + hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx")); + int returnVal = hexfile_chooser.showOpenDialog(frame); + + if (returnVal != JFileChooser.APPROVE_OPTION) + return; + + file = hexfile_chooser.getSelectedFile(); + + thread = new Thread(this); + thread.start(); + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosHexfile.java b/ao-tools/altosui/AltosHexfile.java index c7078877..360e24ad 100644 --- a/ao-tools/altosui/AltosHexfile.java +++ b/ao-tools/altosui/AltosHexfile.java @@ -214,6 +214,10 @@ public class AltosHexfile { public int address; public byte[] data; + public byte get_byte(int a) { + return data[a - address]; + } + public AltosHexfile(FileInputStream file) throws IOException { HexFileInputStream input = new HexFileInputStream(file); LinkedList record_list = new LinkedList(); @@ -244,5 +248,7 @@ public class AltosHexfile { data[records[i].address - base + j] = records[i].data[j]; } } + for (int i = 0xa0; i < 0xaa; i++) + System.out.printf ("%04x: %02x\n", i, get_byte(i)); } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java new file mode 100644 index 00000000..5a2df313 --- /dev/null +++ b/ao-tools/altosui/AltosRomconfig.java @@ -0,0 +1,110 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; +import java.io.*; +import altosui.AltosHexfile; + +public class AltosRomconfig { + public boolean valid; + public int version; + public int check; + public int serial_number; + public int radio_calibration; + + static int get_int(byte[] bytes, int start, int len) { + int v = 0; + int o = 0; + while (len > 0) { + v = v | ((((int) bytes[start]) & 0xff) << o); + start++; + len--; + o += 8; + } + return v; + } + + static void put_int(int value, byte[] bytes, int start, int len) { + while (len > 0) { + bytes[start] = (byte) (value & 0xff); + start++; + len--; + value >>= 8; + } + } + + public AltosRomconfig(byte[] bytes, int offset) { + version = get_int(bytes, offset + 0, 2); + check = get_int(bytes, offset + 2, 2); + if (check == (~version & 0xffff)) { + switch (version) { + case 1: + serial_number = get_int(bytes, offset + 4, 2); + radio_calibration = get_int(bytes, offset + 6, 4); + valid = true; + break; + } + } + System.out.printf("version 0x%x check 0x%x valid %s serial %d cal %d\n", + version, check, valid ? "true" : "false", + serial_number, radio_calibration); + } + + public AltosRomconfig(AltosHexfile hexfile) { + this(hexfile.data, 0xa0 - hexfile.address); + } + + public void write(byte[] bytes, int offset) throws IOException { + if (!valid) + throw new IOException("rom configuration invalid"); + + if (offset < 0 || bytes.length < offset + 10) + throw new IOException("image cannot contain rom config"); + + AltosRomconfig existing = new AltosRomconfig(bytes, offset); + if (!existing.valid) + throw new IOException("image does not contain existing rom config"); + + switch (existing.version) { + case 1: + put_int(serial_number, bytes, offset + 4, 2); + put_int(radio_calibration, bytes, offset + 6, 4); + break; + } + } + + public void write (AltosHexfile hexfile) throws IOException { + write(hexfile.data, 0xa0 - hexfile.address); + new AltosRomconfig(hexfile); + } + + public AltosRomconfig(int in_serial_number, int in_radio_calibration) { + valid = true; + version = 1; + check = (~version & 0xffff); + serial_number = in_serial_number; + radio_calibration = in_radio_calibration; + } + + public boolean valid() { + return valid && serial_number != 0; + } + + public AltosRomconfig() { + valid = false; + } +} diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java new file mode 100644 index 00000000..21c34ef4 --- /dev/null +++ b/ao-tools/altosui/AltosRomconfigUI.java @@ -0,0 +1,160 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import javax.swing.event.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; + +import altosui.AltosRomconfig; + +public class AltosRomconfigUI + extends JDialog + implements ActionListener +{ + Container pane; + Box box; + JLabel serial_label; + JLabel radio_calibration_label; + + JFrame owner; + JTextField serial_value; + JTextField radio_calibration_value; + + JButton ok; + JButton cancel; + + /* Build the UI using a grid bag */ + public AltosRomconfigUI(JFrame in_owner) { + super (in_owner, "Configure TeleMetrum Rom Values", true); + + owner = in_owner; + GridBagConstraints c; + + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + /* Serial */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 0; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JTextField("0"); + pane.add(serial_value, c); + + /* Radio calibration value */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 1; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_calibration_label = new JLabel("Radio Calibration:"); + pane.add(radio_calibration_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 1; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_calibration_value = new JTextField("1186611"); + pane.add(radio_calibration_value, c); + + /* Buttons */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 2; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + ok = new JButton("OK"); + pane.add(ok, c); + ok.addActionListener(this); + ok.setActionCommand("ok"); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 2; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + cancel = new JButton("Cancel"); + pane.add(cancel, c); + cancel.addActionListener(this); + cancel.setActionCommand("cancel"); + + pack(); + setLocationRelativeTo(owner); + } + + boolean selected; + + /* Listen for events from our buttons */ + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + + if (cmd.equals("ok")) + selected = true; + setVisible(false); + } + + int serial() { + return Integer.parseInt(serial_value.getText()); + } + + int radio_calibration() { + return Integer.parseInt(radio_calibration_value.getText()); + } + + public AltosRomconfig romconfig() { + return new AltosRomconfig(serial(), radio_calibration()); + } + + public AltosRomconfig showDialog() { + setVisible(true); + if (selected) + return romconfig(); + return null; + } +} diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index ba00b55e..a62f1225 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -79,6 +79,10 @@ public class AltosSerial implements Runnable { } } + public void flush_reply() { + reply_queue.clear(); + } + public String get_reply() throws InterruptedException { return reply_queue.take(); } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 565866ea..9fd47ea7 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -41,7 +41,7 @@ import altosui.AltosVoice; import altosui.AltosFlightStatusTableModel; import altosui.AltosFlightInfoTableModel; import altosui.AltosChannelMenu; -import altosui.AltosFlash; +import altosui.AltosFlashUI; import libaltosJNI.*; @@ -460,7 +460,7 @@ public class AltosUI extends JFrame { } void FlashImage() { - new AltosFlash(AltosUI.this); + new AltosFlashUI(AltosUI.this); } /* diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index ebe59644..affbac39 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -8,12 +8,14 @@ CLASSFILES=\ AltosConfigUI.class \ AltosConvert.class \ AltosCSV.class \ + AltosDebug.class \ AltosEepromDownload.class \ AltosEepromMonitor.class \ AltosEepromReader.class \ AltosEepromRecord.class \ AltosFile.class \ AltosFlash.class \ + AltosFlashUI.class \ AltosFlightInfoTableModel.class \ AltosFlightStatusTableModel.class \ AltosGPS.class \ @@ -31,6 +33,8 @@ CLASSFILES=\ AltosUI.class \ AltosDevice.class \ AltosDeviceDialog.class \ + AltosRomconfig.class \ + AltosRomconfigUI.class \ AltosVoice.class FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 -- cgit v1.2.3 From b8519b8669ff54741dd738ac343fbd2424451247 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 21:53:37 -0700 Subject: ao-dumplog: Fix --remote and --channel options to actually work --- ao-tools/ao-dumplog/ao-dumplog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c index 57c43290..6d4fa5bf 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.c +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -29,7 +29,7 @@ static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, - { .name = "remote", .has_arg = 1, .val = 'R' }, + { .name = "remote", .has_arg = 0, .val = 'R' }, { .name = "channel", .has_arg = 1, .val = 'C' }, { 0, 0, 0, 0}, }; @@ -91,7 +91,7 @@ main (int argc, char **argv) int invalid; char serial_line[8192]; - while ((c = getopt_long(argc, argv, "T:D:R", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:C:R", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; -- cgit v1.2.3 From 86f7b9314b042f2e512fdf35067817e68532867b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 21:54:47 -0700 Subject: altosui: pad TM config dialog values to avoid clipping descenders --- ao-tools/altosui/AltosConfigUI.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index 6825b9a9..605ccc8b 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -147,6 +147,7 @@ public class AltosConfigUI c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; + c.ipady = 5; version_label = new JLabel("Software version:"); pane.add(version_label, c); @@ -157,6 +158,7 @@ public class AltosConfigUI c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = ir; + c.ipady = 5; version_value = new JLabel(""); pane.add(version_value, c); @@ -167,6 +169,7 @@ public class AltosConfigUI c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; + c.ipady = 5; serial_label = new JLabel("Serial:"); pane.add(serial_label, c); @@ -177,6 +180,7 @@ public class AltosConfigUI c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = ir; + c.ipady = 5; serial_value = new JLabel(""); pane.add(serial_value, c); @@ -187,7 +191,7 @@ public class AltosConfigUI c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; - c.ipady = 3; + c.ipady = 5; main_deploy_label = new JLabel("Main Deploy Altitude(m):"); pane.add(main_deploy_label, c); @@ -278,7 +282,7 @@ public class AltosConfigUI /* Buttons */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 7; - c.gridwidth = 2; + c.gridwidth = 6; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -288,8 +292,8 @@ public class AltosConfigUI save.setActionCommand("save"); c = new GridBagConstraints(); - c.gridx = 2; c.gridy = 7; - c.gridwidth = 2; + c.gridx = 0; c.gridy = 7; + c.gridwidth = 6; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.CENTER; c.insets = il; @@ -299,8 +303,8 @@ public class AltosConfigUI reset.setActionCommand("reset"); c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 7; - c.gridwidth = 2; + c.gridx = 0; c.gridy = 7; + c.gridwidth = 6; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_END; c.insets = il; -- cgit v1.2.3 From f9e80f39bc39e5882bfe75f959b6501cb3277cd2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 21:55:49 -0700 Subject: libaltos: use pipe to wake up getchar on close. use mutexes --- ao-tools/libaltos/libaltos.c | 121 +++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 38 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 3e8485e4..ffdb2366 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -448,16 +448,20 @@ altos_list_finish(struct altos_list *list) #include #include #include +#include #define USB_BUF_SIZE 64 struct altos_file { int fd; + int pipe[2]; unsigned char out_data[USB_BUF_SIZE]; int out_used; unsigned char in_data[USB_BUF_SIZE]; int in_used; int in_read; + pthread_mutex_t putc_mutex; + pthread_mutex_t getc_mutex; }; struct altos_file * @@ -470,6 +474,7 @@ altos_open(struct altos_device *device) if (!file) return NULL; + pipe(file->pipe); file->fd = open(device->path, O_RDWR | O_NOCTTY); if (file->fd < 0) { perror(device->path); @@ -484,8 +489,8 @@ altos_open(struct altos_device *device) return NULL; } cfmakeraw(&term); - term.c_cc[VMIN] = 0; - term.c_cc[VTIME] = 1; + term.c_cc[VMIN] = 1; + term.c_cc[VTIME] = 0; ret = tcsetattr(file->fd, TCSAFLUSH, &term); if (ret < 0) { perror("tcsetattr"); @@ -493,6 +498,8 @@ altos_open(struct altos_device *device) free(file); return NULL; } + pthread_mutex_init(&file->putc_mutex,NULL); + pthread_mutex_init(&file->getc_mutex,NULL); return file; } @@ -500,8 +507,10 @@ void altos_close(struct altos_file *file) { if (file->fd != -1) { - close(file->fd); + int fd = file->fd; file->fd = -1; + write(file->pipe[1], "\r", 1); + close(fd); } } @@ -512,68 +521,104 @@ altos_free(struct altos_file *file) free(file); } +static int +_altos_flush(struct altos_file *file) +{ + while (file->out_used) { + int ret; + + if (file->fd < 0) + return -EBADF; + fflush(stdout); + ret = write (file->fd, file->out_data, file->out_used); + if (ret < 0) + return -errno; + if (ret) { + memmove(file->out_data, file->out_data + ret, + file->out_used - ret); + file->out_used -= ret; + } + } +} + int altos_putchar(struct altos_file *file, char c) { int ret; + pthread_mutex_lock(&file->putc_mutex); if (file->out_used == USB_BUF_SIZE) { - ret = altos_flush(file); - if (ret) + ret = _altos_flush(file); + if (ret) { + pthread_mutex_unlock(&file->putc_mutex); return ret; + } } file->out_data[file->out_used++] = c; + ret = 0; if (file->out_used == USB_BUF_SIZE) - return altos_flush(file); + ret = _altos_flush(file); + pthread_mutex_unlock(&file->putc_mutex); return 0; } int altos_flush(struct altos_file *file) { - while (file->out_used) { - int ret; - - if (file->fd < 0) - return -EBADF; - ret = write (file->fd, file->out_data, file->out_used); - if (ret < 0) - return -errno; - if (ret) { - memmove(file->out_data, file->out_data + ret, - file->out_used - ret); - file->out_used -= ret; - } - } + int ret; + pthread_mutex_lock(&file->putc_mutex); + ret = _altos_flush(file); + pthread_mutex_unlock(&file->putc_mutex); + return ret; } + #include int altos_getchar(struct altos_file *file, int timeout) { - while (file->in_read == file->in_used) { - int ret; + int ret; + struct pollfd fd[2]; - altos_flush(file); - if (file->fd < 0) - return -EBADF; - if (timeout) { - struct pollfd fd; - int ret; - fd.fd = file->fd; - fd.events = POLLIN; - ret = poll(&fd, 1, timeout); - if (ret == 0) - return LIBALTOS_TIMEOUT; + if (timeout == 0) + timeout = -1; + pthread_mutex_lock(&file->getc_mutex); + fd[0].fd = file->fd; + fd[0].events = POLLIN; + fd[1].fd = file->pipe[0]; + fd[1].events = POLLIN; + while (file->in_read == file->in_used) { + if (file->fd < 0) { + pthread_mutex_unlock(&file->getc_mutex); + return LIBALTOS_ERROR; } - ret = read(file->fd, file->in_data, USB_BUF_SIZE); - if (ret < 0) + altos_flush(file); + + ret = poll(fd, 2, timeout); + if (ret < 0) { + perror("altos_getchar"); + pthread_mutex_unlock(&file->getc_mutex); return LIBALTOS_ERROR; - file->in_read = 0; - file->in_used = ret; + } + if (ret == 0) { + pthread_mutex_unlock(&file->getc_mutex); + return LIBALTOS_TIMEOUT; + } + if (fd[0].revents & POLLIN) { + ret = read(file->fd, file->in_data, USB_BUF_SIZE); + if (ret < 0) { + perror("altos_getchar"); + pthread_mutex_unlock(&file->getc_mutex); + return LIBALTOS_ERROR; + } + file->in_read = 0; + file->in_used = ret; + } } - return file->in_data[file->in_read++]; + ret = file->in_data[file->in_read++]; + pthread_mutex_unlock(&file->getc_mutex); + return ret; } #endif /* POSIX_TTY */ -- cgit v1.2.3 From b1758be01397fd49c441f40852f3558fe9343a2d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 21:58:50 -0700 Subject: altosui: Add lots more cc1111 debug interface functions These are sufficient to program the flash. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDebug.java | 139 +++++++++++++++++++++++++++++---------- 1 file changed, 103 insertions(+), 36 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index 7bd3a5cd..83ea5bcb 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -27,35 +27,35 @@ import altosui.AltosRomconfig; public class AltosDebug extends AltosSerial { - static final byte WR_CONFIG = 0x1d; - static final byte RD_CONFIG = 0x24; - static final byte CONFIG_TIMERS_OFF = (1 << 3); - static final byte CONFIG_DMA_PAUSE = (1 << 2); - static final byte CONFIG_TIMER_SUSPEND = (1 << 1); - static final byte SET_FLASH_INFO_PAGE = (1 << 0); - - static final byte GET_PC = 0x28; - static final byte READ_STATUS = 0x34; - static final byte STATUS_CHIP_ERASE_DONE = (byte) (1 << 7); - static final byte STATUS_PCON_IDLE = (1 << 6); - static final byte STATUS_CPU_HALTED = (1 << 5); - static final byte STATUS_POWER_MODE_0 = (1 << 4); - static final byte STATUS_HALT_STATUS = (1 << 3); - static final byte STATUS_DEBUG_LOCKED = (1 << 2); - static final byte STATUS_OSCILLATOR_STABLE = (1 << 1); - static final byte STATUS_STACK_OVERFLOW = (1 << 0); - - static final byte SET_HW_BRKPNT = 0x3b; - static byte HW_BRKPNT_N(byte n) { return (byte) ((n) << 3); } - static final byte HW_BRKPNT_N_MASK = (0x3 << 3); - static final byte HW_BRKPNT_ENABLE = (1 << 2); - - static final byte HALT = 0x44; - static final byte RESUME = 0x4c; - static byte DEBUG_INSTR(byte n) { return (byte) (0x54|(n)); } - static final byte STEP_INSTR = 0x5c; - static byte STEP_REPLACE(byte n) { return (byte) (0x64|(n)); } - static final byte GET_CHIP_ID = 0x68; + public static final byte WR_CONFIG = 0x1d; + public static final byte RD_CONFIG = 0x24; + public static final byte CONFIG_TIMERS_OFF = (1 << 3); + public static final byte CONFIG_DMA_PAUSE = (1 << 2); + public static final byte CONFIG_TIMER_SUSPEND = (1 << 1); + public static final byte SET_FLASH_INFO_PAGE = (1 << 0); + + public static final byte GET_PC = 0x28; + public static final byte READ_STATUS = 0x34; + public static final byte STATUS_CHIP_ERASE_DONE = (byte) (1 << 7); + public static final byte STATUS_PCON_IDLE = (1 << 6); + public static final byte STATUS_CPU_HALTED = (1 << 5); + public static final byte STATUS_POWER_MODE_0 = (1 << 4); + public static final byte STATUS_HALT_STATUS = (1 << 3); + public static final byte STATUS_DEBUG_LOCKED = (1 << 2); + public static final byte STATUS_OSCILLATOR_STABLE = (1 << 1); + public static final byte STATUS_STACK_OVERFLOW = (1 << 0); + + public static final byte SET_HW_BRKPNT = 0x3b; + public static byte HW_BRKPNT_N(byte n) { return (byte) ((n) << 3); } + public static final byte HW_BRKPNT_N_MASK = (0x3 << 3); + public static final byte HW_BRKPNT_ENABLE = (1 << 2); + + public static final byte HALT = 0x44; + public static final byte RESUME = 0x4c; + public static byte DEBUG_INSTR(byte n) { return (byte) (0x54|(n)); } + public static final byte STEP_INSTR = 0x5c; + public static byte STEP_REPLACE(byte n) { return (byte) (0x64|(n)); } + public static final byte GET_CHIP_ID = 0x68; static boolean ishex(int c) { @@ -102,14 +102,32 @@ public class AltosDebug extends AltosSerial { } } + void dump_memory(String header, int address, byte[] bytes, int start, int len) { + System.out.printf("%s\n", header); + for (int j = 0; j < len; j++) { + if ((j & 15) == 0) { + if (j != 0) + System.out.printf("\n"); + System.out.printf ("%04x:", address + j); + } + System.out.printf(" %02x", bytes[start + j]); + } + System.out.printf("\n"); + } + /* * Write target memory */ - public void write_memory(int address, byte[] bytes) { + public void write_memory(int address, byte[] bytes, int start, int len) { ensure_debug_mode(); - printf("O %x %x\n", bytes.length, address); - for (int i = 0; i < bytes.length; i++) - printf("%02x", bytes[i]); +// dump_memory("write_memory", address, bytes, start, len); + printf("O %x %x\n", len, address); + for (int i = 0; i < len; i++) + printf("%02x", bytes[start + i]); + } + + public void write_memory(int address, byte[] bytes) { + write_memory(address, bytes, 0, bytes.length); } /* @@ -123,6 +141,7 @@ public class AltosDebug extends AltosSerial { ensure_debug_mode(); printf("I %x %x\n", length, address); int i = 0; + int start = 0; while (i < length) { String line = get_reply().trim(); if (!ishex(line) || line.length() % 2 != 0) @@ -131,10 +150,12 @@ public class AltosDebug extends AltosSerial { ("Invalid reply \"%s\"", line)); int this_time = line.length() / 2; for (int j = 0; j < this_time; j++) - data[j] = (byte) ((fromhex(line.charAt(j*2)) << 4) + + data[start + j] = (byte) ((fromhex(line.charAt(j*2)) << 4) + fromhex(line.charAt(j*2+1))); + start += this_time; i += this_time; } +// dump_memory("read_memory", address, data, 0, length); return data; } @@ -195,14 +216,60 @@ public class AltosDebug extends AltosSerial { return data; } + public byte read_byte() throws IOException, InterruptedException { + return read_bytes(1)[0]; + } + + public byte debug_instr(byte[] instruction) throws IOException, InterruptedException { + byte[] command = new byte[1 + instruction.length]; + command[0] = DEBUG_INSTR((byte) instruction.length); + for (int i = 0; i < instruction.length; i++) + command[i+1] = instruction[i]; + write_bytes(command); + return read_byte(); + } + + public byte resume() throws IOException, InterruptedException { + write_byte(RESUME); + return read_byte(); + } + + public int read_uint16() throws IOException, InterruptedException { + byte[] d = read_bytes(2); + return ((int) (d[0] & 0xff) << 8) | (d[1] & 0xff); + } + + public int read_uint8() throws IOException, InterruptedException { + byte[] d = read_bytes(1); + return (int) (d[0] & 0xff); + } + + public int get_chip_id() throws IOException, InterruptedException { + write_byte(GET_CHIP_ID); + return read_uint16(); + } + + public int get_pc() throws IOException, InterruptedException { + write_byte(GET_PC); + return read_uint16(); + } + public byte read_status() throws IOException, InterruptedException { write_byte(READ_STATUS); - return read_bytes(2)[0]; + return read_byte(); + } + + static final byte LJMP = 0x02; + + public void set_pc(int pc) throws IOException, InterruptedException { + byte high = (byte) (pc >> 8); + byte low = (byte) pc; + byte[] jump_mem = { LJMP, high, low }; + debug_instr(jump_mem); } public boolean check_connection() throws IOException, InterruptedException { byte reply = read_status(); - System.out.printf("status %x\n", reply); if ((reply & STATUS_CHIP_ERASE_DONE) == 0) return false; if ((reply & STATUS_PCON_IDLE) != 0) -- cgit v1.2.3 From 8857ac5e43eac6db8d5594b8864df497a712242b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:00:16 -0700 Subject: altosui: remove debug printf from AltosHexfile --- ao-tools/altosui/AltosHexfile.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosHexfile.java b/ao-tools/altosui/AltosHexfile.java index 360e24ad..19e35ae1 100644 --- a/ao-tools/altosui/AltosHexfile.java +++ b/ao-tools/altosui/AltosHexfile.java @@ -248,7 +248,5 @@ public class AltosHexfile { data[records[i].address - base + j] = records[i].data[j]; } } - for (int i = 0xa0; i < 0xaa; i++) - System.out.printf ("%04x: %02x\n", i, get_byte(i)); } } \ No newline at end of file -- cgit v1.2.3 From c3f57ffdb6c74de90d982eacd604e658ce9b00a5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:01:11 -0700 Subject: altosui: flush serial output before waiting for reply --- ao-tools/altosui/AltosSerial.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index a62f1225..d02e25a9 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -84,7 +84,9 @@ public class AltosSerial implements Runnable { } public String get_reply() throws InterruptedException { - return reply_queue.take(); + libaltos.altos_flush(altos); + String line = reply_queue.take(); + return line; } public void add_monitor(LinkedBlockingQueue q) { -- cgit v1.2.3 From bd2b44ddd61fadd8bf8ee6bf783ce019b1be7cc0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:01:38 -0700 Subject: altosui: Remove debug printf from AltosRomconfig --- ao-tools/altosui/AltosRomconfig.java | 3 --- 1 file changed, 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java index 5a2df313..844da7c4 100644 --- a/ao-tools/altosui/AltosRomconfig.java +++ b/ao-tools/altosui/AltosRomconfig.java @@ -59,9 +59,6 @@ public class AltosRomconfig { break; } } - System.out.printf("version 0x%x check 0x%x valid %s serial %d cal %d\n", - version, check, valid ? "true" : "false", - serial_number, radio_calibration); } public AltosRomconfig(AltosHexfile hexfile) { -- cgit v1.2.3 From 4c0c099716197ef7539be0cf55bbb164f6804958 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:02:21 -0700 Subject: altosui: Finish device programming code Altosui can now reprogram Altusmetrum devices. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlash.java | 263 ++++++++++++++++++++++++++++++++++++- ao-tools/altosui/AltosFlashUI.java | 115 +++++++++++++++- 2 files changed, 376 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index bab60c1f..0f92d6e7 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -33,17 +33,274 @@ import altosui.AltosHexfile; public class AltosFlash { File file; FileInputStream input; - Thread thread; AltosHexfile image; JFrame frame; AltosDevice debug_dongle; AltosDebug debug; AltosRomconfig rom_config; + ActionListener listener; + boolean aborted; + + static final byte MOV_direct_data = (byte) 0x75; + static final byte MOV_DPTR_data16 = (byte) 0x90; + static final byte MOV_A_data = (byte) 0x74; + static final byte MOVX_atDPTR_A = (byte) 0xf0; + static final byte MOVX_A_atDPTR = (byte) 0xe0; + static final byte INC_DPTR = (byte) 0xa3; + static final byte TRAP = (byte) 0xa5; + + static final byte JB = (byte) 0x20; + + static final byte MOV_A_direct = (byte) 0xe5; + static final byte MOV_direct1_direct2 = (byte) 0x85; + static final byte MOV_direct_A = (byte) 0xf5; + static final byte MOV_R0_data = (byte) (0x78 | 0); + static final byte MOV_R1_data = (byte) (0x78 | 1); + static final byte MOV_R2_data = (byte) (0x78 | 2); + static final byte MOV_R3_data = (byte) (0x78 | 3); + static final byte MOV_R4_data = (byte) (0x78 | 4); + static final byte MOV_R5_data = (byte) (0x78 | 5); + static final byte MOV_R6_data = (byte) (0x78 | 6); + static final byte MOV_R7_data = (byte) (0x78 | 7); + static final byte DJNZ_R0_rel = (byte) (0xd8 | 0); + static final byte DJNZ_R1_rel = (byte) (0xd8 | 1); + static final byte DJNZ_R2_rel = (byte) (0xd8 | 2); + static final byte DJNZ_R3_rel = (byte) (0xd8 | 3); + static final byte DJNZ_R4_rel = (byte) (0xd8 | 4); + static final byte DJNZ_R5_rel = (byte) (0xd8 | 5); + static final byte DJNZ_R6_rel = (byte) (0xd8 | 6); + static final byte DJNZ_R7_rel = (byte) (0xd8 | 7); + + static final byte P1DIR = (byte) 0xFE; + static final byte P1 = (byte) 0x90; + + /* flash controller */ + static final byte FWT = (byte) 0xAB; + static final byte FADDRL = (byte) 0xAC; + static final byte FADDRH = (byte) 0xAD; + static final byte FCTL = (byte) 0xAE; + static final byte FCTL_BUSY = (byte) 0x80; + static final byte FCTL_BUSY_BIT = (byte) 7; + static final byte FCTL_SWBSY = (byte) 0x40; + static final byte FCTL_SWBSY_BIT = (byte) 6; + static final byte FCTL_CONTRD = (byte) 0x10; + static final byte FCTL_WRITE = (byte) 0x02; + static final byte FCTL_ERASE = (byte) 0x01; + static final byte FWDATA = (byte) 0xAF; + + static final byte ACC = (byte) 0xE0; + + /* offsets within the flash_page program */ + static final int FLASH_ADDR_HIGH = 8; + static final int FLASH_ADDR_LOW = 11; + static final int RAM_ADDR_HIGH = 13; + static final int RAM_ADDR_LOW = 14; + static final int FLASH_WORDS_HIGH = 16; + static final int FLASH_WORDS_LOW = 18; + static final int FLASH_TIMING = 21; + + /* sleep mode control */ + static final int SLEEP = (byte) 0xbe; + static final int SLEEP_USB_EN = (byte) 0x80; + static final int SLEEP_XOSC_STB = (byte) 0x40; + static final int SLEEP_HFRC_STB = (byte) 0x20; + static final int SLEEP_RST_MASK = (byte) 0x18; + static final int SLEEP_RST_POWERON = (byte) 0x00; + static final int SLEEP_RST_EXTERNAL = (byte) 0x10; + static final int SLEEP_RST_WATCHDOG = (byte) 0x08; + static final int SLEEP_OSC_PD = (byte) 0x04; + static final int SLEEP_MODE_MASK = (byte) 0x03; + static final int SLEEP_MODE_PM0 = (byte) 0x00; + static final int SLEEP_MODE_PM1 = (byte) 0x01; + static final int SLEEP_MODE_PM2 = (byte) 0x02; + static final int SLEEP_MODE_PM3 = (byte) 0x03; + + /* clock controller */ + static final byte CLKCON = (byte) 0xC6; + static final byte CLKCON_OSC32K = (byte) 0x80; + static final byte CLKCON_OSC = (byte) 0x40; + static final byte CLKCON_TICKSPD = (byte) 0x38; + static final byte CLKCON_CLKSPD = (byte) 0x07; + + static final byte[] flash_page_proto = { + + MOV_direct_data, P1DIR, (byte) 0x02, + MOV_direct_data, P1, (byte) 0xFF, + + MOV_direct_data, FADDRH, 0, /* FLASH_ADDR_HIGH */ + + MOV_direct_data, FADDRL, 0, /* FLASH_ADDR_LOW */ + + MOV_DPTR_data16, 0, 0, /* RAM_ADDR_HIGH, RAM_ADDR_LOW */ + + MOV_R7_data, 0, /* FLASH_WORDS_HIGH */ + + MOV_R6_data, 0, /* FLASH_WORDS_LOW */ + + + MOV_direct_data, FWT, 0x20, /* FLASH_TIMING */ + + MOV_direct_data, FCTL, FCTL_ERASE, +/* eraseWaitLoop: */ + MOV_A_direct, FCTL, + JB, ACC|FCTL_BUSY_BIT, (byte) 0xfb, + + MOV_direct_data, P1, (byte) 0xfd, + + MOV_direct_data, FCTL, FCTL_WRITE, +/* writeLoop: */ + MOV_R5_data, 2, +/* writeWordLoop: */ + MOVX_A_atDPTR, + INC_DPTR, + MOV_direct_A, FWDATA, + DJNZ_R5_rel, (byte) 0xfa, /* writeWordLoop */ +/* writeWaitLoop: */ + MOV_A_direct, FCTL, + JB, ACC|FCTL_SWBSY_BIT, (byte) 0xfb, /* writeWaitLoop */ + DJNZ_R6_rel, (byte) 0xf1, /* writeLoop */ + DJNZ_R7_rel, (byte) 0xef, /* writeLoop */ + + MOV_direct_data, P1DIR, (byte) 0x00, + MOV_direct_data, P1, (byte) 0xFF, + TRAP, + }; + + public byte[] make_flash_page(int flash_addr, int ram_addr, int byte_count) { + int flash_word_addr = flash_addr >> 1; + int flash_word_count = ((byte_count + 1) >> 1); + + byte[] flash_page = new byte[flash_page_proto.length]; + for (int i = 0; i < flash_page.length; i++) + flash_page[i] = flash_page_proto[i]; + + flash_page[FLASH_ADDR_HIGH] = (byte) (flash_word_addr >> 8); + flash_page[FLASH_ADDR_LOW] = (byte) (flash_word_addr); + flash_page[RAM_ADDR_HIGH] = (byte) (ram_addr >> 8); + flash_page[RAM_ADDR_LOW] = (byte) (ram_addr); + + byte flash_words_low = (byte) (flash_word_count); + byte flash_words_high = (byte) (flash_word_count >> 8); + /* the flashing code has a minor 'bug' */ + if (flash_words_low != 0) + flash_words_high++; + + flash_page[FLASH_WORDS_HIGH] = (byte) flash_words_high; + flash_page[FLASH_WORDS_LOW] = (byte) flash_words_low; + return flash_page; + } + + static byte[] set_clkcon_fast = { + MOV_direct_data, CLKCON, 0x00 + }; + + static byte[] get_sleep = { + MOV_A_direct, SLEEP + }; + + public void clock_init() throws IOException, InterruptedException { + debug.debug_instr(set_clkcon_fast); + + byte status; + do { + status = debug.debug_instr(get_sleep); + } while ((status & SLEEP_XOSC_STB) == 0); + } + + void action(String s, int percent) { + if (listener != null && !aborted) + listener.actionPerformed(new ActionEvent(this, + percent, + s)); + } + + void action(int part, int total) { + int percent = 100 * part / total; + action(String.format("%d/%d (%d%%)", + part, total, percent), + percent); + } public void flash() throws IOException, FileNotFoundException, InterruptedException { if (!check_rom_config()) throw new IOException("Invalid rom config settings"); + if (image.address + image.data.length > 0x8000) + throw new IOException(String.format("Flash image too long %d", + image.address + + image.data.length)); + if ((image.address & 0x3ff) != 0) + throw new IOException(String.format("Flash image must start on page boundary (is 0x%x)", + image.address)); + int ram_address = 0xf000; + int flash_prog = 0xf400; + + /* + * Store desired config values into image + */ rom_config.write(image); + /* + * Bring up the clock + */ + clock_init(); + + int remain = image.data.length; + int flash_addr = image.address; + int image_start = 0; + + action(0, image.data.length); + while (remain > 0 && !aborted) { + int this_time = remain; + if (this_time > 0x400) + this_time = 0x400; + + /* write the data */ + debug.write_memory(ram_address, image.data, + image_start, this_time); + + /* write the flash program */ + byte[] flash_page = make_flash_page(flash_addr, + ram_address, + this_time); + debug.write_memory(flash_prog, flash_page); + + debug.set_pc(flash_prog); + int pc = debug.get_pc(); + debug.resume(); + Thread.sleep(100); + for (int times = 0; times < 10; times++) { + byte status = debug.read_status(); + if ((status & AltosDebug.STATUS_CPU_HALTED) != 0) + break; + Thread.sleep(100); + } + + byte[] check = debug.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])); + remain -= this_time; + flash_addr += this_time; + image_start += this_time; + + action(image.data.length - remain, image.data.length); + } + if (!aborted) { + action("done", 100); + debug.set_pc(image.address); + debug.resume(); + } + debug.close(); + } + + public void abort() { + aborted = true; + debug.close(); + } + + public void addActionListener(ActionListener l) { + listener = l; } public boolean check_rom_config() { @@ -56,6 +313,10 @@ public class AltosFlash { rom_config = romconfig; } + public AltosRomconfig romconfig() { + return rom_config; + } + public void open() throws IOException, FileNotFoundException, InterruptedException { input = new FileInputStream(file); image = new AltosHexfile(input); diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 5cae4756..0c2041e3 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -31,15 +31,43 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.AltosHexfile; import altosui.AltosFlash; -public class AltosFlashUI implements Runnable { +public class AltosFlashUI + extends JDialog + implements Runnable, ActionListener +{ + Container pane; + Box box; + JLabel serial_label; + JLabel serial_value; + JLabel file_label; + JLabel file_value; + JProgressBar pbar; + JButton cancel; + File file; Thread thread; JFrame frame; AltosDevice debug_dongle; AltosFlash flash; + public void actionPerformed(ActionEvent e) { + if (e.getSource() == cancel) { + abort(); + dispose(); + } else { + String cmd = e.getActionCommand(); + if (cmd.equals("done")) + dispose(); + else { + pbar.setValue(e.getID()); + pbar.setString(cmd); + } + } + } + public void run() { flash = new AltosFlash(file, debug_dongle); + flash.addActionListener(this); try { flash.open(); if (!flash.check_rom_config()) { @@ -50,6 +78,10 @@ public class AltosFlashUI implements Runnable { return; flash.set_romconfig(romconfig); } + serial_value.setText(String.format("%d", + flash.romconfig().serial_number)); + file_value.setText(file.toString()); + setVisible(true); flash.flash(); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, @@ -67,9 +99,90 @@ public class AltosFlashUI implements Runnable { } } + public void abort() { + if (flash != null) + flash.abort(); + } + + public void build_dialog() { + GridBagConstraints c; + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 0; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JLabel(""); + pane.add(serial_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + file_label = new JLabel("File:"); + pane.add(file_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + file_value = new JLabel(""); + pane.add(file_value, c); + + pbar = new JProgressBar(); + pbar.setMinimum(0); + pbar.setMaximum(100); + pbar.setValue(0); + pbar.setString(""); + pbar.setStringPainted(true); + pbar.setPreferredSize(new Dimension(600, 20)); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 2; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ib = new Insets(4,4,4,4); + c.insets = ib; + pane.add(pbar, c); + + cancel = new JButton("Cancel"); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 3; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ic = new Insets(4,4,4,4); + c.insets = ic; + pane.add(cancel, c); + cancel.addActionListener(this); + pack(); + setLocationRelativeTo(frame); + } + public AltosFlashUI(JFrame in_frame) { + super(in_frame, "Program Altusmetrum Device", false); + frame = in_frame; + build_dialog(); + debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.Any); if (debug_dongle == null) -- cgit v1.2.3 From ef8376c4dd8262a34e02b6bb9e19e907ac2f4330 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:08:30 -0700 Subject: altosui: make default Manifest look for built-in freetts --- ao-tools/altosui/Manifest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt index 504d0de3..251ce2a0 100644 --- a/ao-tools/altosui/Manifest.txt +++ b/ao-tools/altosui/Manifest.txt @@ -1,2 +1,2 @@ Main-Class: altosui.AltosUI -Class-Path: /usr/share/java/freetts.jar +Class-Path: freetts.jar -- cgit v1.2.3 From a55b132668a819cc26478a609cb79bd9190deb9d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 23:01:36 -0700 Subject: altosui: Separate out log file choosing dialog to share with CSV generator This dialog will be shared with the CSV file generating code, so split it out instead of duplicating it. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosLogfileChooser.java | 52 +++++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 14 +++------ ao-tools/altosui/Makefile | 1 + 3 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 ao-tools/altosui/AltosLogfileChooser.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosLogfileChooser.java b/ao-tools/altosui/AltosLogfileChooser.java new file mode 100644 index 00000000..72d21fc8 --- /dev/null +++ b/ao-tools/altosui/AltosLogfileChooser.java @@ -0,0 +1,52 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; + +import altosui.AltosPreferences; + +public class AltosLogfileChooser extends JFileChooser { + JFrame frame; + + public File runDialog() { + int ret; + + ret = showOpenDialog(frame); + if (ret == APPROVE_OPTION) + return getSelectedFile(); + return null; + } + + public AltosLogfileChooser(JFrame in_frame) { + in_frame = frame; + setDialogTitle("Select Flight Record File"); + setFileFilter(new FileNameExtensionFilter("Flight data file", + "eeprom", + "telem")); + setCurrentDirectory(AltosPreferences.logdir()); + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 9fd47ea7..64f96cdd 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -42,6 +42,7 @@ import altosui.AltosFlightStatusTableModel; import altosui.AltosFlightInfoTableModel; import altosui.AltosChannelMenu; import altosui.AltosFlashUI; +import altosui.AltosLogfileChooser; import libaltosJNI.*; @@ -529,17 +530,12 @@ public class AltosUI extends JFrame { * Replay a flight from telemetry data */ private void Replay() { - JFileChooser logfile_chooser = new JFileChooser(); + AltosLogfileChooser chooser = new AltosLogfileChooser( + AltosUI.this); - logfile_chooser.setDialogTitle("Select Flight Record File"); - logfile_chooser.setFileFilter(new FileNameExtensionFilter("Flight data file", "eeprom", "telem")); - logfile_chooser.setCurrentDirectory(AltosPreferences.logdir()); - int returnVal = logfile_chooser.showOpenDialog(AltosUI.this); + File file = chooser.runDialog(); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = logfile_chooser.getSelectedFile(); - if (file == null) - System.out.println("No file selected?"); + if (file != null) { String filename = file.getName(); try { FileInputStream replay = new FileInputStream(file); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index affbac39..de78b765 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -22,6 +22,7 @@ CLASSFILES=\ AltosGreatCircle.class \ AltosHexfile.class \ AltosLog.class \ + AltosLogfileChooser.class \ AltosParse.class \ AltosPreferences.class \ AltosRecord.class \ -- cgit v1.2.3 From 634a550149e7c344a22a637ba484f115592b1018 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 23:15:05 -0700 Subject: altosui: refactor logfile chooser dialog to share more code Move file opening logic into logfile chooser as it can be shared that way. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosLogfileChooser.java | 32 ++++++++++++++++++++++++++++--- ao-tools/altosui/AltosUI.java | 24 ++++------------------- 2 files changed, 33 insertions(+), 23 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosLogfileChooser.java b/ao-tools/altosui/AltosLogfileChooser.java index 72d21fc8..3e9e4892 100644 --- a/ao-tools/altosui/AltosLogfileChooser.java +++ b/ao-tools/altosui/AltosLogfileChooser.java @@ -28,16 +28,42 @@ import java.text.*; import java.util.prefs.*; import altosui.AltosPreferences; +import altosui.AltosReader; +import altosui.AltosEepromReader; +import altosui.AltosTelemetryReader; public class AltosLogfileChooser extends JFileChooser { JFrame frame; + String filename; - public File runDialog() { + public String filename() { + return filename; + } + + public AltosReader runDialog() { int ret; ret = showOpenDialog(frame); - if (ret == APPROVE_OPTION) - return getSelectedFile(); + if (ret == APPROVE_OPTION) { + File file = getSelectedFile(); + if (file == null) + return null; + filename = file.getName(); + try { + FileInputStream in; + + in = new FileInputStream(file); + if (filename.endsWith("eeprom")) + return new AltosEepromReader(in); + else + return new AltosTelemetryReader(in); + } catch (FileNotFoundException fe) { + JOptionPane.showMessageDialog(frame, + filename, + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + } return null; } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 64f96cdd..8a4c753f 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -532,26 +532,10 @@ public class AltosUI extends JFrame { private void Replay() { AltosLogfileChooser chooser = new AltosLogfileChooser( AltosUI.this); - - File file = chooser.runDialog(); - - if (file != null) { - String filename = file.getName(); - try { - FileInputStream replay = new FileInputStream(file); - DisplayThread thread; - if (filename.endsWith("eeprom")) - thread = new ReplayEepromThread(replay, filename); - else - thread = new ReplayTelemetryThread(replay, filename); - run_display(thread); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - filename, - "Cannot open telemetry file", - JOptionPane.ERROR_MESSAGE); - } - } + AltosReader reader = chooser.runDialog(); + if (reader != null) + run_display(new ReplayThread(reader, + chooser.filename())); } /* Connect to TeleMetrum, either directly or through -- cgit v1.2.3 From 7bd220dfd9b3fb0e42eb90c3b37eb7b4169eb21b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 00:29:11 -0700 Subject: altosui: Add ability to create CSV file from telem or eeprom files This creates a comma separated value file to export data for external programs. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 120 +++++++++++++++++++++++++++--- ao-tools/altosui/AltosCSVUI.java | 83 +++++++++++++++++++++ ao-tools/altosui/AltosEepromReader.java | 4 +- ao-tools/altosui/AltosLogfileChooser.java | 9 ++- ao-tools/altosui/AltosReader.java | 2 + ao-tools/altosui/AltosUI.java | 17 +++++ ao-tools/altosui/Makefile | 1 + 7 files changed, 224 insertions(+), 12 deletions(-) create mode 100644 ao-tools/altosui/AltosCSVUI.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index 24936758..f12c0348 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -19,12 +19,20 @@ package altosui; import java.lang.*; import java.io.*; +import java.text.*; +import java.util.*; + import altosui.AltosRecord; +import altosui.AltosReader; public class AltosCSV { - File name; - PrintStream out; - boolean header_written; + File name; + PrintStream out; + boolean header_written; + boolean seen_boost; + int boost_tick; + LinkedList pad_records; + AltosState state; static final int ALTOS_CSV_VERSION = 1; @@ -45,6 +53,7 @@ public class AltosCSV { * acceleration (m/s²) * pressure (mBar) * altitude (m) + * height (m) * accelerometer speed (m/s) * barometer speed (m/s) * temp (°C) @@ -76,8 +85,9 @@ public class AltosCSV { } void write_general(AltosRecord record) { - out.printf("%s,%d,%d,%s,%d", - record.version, record.serial, record.flight, record.callsign, record.tick); + out.printf("%s,%d,%d,%s,%8.2f", + record.version, record.serial, record.flight, record.callsign, + (double) (record.tick - boost_tick) / 100.0); } void write_flight_header() { @@ -85,31 +95,123 @@ public class AltosCSV { } void write_flight(AltosRecord record) { - out.printf("%d,%s", record.state, record.state()); + out.printf("%d,%8s", record.state, record.state()); + } + + 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) { + 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(), + record.accel_speed(), + state.baro_speed, + record.temperature(), + record.battery_voltage(), + record.drogue_voltage(), + record.main_voltage()); + } + + void write_gps_header() { + out.printf("connected locked nsat latitude longitude altitude year month day hour minute second"); + } + + void write_gps(AltosRecord record) { + AltosGPS gps = record.gps; + if (gps == null) + gps = new AltosGPS(); + + out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d", + gps.connected?1:0, + gps.locked?1:0, + gps.nsat, + gps.lat, + gps.lon, + gps.alt, + gps.year, + gps.month, + gps.day, + gps.hour, + gps.minute, + gps.second); } void write_header() { out.printf("# "); write_general_header(); out.printf(" "); write_flight_header(); + out.printf(" "); write_basic_header(); + out.printf(" "); write_gps_header(); + 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(","); + write_gps(record); out.printf ("\n"); } + void flush_pad() { + while (!pad_records.isEmpty()) { + write_one (pad_records.remove()); + } + } + public void write(AltosRecord record) { if (!header_written) { write_header(); header_written = true; } - write_general(record); out.printf(","); - write_flight(record); - out.printf ("\n"); + if (!seen_boost) { + if (record.state >= Altos.ao_flight_boost) { + seen_boost = true; + boost_tick = record.tick; + flush_pad(); + } + } + if (seen_boost) + write_one(record); + else + pad_records.add(record); } public PrintStream out() { return out; } + public void close() { + if (!pad_records.isEmpty()) { + boost_tick = pad_records.element().tick; + flush_pad(); + } + out.close(); + } + + public void write(AltosReader reader) { + AltosRecord record; + + reader.write_comments(out()); + try { + for (;;) { + record = reader.read(); + if (record == null) + break; + write(record); + } + } catch (IOException ie) { + } catch (ParseException pe) { + } + } + public AltosCSV(File in_name) throws FileNotFoundException { name = in_name; out = new PrintStream(name); + pad_records = new LinkedList(); } } diff --git a/ao-tools/altosui/AltosCSVUI.java b/ao-tools/altosui/AltosCSVUI.java new file mode 100644 index 00000000..2d812361 --- /dev/null +++ b/ao-tools/altosui/AltosCSVUI.java @@ -0,0 +1,83 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosLogfileChooser; +import altosui.AltosCSV; + +public class AltosCSVUI + extends JDialog + implements Runnable, ActionListener +{ + JFrame frame; + Thread thread; + AltosReader reader; + AltosCSV writer; + + public void run() { + AltosLogfileChooser chooser; + + chooser = new AltosLogfileChooser(frame); + reader = chooser.runDialog(); + if (reader == null) + return; + JFileChooser csv_chooser; + + File file = chooser.file(); + String path = file.getPath(); + int dot = path.lastIndexOf("."); + if (dot >= 0) + path = path.substring(0,dot); + path = path.concat(".csv"); + csv_chooser = new JFileChooser(path); + int ret = csv_chooser.showSaveDialog(frame); + if (ret == JFileChooser.APPROVE_OPTION) { + try { + writer = new AltosCSV(csv_chooser.getSelectedFile()); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + file.getName(), + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + writer.write(reader); + reader.close(); + writer.close(); + } + } + + public void actionPerformed(ActionEvent e) { + } + + public AltosCSVUI(JFrame in_frame) { + frame = in_frame; + thread = new Thread(this); + thread.start(); + } +} diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index c29fd90b..deab2167 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -218,6 +218,7 @@ public class AltosEepromReader extends AltosReader { case Altos.AO_LOG_PRODUCT: break; case Altos.AO_LOG_SERIAL_NUMBER: + state.serial = record.a; break; case Altos.AO_LOG_SOFTWARE_VERSION: break; @@ -228,6 +229,7 @@ public class AltosEepromReader extends AltosReader { public void write_comments(PrintStream out) { Iterator iterator = records.iterator(); + out.printf("# Comments\n"); while (iterator.hasNext()) { AltosOrderedRecord record = iterator.next(); switch (record.cmd) { @@ -250,7 +252,7 @@ public class AltosEepromReader extends AltosReader { out.printf ("# Accel cal: %d %d\n", record.a, record.b); break; case Altos.AO_LOG_RADIO_CAL: - out.printf ("# Radio cal: %d %d\n", record.a); + out.printf ("# Radio cal: %d\n", record.a); break; case Altos.AO_LOG_MANUFACTURER: out.printf ("# Manufacturer: %s\n", record.data); diff --git a/ao-tools/altosui/AltosLogfileChooser.java b/ao-tools/altosui/AltosLogfileChooser.java index 3e9e4892..36b51de6 100644 --- a/ao-tools/altosui/AltosLogfileChooser.java +++ b/ao-tools/altosui/AltosLogfileChooser.java @@ -35,17 +35,22 @@ import altosui.AltosTelemetryReader; public class AltosLogfileChooser extends JFileChooser { JFrame frame; String filename; + File file; public String filename() { return filename; } + public File file() { + return file; + } + public AltosReader runDialog() { int ret; ret = showOpenDialog(frame); if (ret == APPROVE_OPTION) { - File file = getSelectedFile(); + file = getSelectedFile(); if (file == null) return null; filename = file.getName(); @@ -68,7 +73,7 @@ public class AltosLogfileChooser extends JFileChooser { } public AltosLogfileChooser(JFrame in_frame) { - in_frame = frame; + frame = in_frame; setDialogTitle("Select Flight Record File"); setFileFilter(new FileNameExtensionFilter("Flight data file", "eeprom", diff --git a/ao-tools/altosui/AltosReader.java b/ao-tools/altosui/AltosReader.java index 81779e2b..5be8795d 100644 --- a/ao-tools/altosui/AltosReader.java +++ b/ao-tools/altosui/AltosReader.java @@ -25,4 +25,6 @@ import altosui.AltosRecord; public class AltosReader { public AltosRecord read() throws IOException, ParseException { return null; } + public void close() { } + public void write_comments(PrintStream out) { } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 8a4c753f..63cb486c 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -43,6 +43,7 @@ import altosui.AltosFlightInfoTableModel; import altosui.AltosChannelMenu; import altosui.AltosFlashUI; import altosui.AltosLogfileChooser; +import altosui.AltosCSVUI; import libaltosJNI.*; @@ -545,6 +546,14 @@ public class AltosUI extends JFrame { new AltosEepromDownload(AltosUI.this); } + /* Load a flight log file and write out a CSV file containing + * all of the data in standard units + */ + + private void ExportData() { + new AltosCSVUI(AltosUI.this); + } + /* Create the AltosUI menus */ private void createMenu() { @@ -583,6 +592,14 @@ public class AltosUI extends JFrame { }); menu.add(item); + item = new JMenuItem("Export Data",KeyEvent.VK_F); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ExportData(); + } + }); + menu.add(item); + item = new JMenuItem("Quit",KeyEvent.VK_Q); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index de78b765..1273e7d4 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -8,6 +8,7 @@ CLASSFILES=\ AltosConfigUI.class \ AltosConvert.class \ AltosCSV.class \ + AltosCSVUI.class \ AltosDebug.class \ AltosEepromDownload.class \ AltosEepromMonitor.class \ -- cgit v1.2.3 From 7d44cbd621d2b113ac2b802ef17e3d8a660ce7f2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 03:58:00 -0700 Subject: altosui: disable radio monitoring while using serial line for debugging --- ao-tools/altosui/AltosDebug.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index 83ea5bcb..df40410a 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -97,7 +97,7 @@ public class AltosDebug extends AltosSerial { void ensure_debug_mode() { if (!debug_mode) { - printf("D\n"); + printf("m 0\nD\n"); debug_mode = true; } } -- cgit v1.2.3 From d93787284c8e514a929edb9f944c98ae0206a33f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 03:59:09 -0700 Subject: altosui: Delay mapping Flash UI until flashing actually starts The flash operation may be abandoned before it even starts; this makes sure the UI doesn't flash up on the screen. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlash.java | 1 + ao-tools/altosui/AltosFlashUI.java | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index 0f92d6e7..7aeab89a 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -247,6 +247,7 @@ public class AltosFlash { int flash_addr = image.address; int image_start = 0; + action("start", 0); action(0, image.data.length); while (remain > 0 && !aborted) { int this_time = remain; diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 0c2041e3..b88a16b3 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -57,8 +57,10 @@ public class AltosFlashUI } else { String cmd = e.getActionCommand(); if (cmd.equals("done")) - dispose(); - else { + ; + else if (cmd.equals("start")) { + setVisible(true); + } else { pbar.setValue(e.getID()); pbar.setString(cmd); } @@ -88,15 +90,14 @@ public class AltosFlashUI "Cannot open image", file.toString(), JOptionPane.ERROR_MESSAGE); - return; } catch (IOException e) { JOptionPane.showMessageDialog(frame, e.getMessage(), file.toString(), JOptionPane.ERROR_MESSAGE); - return; } catch (InterruptedException ie) { } + dispose(); } public void abort() { -- cgit v1.2.3 From f62b2aa08ebfd912b3c732397d43ff9f6162ec88 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 04:01:14 -0700 Subject: altosui: fetch existing romconfig for flashing --- ao-tools/altosui/AltosFlash.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index 7aeab89a..b7018555 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -315,6 +315,8 @@ public class AltosFlash { } public AltosRomconfig romconfig() { + if (!check_rom_config()) + return null; return rom_config; } -- cgit v1.2.3 From 220f3afdaa432c65f8ad45be7cdbe5c8a3616db3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 04:01:47 -0700 Subject: altosui: always display romconfig ui while flashing --- ao-tools/altosui/AltosFlashUI.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index b88a16b3..73a97a6b 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -72,14 +72,15 @@ public class AltosFlashUI flash.addActionListener(this); try { flash.open(); - if (!flash.check_rom_config()) { - AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); - romconfig_ui.showDialog(); - AltosRomconfig romconfig = romconfig_ui.romconfig(); - if (romconfig == null) - return; - flash.set_romconfig(romconfig); - } + AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); + + romconfig_ui.set(flash.romconfig()); + romconfig_ui.showDialog(); + + AltosRomconfig romconfig = romconfig_ui.romconfig(); + if (romconfig == null || !romconfig.valid()) + return; + flash.set_romconfig(romconfig); serial_value.setText(String.format("%d", flash.romconfig().serial_number)); file_value.setText(file.toString()); -- cgit v1.2.3 From ba086cc77273efe5397f60dcaccd1e3771441481 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 04:02:27 -0700 Subject: altosui: write USB serial number string while flashing USB serial number is encoded in UCS2 as a part of the string descriptors. Place those right after the other rom config bits so that altosui can find it. altosui is changed to write the serial number there. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosRomconfig.java | 49 +++++++++++++++++++++++++++++++++- ao-tools/altosui/AltosRomconfigUI.java | 21 ++++++++++++++- src/ao.h | 5 ++-- src/ao_product.c | 2 +- 4 files changed, 72 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java index 844da7c4..8c9cb27a 100644 --- a/ao-tools/altosui/AltosRomconfig.java +++ b/ao-tools/altosui/AltosRomconfig.java @@ -47,14 +47,57 @@ public class AltosRomconfig { } } + static void put_string(String value, byte[] bytes, int start) { + for (int i = 0; i < value.length(); i++) + bytes[start + i] = (byte) value.charAt(i); + } + + static final int AO_USB_DESC_STRING = 3; + + static void put_usb_serial(int value, byte[] bytes, int start) { + int offset = start + 0xa; + int string_num = 0; + System.out.printf("Put usb serial %d\n", value); + + while (offset < bytes.length && bytes[offset] != 0) { + if (bytes[offset + 1] == AO_USB_DESC_STRING) { + ++string_num; + if (string_num == 4) + break; + } + offset += ((int) bytes[offset]) & 0xff; + } + System.out.printf("offset %d content %d\n", + offset, bytes[offset]); + if (offset >= bytes.length || bytes[offset] == 0) + return; + int len = ((((int) bytes[offset]) & 0xff) - 2) / 2; + String fmt = String.format("%%0%dd", len); + System.out.printf("existing serial length %d format %s\n", len, fmt); + + String s = String.format(fmt, value); + if (s.length() != len) { + System.out.printf("weird usb length issue %s isn't %d\n", + s, len); + return; + } + for (int i = 0; i < len; i++) { + bytes[offset + 2 + i*2] = (byte) s.charAt(i); + bytes[offset + 2 + i*2+1] = 0; + } + } + public AltosRomconfig(byte[] bytes, int offset) { version = get_int(bytes, offset + 0, 2); check = get_int(bytes, offset + 2, 2); + System.out.printf("version %d check %d\n", version, check); if (check == (~version & 0xffff)) { switch (version) { + case 2: case 1: serial_number = get_int(bytes, offset + 4, 2); radio_calibration = get_int(bytes, offset + 6, 4); + System.out.printf("serial %d cal %d\n", serial_number, radio_calibration); valid = true; break; } @@ -77,6 +120,8 @@ public class AltosRomconfig { throw new IOException("image does not contain existing rom config"); switch (existing.version) { + case 2: + put_usb_serial(serial_number, bytes, offset); case 1: put_int(serial_number, bytes, offset + 4, 2); put_int(radio_calibration, bytes, offset + 6, 4); @@ -86,7 +131,9 @@ public class AltosRomconfig { public void write (AltosHexfile hexfile) throws IOException { write(hexfile.data, 0xa0 - hexfile.address); - new AltosRomconfig(hexfile); + AltosRomconfig check = new AltosRomconfig(hexfile); + if (!check.valid()) + throw new IOException("writing new rom config failed\n"); } public AltosRomconfig(int in_serial_number, int in_radio_calibration) { diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java index 21c34ef4..bc511865 100644 --- a/ao-tools/altosui/AltosRomconfigUI.java +++ b/ao-tools/altosui/AltosRomconfigUI.java @@ -143,12 +143,31 @@ public class AltosRomconfigUI return Integer.parseInt(serial_value.getText()); } + void set_serial(int serial) { + serial_value.setText(String.format("%d", serial)); + } + int radio_calibration() { return Integer.parseInt(radio_calibration_value.getText()); } + void set_radio_calibration(int calibration) { + radio_calibration_value.setText(String.format("%d", calibration)); + } + + public void set(AltosRomconfig config) { + if (config != null && config.valid()) { + set_serial(config.serial_number); + set_radio_calibration(config.radio_calibration); + } + } + public AltosRomconfig romconfig() { - return new AltosRomconfig(serial(), radio_calibration()); + try { + return new AltosRomconfig(serial(), radio_calibration()); + } catch (NumberFormatException ne) { + return null; + } } public AltosRomconfig showDialog() { diff --git a/src/ao.h b/src/ao.h index 9c418db2..d289ced1 100644 --- a/src/ao.h +++ b/src/ao.h @@ -293,12 +293,13 @@ ao_led_init(uint8_t enable); * ao_romconfig.c */ -#define AO_ROMCONFIG_VERSION 1 +#define AO_ROMCONFIG_VERSION 2 extern __code __at (0x00a0) uint16_t ao_romconfig_version; extern __code __at (0x00a2) uint16_t ao_romconfig_check; extern __code __at (0x00a4) uint16_t ao_serial_number; extern __code __at (0x00a6) uint32_t ao_radio_cal; +extern __code __at (0x00aa) uint8_t ao_usb_descriptors []; /* * ao_usb.c @@ -1008,7 +1009,7 @@ ao_rssi_init(uint8_t rssi_led); * each instance of a product */ -extern const uint8_t ao_usb_descriptors []; +extern __code __at(0x00aa) uint8_t ao_usb_descriptors []; extern const char ao_version[]; extern const char ao_manufacturer[]; extern const char ao_product[]; diff --git a/src/ao_product.c b/src/ao_product.c index f0eb4c07..82d6298f 100644 --- a/src/ao_product.c +++ b/src/ao_product.c @@ -28,7 +28,7 @@ const char ao_product[] = AO_iProduct_STRING; #define LE_WORD(x) ((x)&0xFF),((uint8_t) (((uint16_t) (x))>>8)) /* USB descriptors in one giant block of bytes */ -const uint8_t ao_usb_descriptors [] = +__code __at(0x00aa) uint8_t ao_usb_descriptors [] = { /* Device descriptor */ 0x12, -- cgit v1.2.3 From 99400fdc0f19ef538fc362dde5c3ab5b7cdac409 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 16:43:38 -0700 Subject: altosui: flush replies from serial link when entering debug mode We use replies in debug mode a lot and depend on them matching the expected parameters. The case which caused trouble was using TeleMetrum to reprogram TeleDongle -- sending the 'm 0' command (to disable telemetry monitoring on TeleDongle) to the TeleMetrum caused it to reply 'Syntax Error' which confused the subsequent flashing operation. Flushing that reply gets things back in sync. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDebug.java | 1 + ao-tools/altosui/AltosSerial.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index df40410a..06c9a0bd 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -98,6 +98,7 @@ public class AltosDebug extends AltosSerial { void ensure_debug_mode() { if (!debug_mode) { printf("m 0\nD\n"); + flush_reply(); debug_mode = true; } } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index d02e25a9..3684f253 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -66,8 +66,10 @@ public class AltosSerial implements Runnable { LinkedBlockingQueue q = monitors.get(e); q.put(line); } - } else + } else { +// System.out.printf("GOT: %s\n", line); reply_queue.put(line); + } line = ""; } } else { @@ -80,6 +82,11 @@ public class AltosSerial implements Runnable { } public void flush_reply() { + libaltos.altos_flush(altos); + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + } reply_queue.clear(); } @@ -132,6 +139,7 @@ public class AltosSerial implements Runnable { } public void print(String data) { +// System.out.printf("\"%s\" ", data); for (int i = 0; i < data.length(); i++) putc(data.charAt(i)); } -- cgit v1.2.3 From f0fd423d0bf83bc5c3f9d39e9c09397fbe8caed2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:41:26 -0700 Subject: altosui: Move number parsing code to Altos general class This moves these shared functions to the global shared class. Signed-off-by: Keith Packard --- ao-tools/altosui/Altos.java | 86 ++++++++++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosDebug.java | 43 ++------------------ ao-tools/altosui/AltosParse.java | 10 ++++- 3 files changed, 98 insertions(+), 41 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java index 53359e23..07bd01ae 100644 --- a/ao-tools/altosui/Altos.java +++ b/ao-tools/altosui/Altos.java @@ -114,4 +114,90 @@ public class Altos { static final int AO_GPS_DATE_VALID = (1 << 6); static final int AO_GPS_NUM_SAT_SHIFT = 0; static final int AO_GPS_NUM_SAT_MASK = 0xf; + + static boolean isspace(int c) { + switch (c) { + case ' ': + case '\t': + return true; + } + return false; + } + + static boolean ishex(int c) { + if ('0' <= c && c <= '9') + return true; + if ('a' <= c && c <= 'f') + return true; + if ('A' <= c && c <= 'F') + return true; + return false; + } + + static boolean ishex(String s) { + for (int i = 0; i < s.length(); i++) + if (!ishex(s.charAt(i))) + return false; + return true; + } + + static int fromhex(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - 'a' + 10; + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + return -1; + } + + static int fromhex(String s) throws NumberFormatException { + int c, v = 0; + for (int i = 0; i < s.length(); i++) { + c = s.charAt(i); + if (!ishex(c)) { + if (i == 0) + throw new NumberFormatException(String.format("invalid hex \"%s\"", s)); + return v; + } + v = v * 16 + fromhex(c); + } + return v; + } + + static boolean isdec(int c) { + if ('0' <= c && c <= '9') + return true; + return false; + } + + static boolean isdec(String s) { + for (int i = 0; i < s.length(); i++) + if (!isdec(s.charAt(i))) + return false; + return true; + } + + static int fromdec(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + return -1; + } + + static int fromdec(String s) throws NumberFormatException { + int c, v = 0; + int sign = 1; + for (int i = 0; i < s.length(); i++) { + c = s.charAt(i); + if (i == 0 && c == '-') { + sign = -1; + } else if (!isdec(c)) { + if (i == 0) + throw new NumberFormatException(String.format("invalid number \"%s\"", s)); + return v; + } else + v = v * 10 + fromdec(c); + } + return v * sign; + } } diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index 06c9a0bd..ca2e5a90 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -58,41 +58,6 @@ public class AltosDebug extends AltosSerial { public static final byte GET_CHIP_ID = 0x68; - static boolean ishex(int c) { - if ('0' <= c && c <= '9') - return true; - if ('a' <= c && c <= 'f') - return true; - if ('A' <= c && c <= 'F') - return true; - return false; - } - - static boolean ishex(String s) { - for (int i = 0; i < s.length(); i++) - if (!ishex(s.charAt(i))) - return false; - return true; - } - static boolean isspace(int c) { - switch (c) { - case ' ': - case '\t': - return true; - } - return false; - } - - static int fromhex(int c) { - if ('0' <= c && c <= '9') - return c - '0'; - if ('a' <= c && c <= 'f') - return c - 'a' + 10; - if ('A' <= c && c <= 'F') - return c - 'A' + 10; - return -1; - } - boolean debug_mode; void ensure_debug_mode() { @@ -145,14 +110,14 @@ public class AltosDebug extends AltosSerial { int start = 0; while (i < length) { String line = get_reply().trim(); - if (!ishex(line) || line.length() % 2 != 0) + if (!Altos.ishex(line) || line.length() % 2 != 0) throw new IOException( String.format ("Invalid reply \"%s\"", line)); int this_time = line.length() / 2; for (int j = 0; j < this_time; j++) - data[start + j] = (byte) ((fromhex(line.charAt(j*2)) << 4) + - fromhex(line.charAt(j*2+1))); + data[start + j] = (byte) ((Altos.fromhex(line.charAt(j*2)) << 4) + + Altos.fromhex(line.charAt(j*2+1))); start += this_time; i += this_time; } @@ -199,7 +164,7 @@ public class AltosDebug extends AltosSerial { String line = get_reply().trim(); String tokens[] = line.split("\\s+"); for (int j = 0; j < tokens.length; j++) { - if (!ishex(tokens[j]) || + if (!Altos.ishex(tokens[j]) || tokens[j].length() != 2) throw new IOException( String.format diff --git a/ao-tools/altosui/AltosParse.java b/ao-tools/altosui/AltosParse.java index a60dc694..4d82de78 100644 --- a/ao-tools/altosui/AltosParse.java +++ b/ao-tools/altosui/AltosParse.java @@ -20,10 +20,16 @@ package altosui; import java.text.*; import java.lang.*; +import altosui.Altos; + public class AltosParse { + static boolean isdigit(char c) { + return '0' <= c && c <= '9'; + } + static int parse_int(String v) throws ParseException { try { - return Integer.parseInt(v); + return Altos.fromdec(v); } catch (NumberFormatException e) { throw new ParseException("error parsing int " + v, 0); } @@ -31,7 +37,7 @@ public class AltosParse { static int parse_hex(String v) throws ParseException { try { - return Integer.parseInt(v, 16); + return Altos.fromhex(v); } catch (NumberFormatException e) { throw new ParseException("error parsing hex " + v, 0); } -- cgit v1.2.3 From 3dc67c1401976d6e9e2e942d5a4707a4810a0404 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:43:00 -0700 Subject: altosui: Add AltosGreatCircle constructors This adds constructurs from AltosGPS pairs and also one from empty args (which defines both distance and bearing as 0). Signed-off-by: Keith Packard --- ao-tools/altosui/AltosGreatCircle.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosGreatCircle.java b/ao-tools/altosui/AltosGreatCircle.java index 878da03e..07c02c16 100644 --- a/ao-tools/altosui/AltosGreatCircle.java +++ b/ao-tools/altosui/AltosGreatCircle.java @@ -17,6 +17,8 @@ package altosui; +import altosui.AltosGPS; + import java.lang.Math; public class AltosGreatCircle { @@ -28,8 +30,8 @@ public class AltosGreatCircle { static final double rad = Math.PI / 180; static final double earth_radius = 6371.2 * 1000; /* in meters */ - AltosGreatCircle (double start_lat, double start_lon, - double end_lat, double end_lon) + public AltosGreatCircle (double start_lat, double start_lon, + double end_lat, double end_lon) { double lat1 = rad * start_lat; double lon1 = rad * -start_lon; @@ -63,4 +65,13 @@ public class AltosGreatCircle { distance = d * earth_radius; bearing = course * 180/Math.PI; } + + public AltosGreatCircle(AltosGPS start, AltosGPS end) { + this(start.lat, start.lon, end.lat, end.lon); + } + + public AltosGreatCircle() { + distance = 0; + bearing = 0; + } } -- cgit v1.2.3 From 651f6102ac79459fc8d5679d852c963dcb5bb3fc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:44:25 -0700 Subject: altosui: add rssi and distance/dir from pad to CSV files Just adds a couple more fields to the CSV files that might be interesting. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index f12c0348..db50e7a2 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -44,6 +44,7 @@ public class AltosCSV { * flight number * callsign * time (seconds since boost) + * rssi * * Flight status * state @@ -74,6 +75,8 @@ public class AltosCSV { * hour (0-23) * minute (0-59) * second (0-59) + * from_pad_dist (m) + * from_pad_dir (deg true) * * GPS Sat data * hdop @@ -81,13 +84,14 @@ public class AltosCSV { */ void write_general_header() { - out.printf("version serial flight call time"); + out.printf("version serial flight call time rssi"); } void write_general(AltosRecord record) { - out.printf("%s,%d,%d,%s,%8.2f", + out.printf("%s,%d,%d,%s,%8.2f,%4d", record.version, record.serial, record.flight, record.callsign, - (double) (record.tick - boost_tick) / 100.0); + (double) record.time, + record.rssi); } void write_flight_header() { @@ -117,7 +121,7 @@ public class AltosCSV { } void write_gps_header() { - out.printf("connected locked nsat latitude longitude altitude year month day hour minute second"); + out.printf("connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_dir"); } void write_gps(AltosRecord record) { @@ -125,7 +129,11 @@ public class AltosCSV { if (gps == null) gps = new AltosGPS(); - out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d", + AltosGreatCircle from_pad = state.from_pad; + 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,%4.0f", gps.connected?1:0, gps.locked?1:0, gps.nsat, @@ -137,7 +145,9 @@ public class AltosCSV { gps.day, gps.hour, gps.minute, - gps.second); + gps.second, + from_pad.distance, + from_pad.bearing); } void write_header() { @@ -205,7 +215,9 @@ public class AltosCSV { write(record); } } catch (IOException ie) { + System.out.printf("IOException\n"); } catch (ParseException pe) { + System.out.printf("ParseException %s\n", pe.getMessage()); } } @@ -214,4 +226,8 @@ public class AltosCSV { out = new PrintStream(name); pad_records = new LinkedList(); } + + public AltosCSV(String in_string) throws FileNotFoundException { + this(new File(in_string)); + } } -- cgit v1.2.3 From e383595cd281687de903fb6176564bbef270cb83 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:47:38 -0700 Subject: altosui: AltosEepromReader was mis-setting boost tick It was supposed to use record.tick instead of the (unset) state.tick value. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index deab2167..3f2d4c62 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -133,8 +133,6 @@ public class AltosEepromReader extends AltosReader { ground_pres += state.pres; state.ground_pres = (int) (ground_pres / n_pad_samples); state.flight_pres = state.ground_pres; - System.out.printf("ground pressure %d altitude %f\n", - record.b, state.altitude()); ground_accel += state.accel; state.ground_accel = (int) (ground_accel / n_pad_samples); state.flight_accel = state.ground_accel; @@ -156,7 +154,6 @@ public class AltosEepromReader extends AltosReader { seen |= seen_deploy; break; case Altos.AO_LOG_STATE: - System.out.printf("state %d\n", record.a); state.state = record.a; break; case Altos.AO_LOG_GPS_TIME: @@ -298,10 +295,10 @@ public class AltosEepromReader extends AltosReader { break; tick = record.tick; if (!saw_boost && record.cmd == Altos.AO_LOG_STATE && - record.a == Altos.ao_flight_boost) + record.a >= Altos.ao_flight_boost) { saw_boost = true; - boost_tick = state.tick; + boost_tick = tick; } records.add(record); } -- cgit v1.2.3 From 0942912163255523d923140c01afbdb5da1c19b5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:49:37 -0700 Subject: altosui: Add support for old (version < 3) telemetry files This lets the code read telemetry files from pre-released versions of the software. Not strictly necessary for production, but useful for analysing old files. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosGPS.java | 61 ++++++++++++++++++++++-------------- ao-tools/altosui/AltosTelemetry.java | 34 ++++++++++++++------ 2 files changed, 63 insertions(+), 32 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index b3ee67e8..acb6fb2c 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -52,14 +52,16 @@ public class AltosGPS { AltosGPSSat[] cc_gps_sat; /* tracking data */ - void ParseGPSTime(String date, String time) throws ParseException { + void ParseGPSDate(String date) throws ParseException { String[] ymd = date.split("-"); if (ymd.length != 3) throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); year = AltosParse.parse_int(ymd[0]); month = AltosParse.parse_int(ymd[1]); day = AltosParse.parse_int(ymd[2]); + } + void ParseGPSTime(String time) throws ParseException { String[] hms = time.split(":"); if (hms.length != 3) throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); @@ -73,7 +75,7 @@ public class AltosGPS { hour = minute = second = 0; } - public AltosGPS(String[] words, int i) throws ParseException { + public AltosGPS(String[] words, int i, int version) throws ParseException { AltosParse.word(words[i++], "GPS"); nsat = AltosParse.parse_int(words[i++]); AltosParse.word(words[i++], "sat"); @@ -92,32 +94,44 @@ public class AltosGPS { locked = true; connected = true; - ParseGPSTime(words[i], words[i+1]); i += 2; + if (version > 1) + ParseGPSDate(words[i++]); + else + year = month = day = 0; + ParseGPSTime(words[i++]); lat = AltosParse.parse_coord(words[i++]); lon = AltosParse.parse_coord(words[i++]); - alt = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "m")); - ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)")); - course = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "°")); - climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)")); - hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)")); - h_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(herr)")); - v_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(verr)")); + alt = AltosParse.parse_int(words[i++]); + if (version > 1 || (i < words.length && !words[i].equals("SAT"))) { + ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)")); + course = AltosParse.parse_int(words[i++]); + climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)")); + hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)")); + h_error = AltosParse.parse_int(words[i++]); + v_error = AltosParse.parse_int(words[i++]); + } } else { i++; } - AltosParse.word(words[i++], "SAT"); - int tracking_channels = 0; - if (words[i].equals("not-connected")) - tracking_channels = 0; - else - tracking_channels = AltosParse.parse_int(words[i]); - i++; - cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels]; - for (int chan = 0; chan < tracking_channels; chan++) { - cc_gps_sat[chan] = new AltosGPS.AltosGPSSat(); - cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]); - cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]); - } + if (i < words.length) { + AltosParse.word(words[i++], "SAT"); + int tracking_channels = 0; + if (words[i].equals("not-connected")) + tracking_channels = 0; + else + tracking_channels = AltosParse.parse_int(words[i]); + i++; + cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels]; + for (int chan = 0; chan < tracking_channels; chan++) { + cc_gps_sat[chan] = new AltosGPS.AltosGPSSat(); + cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]); + /* Older versions included SiRF status bits */ + if (version < 2) + i++; + cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]); + } + } else + cc_gps_sat = new AltosGPS.AltosGPSSat[0]; } public void set_latitude(int in_lat) { @@ -172,6 +186,7 @@ public class AltosGPS { nsat = old.nsat; locked = old.locked; connected = old.connected; + date_valid = old.date_valid; lat = old.lat; /* degrees (+N -S) */ lon = old.lon; /* degrees (+E -W) */ alt = old.alt; /* m */ diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index af29b8c0..bc62690b 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -57,8 +57,12 @@ public class AltosTelemetry extends AltosRecord { String[] words = line.split("\\s+"); int i = 0; - AltosParse.word (words[i++], "VERSION"); - version = AltosParse.parse_int(words[i++]); + if (words[i].equals("CALL")) { + version = 0; + } else { + AltosParse.word (words[i++], "VERSION"); + version = AltosParse.parse_int(words[i++]); + } AltosParse.word (words[i++], "CALL"); callsign = words[i++]; @@ -66,12 +70,19 @@ public class AltosTelemetry extends AltosRecord { AltosParse.word (words[i++], "SERIAL"); serial = AltosParse.parse_int(words[i++]); - AltosParse.word (words[i++], "FLIGHT"); - flight = 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++]); @@ -113,12 +124,17 @@ public class AltosTelemetry extends AltosRecord { AltosParse.word(words[i++], "gp:"); ground_pres = AltosParse.parse_int(words[i++]); - AltosParse.word(words[i++], "a+:"); - accel_plus_g = 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++]); + 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); + gps = new AltosGPS(words, i, version); } } -- cgit v1.2.3 From a16db143fc7ca72dc91e7989420049192114642d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:50:51 -0700 Subject: altosui: Serial line is in UTF-8 encoding. Deal with it. We read bytes from the serial line and need to convert each line into a string. So, save the bytes and at EOL, pass the whole mess to the string constructor with the appropriate encoding info. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 3684f253..5b47960f 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -45,6 +45,8 @@ public class AltosSerial implements Runnable { LinkedBlockingQueue reply_queue; Thread input_thread; String line; + byte[] line_bytes; + int line_count; public void run () { int c; @@ -60,7 +62,14 @@ public class AltosSerial implements Runnable { continue; synchronized(this) { if (c == '\n') { - if (line != "") { + if (line_count != 0) { + try { + line = new String(line_bytes, 0, line_count, "UTF-8"); + } catch (UnsupportedEncodingException ue) { + line = ""; + for (int i = 0; i < line_count; i++) + line = line + line_bytes[i]; + } if (line.startsWith("VERSION")) { for (int e = 0; e < monitors.size(); e++) { LinkedBlockingQueue q = monitors.get(e); @@ -70,10 +79,19 @@ public class AltosSerial implements Runnable { // System.out.printf("GOT: %s\n", line); reply_queue.put(line); } + line_count = 0; line = ""; } } else { - line = line + (char) c; + if (line_bytes == null) { + line_bytes = new byte[256]; + } else if (line_count == line_bytes.length) { + byte[] new_line_bytes = new byte[line_count * 2]; + System.arraycopy(line_bytes, 0, new_line_bytes, 0, line_count); + line_bytes = new_line_bytes; + } + line_bytes[line_count] = (byte) c; + line_count++; } } } @@ -139,7 +157,7 @@ public class AltosSerial implements Runnable { } public void print(String data) { -// System.out.printf("\"%s\" ", data); +//h System.out.printf("\"%s\" ", data); for (int i = 0; i < data.length(); i++) putc(data.charAt(i)); } -- cgit v1.2.3 From 49364608b59de7421ab00d87d2685bc3b5f58411 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:53:06 -0700 Subject: altosui: When parsing saved telem files, errors shouldn't abort file Make syntax errors in telem files just skip the current line and move on to the next one instead of abandoning the whole file. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosTelemetryReader.java | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index f1f6788c..a3402f9c 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -47,20 +47,25 @@ public class AltosTelemetryReader extends AltosReader { try { for (;;) { String line = AltosRecord.gets(input); - if (line == null) + if (line == null) { break; - AltosTelemetry record = new AltosTelemetry(line); - if (record == null) - break; - if (!saw_boost && record.state >= Altos.ao_flight_boost) - { - saw_boost = true; - boost_tick = record.tick; } - records.add(record); + try { + AltosTelemetry record = new AltosTelemetry(line); + if (record == null) + break; + if (!saw_boost && record.state >= Altos.ao_flight_boost) + { + saw_boost = true; + boost_tick = record.tick; + } + records.add(record); + } catch (ParseException pe) { + System.out.printf("parse exception %s\n", pe.getMessage()); + } } } catch (IOException io) { - } catch (ParseException pe) { + System.out.printf("io exception\n"); } record_iterator = records.iterator(); try { -- cgit v1.2.3 From 7e0506dc2014b7178f52b950e8c1cb820b35f9c6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:54:53 -0700 Subject: altosui: Remove debug printf from AltosState.java Signed-off-by: Keith Packard --- ao-tools/altosui/AltosState.java | 5 ----- 1 file changed, 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index deeb4c77..c13dfe68 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -124,11 +124,6 @@ public class AltosState { } if (state == Altos.ao_flight_pad) { - if (data.gps == null) - System.out.printf("on pad, gps null\n"); - else - System.out.printf ("on pad gps lat %f lon %f locked %d nsat %d\n", - data.gps.lat, data.gps.lon, data.gps.locked ? 1 : 0, data.gps.nsat); if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) { npad++; if (npad > 1) { -- cgit v1.2.3 From 68967157cee620ebedcc8c2ffd6fc7656532087b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:55:44 -0700 Subject: altosui: command line args are converted to csv format Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 63 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 63cb486c..4f3b5dde 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -719,8 +719,67 @@ public class AltosUI extends JFrame { this.setJMenuBar(menubar); } + + static String replace_extension(String input, String extension) { + int dot = input.lastIndexOf("."); + if (dot > 0) + input = input.substring(0,dot); + return input.concat(extension); + } + + static AltosReader open_logfile(String filename) { + File file = new File (filename); + try { + FileInputStream in; + + in = new FileInputStream(file); + if (filename.endsWith("eeprom")) + return new AltosEepromReader(in); + else + return new AltosTelemetryReader(in); + } catch (FileNotFoundException fe) { + System.out.printf("Cannot open '%s'\n", filename); + return null; + } + } + + static AltosCSV open_csv(String filename) { + File file = new File (filename); + try { + return new AltosCSV(file); + } catch (FileNotFoundException fe) { + System.out.printf("Cannot open '%s'\n", filename); + return null; + } + } + + static void process_file(String input) { + String output = replace_extension(input,".csv"); + if (input.equals(output)) { + System.out.printf("Not processing '%s'\n", input); + return; + } + System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); + AltosReader reader = open_logfile(input); + if (reader == null) + return; + AltosCSV writer = open_csv(output); + if (writer == null) + return; + writer.write(reader); + reader.close(); + writer.close(); + } + public static void main(final String[] args) { - AltosUI altosui = new AltosUI(); - altosui.setVisible(true); + + /* Handle batch-mode */ + if (args.length > 0) { + for (int i = 0; i < args.length; i++) + process_file(args[i]); + } else { + AltosUI altosui = new AltosUI(); + altosui.setVisible(true); + } } } \ No newline at end of file -- cgit v1.2.3 From 9ea94411c9730f7a271366d309ab4827beeeb839 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 11:17:54 -0600 Subject: add a dummy install target --- ao-tools/libaltos/Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index a251e54e..9933dc80 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -1,5 +1,8 @@ OS:=$(shell uname) +# dummy install target for now so I can work on the rest of the packaging +install: + @echo warning - make install doing nothing in libaltos! # # Linux # -- cgit v1.2.3 From 72c33a72ee105ec692dad62d6d9c1ad40b89bfe8 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 11:45:19 -0600 Subject: add install target for libaltos --- ao-tools/libaltos/Makefile | 6 +++--- debian/dirs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 9933dc80..cd96fd5f 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -1,8 +1,5 @@ OS:=$(shell uname) -# dummy install target for now so I can work on the rest of the packaging -install: - @echo warning - make install doing nothing in libaltos! # # Linux # @@ -17,6 +14,9 @@ OS_LDFLAGS= LIBNAME=libaltos.so EXEEXT= +install: $(LIBNAME) + /usr/bin/install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) + endif # diff --git a/debian/dirs b/debian/dirs index db75fea7..6bf06c6e 100644 --- a/debian/dirs +++ b/debian/dirs @@ -1,5 +1,6 @@ etc/apt/sources.list.d usr/bin +usr/lib/altos usr/share/altos usr/share/applications usr/share/gdm/themes/altusmetrum -- cgit v1.2.3 From 72a18502e40f55cbba6418dc94315517881cd411 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 11:51:24 -0600 Subject: add an install target for altosui --- ao-tools/altosui/Makefile | 7 ++++++- debian/dirs | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index d3ecb889..258a334f 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -96,8 +96,13 @@ endif ifeq ($(OS),Linux) altosui: echo "#!/bin/sh" > $@ - echo "exec java -Djava.library.path=../libaltos -jar altosui.jar" >> $@ + echo "exec java -Djava.library.path=/usr/lib/altos/libaltos -jar altosui.jar" >> $@ chmod +x ./altosui + +install: altosui.jar altosui + /usr/bin/install -c altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + /usr/bin/install -c altosui $(DESTDIR)/usr/bin/altosui + endif clean: diff --git a/debian/dirs b/debian/dirs index 6bf06c6e..7b4dffb8 100644 --- a/debian/dirs +++ b/debian/dirs @@ -4,5 +4,6 @@ usr/lib/altos usr/share/altos usr/share/applications usr/share/gdm/themes/altusmetrum +usr/share/java usr/share/pixmaps usr/share/slim/themes/altusmetrum -- cgit v1.2.3 From 63bd34cd1b5a411489e8c3ab377f0fe0eec11f67 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 27 Aug 2010 10:58:55 -0700 Subject: altosui: add elevation and range information Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 12 ++-- ao-tools/altosui/AltosEepromReader.java | 99 ++++++++++++++++++++++++++++++++- ao-tools/altosui/AltosEepromRecord.java | 9 ++- ao-tools/altosui/AltosState.java | 13 ++++- ao-tools/altosui/AltosUI.java | 22 ++++++-- 5 files changed, 142 insertions(+), 13 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index db50e7a2..4ce8e30e 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -76,7 +76,9 @@ public class AltosCSV { * minute (0-59) * second (0-59) * from_pad_dist (m) - * from_pad_dir (deg true) + * from_pad_azimuth (deg true) + * from_pad_range (m) + * from_pad_elevation (deg from horizon) * * GPS Sat data * hdop @@ -121,7 +123,7 @@ public class AltosCSV { } void write_gps_header() { - out.printf("connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_dir"); + out.printf("connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_range pad_az pad_el"); } void write_gps(AltosRecord record) { @@ -133,7 +135,7 @@ public class AltosCSV { 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,%4.0f", + out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d,%9.0f,%9.0f,%4.0f,%4.0f", gps.connected?1:0, gps.locked?1:0, gps.nsat, @@ -147,7 +149,9 @@ public class AltosCSV { gps.minute, gps.second, from_pad.distance, - from_pad.bearing); + state.range, + from_pad.bearing, + state.elevation); } void write_header() { diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 3f2d4c62..0705d44e 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -42,7 +42,7 @@ import altosui.AltosEepromMonitor; */ class AltosOrderedRecord extends AltosEepromRecord implements Comparable { - int index; + public int index; public AltosOrderedRecord(String line, int in_index, int prev_tick) throws ParseException { @@ -56,6 +56,11 @@ class AltosOrderedRecord extends AltosEepromRecord implements Comparable> Altos.AO_GPS_NUM_SAT_SHIFT; + System.out.printf("GPS %2d:%02d:%02d%s%s%s %d\n", + state.gps.hour, state.gps.minute, state.gps.second, + state.gps.connected ? " connected" : "", + state.gps.locked ? " locked" : "", + state.gps.date_valid ? " date_valid" : "", + state.gps.nsat); break; case Altos.AO_LOG_GPS_LAT: int lat32 = record.a | (record.b << 16); @@ -267,6 +282,38 @@ public class AltosEepromReader extends AltosReader { } } + /* + * 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; + + 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); + + System.out.printf("Synthesizing time good %2d:%02d:%02d bad %2d:%02d:%02d\n", + hour, minute, second, + new_hour, new_minute, new_second); + + bad.a = new_hour + (new_minute << 8); + bad.b = new_second + (flags << 8); + } + /* * Read the whole file, dumping records into a RB tree so * we can enumerate them in time order -- the eeprom data @@ -282,9 +329,13 @@ public class AltosEepromReader extends AltosReader { seen = 0; records = new TreeSet(); + AltosOrderedRecord last_gps_time = null; + int index = 0; int tick = 0; + boolean missing_time = false; + try { for (;;) { String line = AltosRecord.gets(input); @@ -300,6 +351,52 @@ public class AltosEepromReader extends AltosReader { saw_boost = true; boost_tick = tick; } + + /* 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 == Altos.AO_LOG_GPS_DATE) + saw_gps_date = true; + + /* go back and fix up any missing time values */ + if (record.cmd == Altos.AO_LOG_GPS_TIME) { + last_gps_time = record; + if (missing_time) { + System.out.printf("Going back to clean up broken GPS time records\n"); + Iterator iterator = records.iterator(); + while (iterator.hasNext()) { + AltosOrderedRecord old = iterator.next(); + if (old.cmd == Altos.AO_LOG_GPS_TIME) { + System.out.printf("Old time record %d, %d\n", old.a, old.b); + } + if (old.cmd == Altos.AO_LOG_GPS_TIME && + old.a == -1 && old.b == -1) + { + update_time(record, old); + } + } + missing_time = false; + } + } + + if (record.cmd == Altos.AO_LOG_GPS_LAT) { + if (last_gps_time == null || last_gps_time.tick != record.tick) { + AltosOrderedRecord add_gps_time = new AltosOrderedRecord(Altos.AO_LOG_GPS_TIME, + record.tick, + -1, -1, index-1); + if (last_gps_time != null) + update_time(last_gps_time, add_gps_time); + else { + System.out.printf("early GPS missing time\n"); + missing_time = true; + } + records.add(add_gps_time); + record.index = index++; + } + } records.add(record); } } catch (IOException io) { diff --git a/ao-tools/altosui/AltosEepromRecord.java b/ao-tools/altosui/AltosEepromRecord.java index 86ac1fd2..4d0817ab 100644 --- a/ao-tools/altosui/AltosEepromRecord.java +++ b/ao-tools/altosui/AltosEepromRecord.java @@ -44,7 +44,7 @@ public class AltosEepromRecord { public int tick; public int a; public int b; - String data; + public String data; public boolean tick_valid; public AltosEepromRecord (String line) throws ParseException { @@ -107,4 +107,11 @@ public class AltosEepromRecord { } } + 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/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index c13dfe68..3ef00f35 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -64,6 +64,8 @@ public class AltosState { boolean gps_ready; AltosGreatCircle from_pad; + double elevation; /* from pad */ + double range; /* total distance */ double gps_height; @@ -124,7 +126,7 @@ public class AltosState { } if (state == Altos.ao_flight_pad) { - if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) { + if (data.gps != null && data.gps.locked) { npad++; if (npad > 1) { /* filter pad position */ @@ -161,11 +163,18 @@ public class AltosState { if (data.gps != null) { if (gps == null || !gps.locked || data.gps.locked) gps = data.gps; - if (npad > 0 && gps.locked) + if (npad > 0 && gps.locked) { from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); + } } + elevation = 0; + range = -1; if (npad > 0) { gps_height = gps.alt - pad_alt; + if (from_pad != null) { + elevation = Math.atan2(height, from_pad.distance) * 180 / Math.PI; + range = Math.sqrt(height * height + from_pad.distance * from_pad.distance); + } } else { gps_height = 0; } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 4f3b5dde..5b48e26f 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -264,7 +264,7 @@ public class AltosUI extends JFrame { private AltosState state; int reported_landing; - public void report(boolean last) { + public synchronized void report(boolean last) { if (state == null) return; @@ -278,7 +278,16 @@ public class AltosUI extends JFrame { } /* If the rocket isn't on the pad, then report height */ - if (state.state > Altos.ao_flight_pad) { + if (Altos.ao_flight_drogue <= state.state && + state.state < Altos.ao_flight_landed && + state.range >= 0) + { + voice.speak("Height %d, bearing %d, elevation %d, range %d.\n", + (int) (state.height + 0.5), + (int) (state.from_pad.bearing + 0.5), + (int) (state.elevation + 0.5), + (int) (state.range + 0.5)); + } else if (state.state > Altos.ao_flight_pad) { voice.speak("%d meters", (int) (state.height + 0.5)); } else { reported_landing = 0; @@ -288,7 +297,7 @@ public class AltosUI extends JFrame { * either we've got a landed report or we haven't heard from it in * a long time */ - if (!state.ascent && + if (state.state >= Altos.ao_flight_drogue && (last || System.currentTimeMillis() - state.report_time >= 15000 || state.state == Altos.ao_flight_landed)) @@ -298,7 +307,7 @@ public class AltosUI extends JFrame { else voice.speak("rocket may have crashed"); if (state.from_pad != null) - voice.speak("bearing %d degrees, range %d meters", + voice.speak("Bearing %d degrees, range %d meters.", (int) (state.from_pad.bearing + 0.5), (int) (state.from_pad.distance + 0.5)); ++reported_landing; @@ -311,7 +320,7 @@ public class AltosUI extends JFrame { state = null; try { for (;;) { - Thread.sleep(10000); + Thread.sleep(20000); report(false); } } catch (InterruptedException ie) { @@ -319,7 +328,10 @@ public class AltosUI extends JFrame { } public void notice(AltosState new_state) { + AltosState old_state = state; state = new_state; + if (old_state != null && old_state.state != state.state) + report(false); } } -- cgit v1.2.3 From c280071b7db4e9a7af31dc5740eb8d27f137950e Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 12:04:13 -0600 Subject: fix up the wrapper's path to the jar file --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 258a334f..73bc230d 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -96,7 +96,7 @@ endif ifeq ($(OS),Linux) altosui: echo "#!/bin/sh" > $@ - echo "exec java -Djava.library.path=/usr/lib/altos/libaltos -jar altosui.jar" >> $@ + echo "exec java -Djava.library.path=/usr/lib/altos/libaltos -jar /usr/share/java/altosui.jar" >> $@ chmod +x ./altosui install: altosui.jar altosui -- cgit v1.2.3 From 5cc933039e4763b8675611c63b6147b42878a2bb Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 12:16:19 -0600 Subject: fix permissions on installed jar file, switch from ao-view to altosui in the desktop file --- ao-tools/altosui/Makefile | 4 ++-- ao-tools/altosui/altosui.1 | 44 ++++++++++++++++++++++++++++++++++++++++++++ debian/altos.desktop | 4 ++-- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 ao-tools/altosui/altosui.1 (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 73bc230d..101954db 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -100,8 +100,8 @@ altosui: chmod +x ./altosui install: altosui.jar altosui - /usr/bin/install -c altosui.jar $(DESTDIR)/usr/share/java/altosui.jar - /usr/bin/install -c altosui $(DESTDIR)/usr/bin/altosui + /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui endif diff --git a/ao-tools/altosui/altosui.1 b/ao-tools/altosui/altosui.1 new file mode 100644 index 00000000..c3130fce --- /dev/null +++ b/ao-tools/altosui/altosui.1 @@ -0,0 +1,44 @@ +.\" +.\" Copyright © 2010 Bdale Garbee +.\" +.\" 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-VIEW 1 "altosui" "" +.SH NAME +altosui \- Rocket flight monitor +.SH SYNOPSIS +.B "altosui" +.SH DESCRIPTION +.I altosui +connects to a TeleDongle or TeleMetrum device through a USB serial device. +It provides a user interface to monitor, record and review rocket flight data. +.SH USAGE +When connected to a TeleDongle device, altosui turns on the radio +receiver and listens for telemetry packets. It displays the received +telemetry data, and reports flight status via voice synthesis. All +received telemetry information is recorded to a file. +.P +When connected to a TeleMetrum device, altosui downloads the eeprom +data and stores it in a file. +.SH FILES +All data log files are recorded into a user-specified directory +(default ~/AltOS). Files are named using the current date, the serial +number of the reporting device, the flight number recorded in the data +and either '.telem' for telemetry data or '.eeprom' for eeprom data. +.SH "SEE ALSO" +ao-view(1), ao-load(1), ao-eeprom(1) +.SH AUTHOR +Keith Packard diff --git a/debian/altos.desktop b/debian/altos.desktop index 4281ad3a..4345cf09 100644 --- a/debian/altos.desktop +++ b/debian/altos.desktop @@ -1,10 +1,10 @@ [Desktop Entry] Type=Application -Name=AltOS View +Name=AltOS UI GenericName=TeleMetrum Telemetry Viewer Comment=View and log downlink data from TeleMetrum Icon=/usr/share/pixmaps/altusmetrum.xpm -Exec=/usr/bin/ao-view %f +Exec=/usr/bin/altosui %f Terminal=false MimeType=text/plain; Categories=Education;Science; -- cgit v1.2.3 From a8dbe082960dc9bdd44c6e4b1198423c4e566029 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 12:18:28 -0600 Subject: install altosui man page --- ao-tools/altosui/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 101954db..df960130 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -101,6 +101,7 @@ altosui: install: altosui.jar altosui /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/altosui.1 /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui endif -- cgit v1.2.3 From de2e71c4923a0282df74dbe37d087c34b4ddd279 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 12:25:20 -0600 Subject: fix man page delivery path --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index df960130..22752d5d 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -101,7 +101,7 @@ altosui: install: altosui.jar altosui /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar - /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/altosui.1 + /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui endif -- cgit v1.2.3 From 0bd4cc03b3bf23aa32b5ce1921078021d1d8a9c6 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 13:12:46 -0600 Subject: fix path to installed shared library --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 22752d5d..770abcf3 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -96,7 +96,7 @@ endif ifeq ($(OS),Linux) altosui: echo "#!/bin/sh" > $@ - echo "exec java -Djava.library.path=/usr/lib/altos/libaltos -jar /usr/share/java/altosui.jar" >> $@ + echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ chmod +x ./altosui install: altosui.jar altosui -- cgit v1.2.3 From edcfb1bdf64772d3b83405ccf99385b8fea5d8e4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 17:33:59 -0700 Subject: libaltos: AltusMetrum devices use more than one USB ID. List all usb devices, picking those with AltusMetrum IDs. Signed-off-by: Keith Packard --- ao-tools/libaltos/libaltos.c | 45 +++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index ffdb2366..93c483d1 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -391,24 +391,40 @@ get_string(io_object_t object, CFStringRef entry, char *result, int result_len) return 0; } +static int +get_number(io_object_t object, CFStringRef entry, int *result) +{ + CFTypeRef entry_as_number; + Boolean got_number; + + entry_as_number = IORegistryEntrySearchCFProperty (object, + kIOServicePlane, + entry, + kCFAllocatorDefault, + kIORegistryIterateRecursively); + if (entry_as_number) { + got_number = CFNumberGetValue(entry_as_number, + kCFNumberIntType, + result); + if (got_number) + return 1; + } + return 0; +} + struct altos_list * altos_list_start(void) { struct altos_list *list = calloc (sizeof (struct altos_list), 1); CFMutableDictionaryRef matching_dictionary = IOServiceMatching("IOUSBDevice"); - UInt32 vendor = 0xfffe, product = 0x000a; - CFNumberRef vendor_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vendor); - CFNumberRef product_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &product); io_iterator_t tdIterator; io_object_t tdObject; - - CFDictionaryAddValue(matching_dictionary, CFSTR(kUSBVendorID), vendor_ref); - CFDictionaryAddValue(matching_dictionary, CFSTR(kUSBProductID), product_ref); + kern_return_t ret; + int i; - IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dictionary, &list->iterator); - - CFRelease(vendor_ref); - CFRelease(product_ref); + ret = IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dictionary, &list->iterator); + if (ret != kIOReturnSuccess) + return NULL; return list; } @@ -423,8 +439,15 @@ altos_list_next(struct altos_list *list, struct altos_device *device) if (!object) return 0; + if (!get_number (object, CFSTR(kUSBVendorID), &device->vendor) || + !get_number (object, CFSTR(kUSBProductID), &device->product)) + continue; + if (device->vendor != 0xfffe) + continue; + if (device->product < 0x000a || 0x0013 < device->product) + continue; if (get_string (object, CFSTR("IOCalloutDevice"), device->path, sizeof (device->path)) && - get_string (object, CFSTR("USB Product Name"), device->product, sizeof (device->product)) && + get_string (object, CFSTR("USB Product Name"), device->name, sizeof (device->name)) && get_string (object, CFSTR("USB Serial Number"), serial_string, sizeof (serial_string))) { device->serial = atoi(serial_string); return 1; -- cgit v1.2.3 From ae02b1590439d5c8dfb472cf1f83a14fdcfbaf11 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:36:47 -0700 Subject: altosui: provide separate flush_input/flush_output for serial. deal with monitor automatically (yes, this should be two patches, but the diffs in AltosSerial were merged together). First, this replaces the existing flush/flush_reply mess with two simple functions, one to flush output to the serial device, making sure that all data written will be seen while we wait for input. The other sucks any pending input off of the serial line and discards it. Second, AltosSerial now tracks whether the serial line is being used for telemetry monitoring. If so, it enables monitoring, otherwise it disables it. Eliminates a bunch of manual state tracking elsewhere. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 6 +-- ao-tools/altosui/AltosDebug.java | 8 ++-- ao-tools/altosui/AltosEepromDownload.java | 5 ++- ao-tools/altosui/AltosSerial.java | 62 ++++++++++++++++++++----------- 4 files changed, 50 insertions(+), 31 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index ac73e7c5..3d970748 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -122,17 +122,17 @@ public class AltosConfig implements Runnable, ActionListener { void start_serial() throws InterruptedException { if (remote) { - serial_line.printf("m 0\n"); serial_line.set_channel(AltosPreferences.channel()); serial_line.set_callsign(AltosPreferences.callsign()); serial_line.printf("p\n"); + serial_line.flush_input(); } } void stop_serial() throws InterruptedException { if (remote) { - serial_line.printf("~\n"); - serial_line.flush(); + serial_line.printf("~"); + serial_line.flush_output(); } } diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index ca2e5a90..3f469d48 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -62,8 +62,8 @@ public class AltosDebug extends AltosSerial { void ensure_debug_mode() { if (!debug_mode) { - printf("m 0\nD\n"); - flush_reply(); + printf("D\n"); + flush_input(); debug_mode = true; } } @@ -103,7 +103,7 @@ public class AltosDebug extends AltosSerial { throws IOException, InterruptedException { byte[] data = new byte[length]; - flush_reply(); + flush_input(); ensure_debug_mode(); printf("I %x %x\n", length, address); int i = 0; @@ -155,7 +155,7 @@ public class AltosDebug extends AltosSerial { public byte[] read_bytes(int length) throws IOException, InterruptedException { - flush_reply(); + flush_input(); ensure_debug_mode(); printf("G %x\n", length); int i = 0; diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 02a71118..5e43345b 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -223,10 +223,10 @@ public class AltosEepromDownload implements Runnable { public void run () { if (remote) { - serial_line.printf("m 0\n"); serial_line.set_channel(AltosPreferences.channel()); serial_line.set_callsign(AltosPreferences.callsign()); - serial_line.printf("p\n"); + serial_line.printf("p\nE 0\n"); + serial_line.flush_input(); } monitor = new AltosEepromMonitor(frame, Altos.ao_flight_boost, Altos.ao_flight_landed); @@ -247,6 +247,7 @@ public class AltosEepromDownload implements Runnable { if (remote) serial_line.printf("~"); monitor.done(); + serial_line.flush_output(); serial_line.close(); } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 5b47960f..99ba3324 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -47,6 +47,7 @@ public class AltosSerial implements Runnable { String line; byte[] line_bytes; int line_count; + boolean monitor_mode; public void run () { int c; @@ -99,35 +100,39 @@ public class AltosSerial implements Runnable { } } - public void flush_reply() { + public void flush_output() { libaltos.altos_flush(altos); + } + + public void flush_input() { + flush_output(); try { - Thread.sleep(100); + Thread.sleep(200); } catch (InterruptedException ie) { } - reply_queue.clear(); + synchronized(this) { + if (!"VERSION".startsWith(line) && + !line.startsWith("VERSION")) + line = ""; + reply_queue.clear(); + } } public String get_reply() throws InterruptedException { - libaltos.altos_flush(altos); + flush_output(); String line = reply_queue.take(); return line; } public void add_monitor(LinkedBlockingQueue q) { + set_monitor(true); monitors.add(q); } public void remove_monitor(LinkedBlockingQueue q) { monitors.remove(q); - } - - public void flush () { - synchronized(this) { - if (!"VERSION".startsWith(line) && !line.startsWith("VERSION")) - line = ""; - reply_queue.clear(); - } + if (monitors.isEmpty()) + set_monitor(false); } public boolean opened() { @@ -135,8 +140,9 @@ public class AltosSerial implements Runnable { } public void close() { - if (altos != null) + if (altos != null) { libaltos.altos_close(altos); + } if (input_thread != null) { try { input_thread.interrupt(); @@ -157,7 +163,7 @@ public class AltosSerial implements Runnable { } public void print(String data) { -//h System.out.printf("\"%s\" ", data); +// System.out.printf("\"%s\" ", data); for (int i = 0; i < data.length(); i++) putc(data.charAt(i)); } @@ -173,17 +179,28 @@ public class AltosSerial implements Runnable { throw new FileNotFoundException(device.getPath()); input_thread = new Thread(this); input_thread.start(); - print("\nE 0\n"); - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } - flush(); + print("~\nE 0\n"); + set_monitor(monitor_mode); + flush_input(); } public void set_channel(int channel) { - if (altos != null) - printf("m 0\nc r %d\nm 1\n", channel); + if (altos != null) { + if (monitor_mode) + printf("m 0\nc r %d\nm 1\n", channel); + else + printf("c r %d\n", channel); + } + } + + void set_monitor(boolean monitor) { + monitor_mode = monitor; + if (altos != null) { + if (monitor) + printf("m 1\n"); + else + printf("m 0\n"); + } } public void set_callsign(String callsign) { @@ -195,6 +212,7 @@ public class AltosSerial implements Runnable { altos = null; input_thread = null; line = ""; + monitor_mode = false; monitors = new LinkedList> (); reply_queue = new LinkedBlockingQueue (); } -- cgit v1.2.3 From e60c59123232915e808cee23ef89eb1a38ced34b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:40:21 -0700 Subject: altosui: discard invalid lines while reading Eeprom flight data This shouldn't happen, but it's easy enough to get back in sync by just skipping lines with weird contents. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromDownload.java | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 5e43345b..6dbbd3eb 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -142,6 +142,7 @@ public class AltosEepromDownload implements Runnable { if (values == null) { System.out.printf("invalid line: %s\n", line); + continue; } else if (values[0] != addr) { System.out.printf("data address out of sync at 0x%x\n", block * 256 + values[0]); -- cgit v1.2.3 From b7fa1ea3338f63b8edcf8aacccb5e519ca0b213f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:41:40 -0700 Subject: libaltos: Mac OS X cannot use 'poll(2)' on serial lines. Who ships this stuff, anyway? Instead of blocking, we'll poll every 100ms now, otherwise, we won't be able to abort the read when the device is closed. Yay! Signed-off-by: Keith Packard --- ao-tools/libaltos/libaltos.c | 134 +++++++++++++++++++++++++++---------------- 1 file changed, 86 insertions(+), 48 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 93c483d1..65cd6c1a 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -21,6 +21,8 @@ #include #include +#define USE_POLL + PUBLIC int altos_init(void) { @@ -33,6 +35,9 @@ altos_fini(void) } #ifdef DARWIN + +#undef USE_POLL + /* Mac OS X don't have strndup even if _GNU_SOURCE is defined */ static char * altos_strndup (const char *s, size_t n) @@ -471,20 +476,21 @@ altos_list_finish(struct altos_list *list) #include #include #include -#include #define USB_BUF_SIZE 64 struct altos_file { int fd; +#ifdef USE_POLL int pipe[2]; +#else + int out_fd; +#endif unsigned char out_data[USB_BUF_SIZE]; int out_used; unsigned char in_data[USB_BUF_SIZE]; int in_used; int in_read; - pthread_mutex_t putc_mutex; - pthread_mutex_t getc_mutex; }; struct altos_file * @@ -497,32 +503,54 @@ altos_open(struct altos_device *device) if (!file) return NULL; - pipe(file->pipe); + printf("open %s\n", device->path); file->fd = open(device->path, O_RDWR | O_NOCTTY); + printf("opened %d\n", file->fd); if (file->fd < 0) { perror(device->path); free(file); return NULL; } +#ifdef USE_POLL + pipe(file->pipe); +#else + file->out_fd = open(device->path, O_RDWR | O_NOCTTY); + if (file->out_fd < 0) { + perror(device->path); + close(file->fd); + free(file); + return NULL; + } +#endif ret = tcgetattr(file->fd, &term); if (ret < 0) { perror("tcgetattr"); close(file->fd); +#ifndef USE_POLL + close(file->out_fd); +#endif free(file); return NULL; } cfmakeraw(&term); +#ifdef USE_POLL term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; +#else + term.c_cc[VMIN] = 0; + term.c_cc[VTIME] = 1; +#endif ret = tcsetattr(file->fd, TCSAFLUSH, &term); if (ret < 0) { perror("tcsetattr"); close(file->fd); +#ifndef USE_POLL + close(file->out_fd); +#endif free(file); return NULL; } - pthread_mutex_init(&file->putc_mutex,NULL); - pthread_mutex_init(&file->getc_mutex,NULL); + printf("running %d\n", file->fd); return file; } @@ -532,7 +560,13 @@ altos_close(struct altos_file *file) if (file->fd != -1) { int fd = file->fd; file->fd = -1; +#ifdef USE_POLL write(file->pipe[1], "\r", 1); +#else + close(file->out_fd); + file->out_fd = -1; +#endif + printf("close %d\n", fd); close(fd); } } @@ -544,16 +578,20 @@ altos_free(struct altos_file *file) free(file); } -static int -_altos_flush(struct altos_file *file) +int +altos_flush(struct altos_file *file) { while (file->out_used) { int ret; if (file->fd < 0) return -EBADF; - fflush(stdout); + printf("write %d\n", file->out_used); +#ifdef USE_POLL ret = write (file->fd, file->out_data, file->out_used); +#else + ret = write (file->out_fd, file->out_data, file->out_used); +#endif if (ret < 0) return -errno; if (ret) { @@ -562,6 +600,7 @@ _altos_flush(struct altos_file *file) file->out_used -= ret; } } + return 0; } int @@ -569,79 +608,81 @@ altos_putchar(struct altos_file *file, char c) { int ret; - pthread_mutex_lock(&file->putc_mutex); if (file->out_used == USB_BUF_SIZE) { - ret = _altos_flush(file); + ret = altos_flush(file); if (ret) { - pthread_mutex_unlock(&file->putc_mutex); return ret; } } file->out_data[file->out_used++] = c; ret = 0; if (file->out_used == USB_BUF_SIZE) - ret = _altos_flush(file); - pthread_mutex_unlock(&file->putc_mutex); + ret = altos_flush(file); return 0; } -int -altos_flush(struct altos_file *file) -{ - int ret; - pthread_mutex_lock(&file->putc_mutex); - ret = _altos_flush(file); - pthread_mutex_unlock(&file->putc_mutex); - return ret; -} - - +#ifdef USE_POLL #include +#endif int -altos_getchar(struct altos_file *file, int timeout) +altos_fill(struct altos_file *file, int timeout) { int ret; +#ifdef USE_POLL struct pollfd fd[2]; +#endif if (timeout == 0) timeout = -1; - pthread_mutex_lock(&file->getc_mutex); - fd[0].fd = file->fd; - fd[0].events = POLLIN; - fd[1].fd = file->pipe[0]; - fd[1].events = POLLIN; while (file->in_read == file->in_used) { - if (file->fd < 0) { - pthread_mutex_unlock(&file->getc_mutex); + if (file->fd < 0) return LIBALTOS_ERROR; - } - altos_flush(file); - +#ifdef USE_POLL + fd[0].fd = file->fd; + fd[0].events = POLLIN; + fd[1].fd = file->pipe[0]; + fd[1].events = POLLIN; ret = poll(fd, 2, timeout); if (ret < 0) { perror("altos_getchar"); - pthread_mutex_unlock(&file->getc_mutex); return LIBALTOS_ERROR; } - if (ret == 0) { - pthread_mutex_unlock(&file->getc_mutex); + if (ret == 0) return LIBALTOS_TIMEOUT; - } - if (fd[0].revents & POLLIN) { + if (fd[0].revents & POLLIN) +#endif + { ret = read(file->fd, file->in_data, USB_BUF_SIZE); + if (ret) + printf("read %d\n", ret); if (ret < 0) { perror("altos_getchar"); - pthread_mutex_unlock(&file->getc_mutex); return LIBALTOS_ERROR; } file->in_read = 0; file->in_used = ret; +#ifndef USE_POLL + if (ret == 0 && timeout > 0) + return LIBALTOS_TIMEOUT; +#endif } } - ret = file->in_data[file->in_read++]; - pthread_mutex_unlock(&file->getc_mutex); - return ret; + return 0; +} + +int +altos_getchar(struct altos_file *file, int timeout) +{ + int ret; + while (file->in_read == file->in_used) { + if (file->fd < 0) + return LIBALTOS_ERROR; + ret = altos_fill(file, timeout); + if (ret) + return ret; + } + return file->in_data[file->in_read++]; } #endif /* POSIX_TTY */ @@ -919,9 +960,6 @@ altos_getchar(struct altos_file *file, int timeout) { int ret; while (file->in_read == file->in_used) { - ret = altos_flush(file); - if (ret) - return ret; if (file->handle == INVALID_HANDLE_VALUE) return LIBALTOS_ERROR; ret = altos_fill(file, timeout); -- cgit v1.2.3 From 6527357d1f0e94faf9e7dacac10a39875131be7c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:43:46 -0700 Subject: libaltos: Missing OS_LDFLAGS on cjnitest build --- ao-tools/libaltos/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index cd96fd5f..f336f22f 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -96,8 +96,8 @@ SRCS = libaltos.c $(SWIG_WRAP) OBJS = $(SRCS:%.c=%.o) LIBS = $(DARWIN_LIBS) -$(CJNITEST): cjnitest.o $(OBJS) - cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBS) +$(CJNITEST): cjnitest.o $(LIBNAME) + cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBNAME) $(LIBS) $(OS_LDFLAGS) $(LIBNAME): $(OBJS) gcc -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) -- cgit v1.2.3 From 1acd3c7ec167b1b18e4ea493e5978c938a91cc89 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:45:19 -0700 Subject: libaltos: cjnitest needs altos_flush now --- ao-tools/libaltos/cjnitest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/cjnitest.c b/ao-tools/libaltos/cjnitest.c index 93d1f376..c6d6e069 100644 --- a/ao-tools/libaltos/cjnitest.c +++ b/ao-tools/libaltos/cjnitest.c @@ -30,6 +30,7 @@ main () continue; } altos_puts(file,"v\nc s\n"); + altos_flush(file); while ((c = altos_getchar(file, 100)) >= 0) { putchar (c); } -- cgit v1.2.3 From dd5374b8e660012ae4f8b058454fd101e0749ca7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 02:00:30 -0700 Subject: libaltos: Fix windows build. Need stdlib.h to get calloc/free defined, remove debug printfs, fix serial timeouts. Signed-off-by: Keith Packard --- ao-tools/libaltos/libaltos.c | 108 ++++++++++++++++++++----------------------- ao-tools/libaltos/libaltos.h | 2 + 2 files changed, 51 insertions(+), 59 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 65cd6c1a..1d3b26dd 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -15,7 +15,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#define BUILD_DLL #include "libaltos.h" #include #include @@ -503,9 +502,7 @@ altos_open(struct altos_device *device) if (!file) return NULL; - printf("open %s\n", device->path); file->fd = open(device->path, O_RDWR | O_NOCTTY); - printf("opened %d\n", file->fd); if (file->fd < 0) { perror(device->path); free(file); @@ -550,7 +547,6 @@ altos_open(struct altos_device *device) free(file); return NULL; } - printf("running %d\n", file->fd); return file; } @@ -566,7 +562,6 @@ altos_close(struct altos_file *file) close(file->out_fd); file->out_fd = -1; #endif - printf("close %d\n", fd); close(fd); } } @@ -586,7 +581,6 @@ altos_flush(struct altos_file *file) if (file->fd < 0) return -EBADF; - printf("write %d\n", file->out_used); #ifdef USE_POLL ret = write (file->fd, file->out_data, file->out_used); #else @@ -654,8 +648,6 @@ altos_fill(struct altos_file *file, int timeout) #endif { ret = read(file->fd, file->in_data, USB_BUF_SIZE); - if (ret) - printf("read %d\n", ret); if (ret < 0) { perror("altos_getchar"); return LIBALTOS_ERROR; @@ -689,6 +681,7 @@ altos_getchar(struct altos_file *file, int timeout) #ifdef WINDOWS +#include #include #include @@ -708,7 +701,6 @@ struct altos_file { int in_read; }; - PUBLIC struct altos_list * altos_list_start(void) { @@ -733,15 +725,15 @@ altos_list_next(struct altos_list *list, struct altos_device *device) SP_DEVINFO_DATA dev_info_data; char port[128]; DWORD port_len; - char location[256]; + char friendlyname[256]; char symbolic[256]; DWORD symbolic_len; HKEY dev_key; int vid, pid; int serial; HRESULT result; - DWORD location_type; - DWORD location_len; + DWORD friendlyname_type; + DWORD friendlyname_len; dev_info_data.cbSize = sizeof (SP_DEVINFO_DATA); while(SetupDiEnumDeviceInfo(list->dev_info, list->index, @@ -775,8 +767,6 @@ altos_list_next(struct altos_list *list, struct altos_device *device) sscanf(symbolic + sizeof("\\??\\USB#VID_XXXX&PID_XXXX#") - 1, "%d", &serial); if (!USB_IS_ALTUSMETRUM(vid, pid)) { - printf("Not Altus Metrum symbolic name: %s\n", - symbolic); RegCloseKey(dev_key); continue; } @@ -791,33 +781,26 @@ altos_list_next(struct altos_list *list, struct altos_device *device) continue; } - /* Fetch the 'location information' which is the device name, - * at least on XP */ - location_len = sizeof (location); + /* Fetch the device description which is the device name, + * with firmware that has unique USB ids */ + friendlyname_len = sizeof (friendlyname); if(!SetupDiGetDeviceRegistryProperty(list->dev_info, &dev_info_data, - SPDRP_LOCATION_INFORMATION, - &location_type, - (BYTE *)location, - sizeof(location), - &location_len)) + SPDRP_FRIENDLYNAME, + &friendlyname_type, + (BYTE *)friendlyname, + sizeof(friendlyname), + &friendlyname_len)) { - printf("Failed to get location\n"); + printf("Failed to get friendlyname\n"); continue; } device->vendor = vid; device->product = pid; device->serial = serial; - - if (strcasestr(location, "tele")) - strcpy(device->name, location); - else - strcpy(device->name, ""); + strcpy(device->name, friendlyname); strcpy(device->path, port); - printf ("product: %04x:%04x (%s) path: %s serial %d\n", - device->vendor, device->product, device->name, - device->path, device->serial); return 1; } result = GetLastError(); @@ -844,31 +827,32 @@ altos_fill(struct altos_file *file, int timeout) return LIBALTOS_SUCCESS; file->in_read = file->in_used = 0; - if (timeout) { - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; + if (timeout) timeouts.ReadTotalTimeoutConstant = timeout; - } else { - timeouts.ReadIntervalTimeout = 0; - timeouts.ReadTotalTimeoutMultiplier = 0; - timeouts.ReadTotalTimeoutConstant = 0; - } + else + timeouts.ReadTotalTimeoutConstant = 1000; + + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 0; - if (!SetCommTimeouts(file->handle, &timeouts)) { + if (!SetCommTimeouts(file->handle, &timeouts)) printf("SetCommTimeouts failed %d\n", GetLastError()); - } - if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, NULL)) { - result = GetLastError(); - printf ("read failed %d\n", result); - return LIBALTOS_ERROR; - got = 0; + for (;;) { + if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, NULL)) { + result = GetLastError(); + return LIBALTOS_ERROR; + got = 0; + } + file->in_read = 0; + file->in_used = got; + if (got) + return LIBALTOS_SUCCESS; + if (timeout) + return LIBALTOS_TIMEOUT; } - if (got) - return LIBALTOS_SUCCESS; - return LIBALTOS_TIMEOUT; } PUBLIC int @@ -882,7 +866,6 @@ altos_flush(struct altos_file *file) while (used) { if (!WriteFile(file->handle, data, used, &put, NULL)) { result = GetLastError(); - printf ("write failed %d\n", result); return LIBALTOS_ERROR; } data += put; @@ -895,8 +878,9 @@ altos_flush(struct altos_file *file) PUBLIC struct altos_file * altos_open(struct altos_device *device) { - struct altos_file *file = calloc (sizeof (struct altos_file), 1); + struct altos_file *file = calloc (1, sizeof (struct altos_file)); char full_name[64]; + DCB dcbSerialParams = {0}; if (!file) return NULL; @@ -910,14 +894,20 @@ altos_open(struct altos_device *device) free(file); return NULL; } - - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; - timeouts.ReadTotalTimeoutConstant = 100; - timeouts.WriteTotalTimeoutMultiplier = 0; - timeouts.WriteTotalTimeoutConstant = 10000; - if (!SetCommTimeouts(file->handle, &timeouts)) { - printf("SetCommTimeouts failed %d\n", GetLastError()); + dcbSerialParams.DCBlength = sizeof(dcbSerialParams); + if (!GetCommState(file->handle, &dcbSerialParams)) { + CloseHandle(file->handle); + free(file); + return NULL; + } + dcbSerialParams.BaudRate = CBR_9600; + dcbSerialParams.ByteSize = 8; + dcbSerialParams.StopBits = ONESTOPBIT; + dcbSerialParams.Parity = NOPARITY; + if (!SetCommState(file->handle, &dcbSerialParams)) { + CloseHandle(file->handle); + free(file); + return NULL; } return file; diff --git a/ao-tools/libaltos/libaltos.h b/ao-tools/libaltos/libaltos.h index fe2c483c..6e94899e 100644 --- a/ao-tools/libaltos/libaltos.h +++ b/ao-tools/libaltos/libaltos.h @@ -18,6 +18,8 @@ #ifndef _LIBALTOS_H_ #define _LIBALTOS_H_ +#include + #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # ifndef BUILD_STATIC # ifdef BUILD_DLL -- cgit v1.2.3 From df34bbe7d1c43b12ab6d610fe810b6e1683e4c21 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 02:49:49 -0700 Subject: libaltos: Improve Makefile Builds Windows .dll correctly now and sample app. Moves linux install target to end so it is not default Adds .NOTPARALLEL to disable parallel gnumake. Removes -g debugging flags to shrink file size. Signed-off-by: Keith Packard --- ao-tools/libaltos/Makefile | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index f336f22f..201cf8e2 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -7,16 +7,14 @@ ifeq ($(OS),Linux) JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include -OS_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) +OS_LIB_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) + +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) OS_LDFLAGS= LIBNAME=libaltos.so EXEEXT= - -install: $(LIBNAME) - /usr/bin/install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) - endif # @@ -24,12 +22,13 @@ endif # ifeq ($(OS),Darwin) -OS_CFLAGS=\ +OS_LIB_CFLAGS=\ -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) OS_LDFLAGS =\ -framework IOKit -framework CoreFoundation @@ -46,7 +45,8 @@ ifneq (,$(findstring MINGW,$(OS))) CC=gcc -OS_CFLAGS = -DWINDOWS -mconsole +OS_LIB_CFLAGS = -DWINDOWS -mconsole -DBUILD_DLL +OS_APP_CFLAGS = -DWINDOWS -mconsole OS_LDFLAGS = -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lole32 \ -ladvapi32 -lcomctl32 -mconsole -Wl,--add-stdcall-alias @@ -87,7 +87,7 @@ all: $(LIBNAME) $(CJNITEST) $(CLASSFILES) .java.class: javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java -CFLAGS=$(OS_CFLAGS) -O0 -g -I. +CFLAGS=$(OS_LIB_CFLAGS) -O -I. LDFLAGS=$(OS_LDFLAGS) @@ -96,11 +96,11 @@ SRCS = libaltos.c $(SWIG_WRAP) OBJS = $(SRCS:%.c=%.o) LIBS = $(DARWIN_LIBS) -$(CJNITEST): cjnitest.o $(LIBNAME) - cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBNAME) $(LIBS) $(OS_LDFLAGS) +$(CJNITEST): cjnitest.c $(LIBNAME) + $(CC) -o $@ $(OS_APP_CFLAGS) cjnitest.c $(LIBNAME) $(LIBS) $(LDFLAGS) $(LIBNAME): $(OBJS) - gcc -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) + $(CC) -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) clean: rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o @@ -114,3 +114,11 @@ $(JNI_FILE): libaltos.i0 $(HEADERS) cp swig_bindings/java/*.java libaltosJNI $(SWIG_WRAP): $(JNI_FILE) + +ifeq ($(OS),Linux) +install: $(LIBNAME) + /usr/bin/install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) + +endif + +.NOTPARALLEL: -- cgit v1.2.3 From 0300fe581c949232bc52b05fe9c1f6032cad6b60 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 02:56:25 -0700 Subject: libaltos: Add pre-built Mac OS X libaltos.dylib This allows the mac bits to be built on Linux. Signed-off-by: Keith Packard --- ao-tools/libaltos/libaltos.dylib | Bin 0 -> 54176 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 ao-tools/libaltos/libaltos.dylib (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.dylib b/ao-tools/libaltos/libaltos.dylib new file mode 100755 index 00000000..89aa12e7 Binary files /dev/null and b/ao-tools/libaltos/libaltos.dylib differ -- cgit v1.2.3 From 20a472cfe3369200150ea4ff067ceb28968dbcac Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 02:58:23 -0700 Subject: libaltos: Add pre-built Windows .dll This lets us create the windows distribution on Linux. Signed-off-by: Keith Packard --- ao-tools/libaltos/altos.dll | Bin 0 -> 30550 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 ao-tools/libaltos/altos.dll (limited to 'ao-tools') diff --git a/ao-tools/libaltos/altos.dll b/ao-tools/libaltos/altos.dll new file mode 100755 index 00000000..f40181e8 Binary files /dev/null and b/ao-tools/libaltos/altos.dll differ -- cgit v1.2.3 From 35d9a8214252dbe79aeb69ae47d2e5c58a654702 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 05:27:45 -0700 Subject: libaltos: Use overlapped I/O on windows Otherwise, reads block writes and vice-versa. Crazy stuff. Signed-off-by: Keith Packard --- ao-tools/libaltos/altos.dll | Bin 30550 -> 31765 bytes ao-tools/libaltos/libaltos.c | 127 ++++++++++++++++++++++++++++++------------- 2 files changed, 90 insertions(+), 37 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/altos.dll b/ao-tools/libaltos/altos.dll index f40181e8..28e9b4ad 100755 Binary files a/ao-tools/libaltos/altos.dll and b/ao-tools/libaltos/altos.dll differ diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 1d3b26dd..059d2ae9 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -492,7 +492,7 @@ struct altos_file { int in_read; }; -struct altos_file * +PUBLIC struct altos_file * altos_open(struct altos_device *device) { struct altos_file *file = calloc (sizeof (struct altos_file), 1); @@ -550,7 +550,7 @@ altos_open(struct altos_device *device) return file; } -void +PUBLIC void altos_close(struct altos_file *file) { if (file->fd != -1) { @@ -566,14 +566,14 @@ altos_close(struct altos_file *file) } } -void +PUBLIC void altos_free(struct altos_file *file) { altos_close(file); free(file); } -int +PUBLIC int altos_flush(struct altos_file *file) { while (file->out_used) { @@ -597,7 +597,7 @@ altos_flush(struct altos_file *file) return 0; } -int +PUBLIC int altos_putchar(struct altos_file *file, char c) { int ret; @@ -619,7 +619,7 @@ altos_putchar(struct altos_file *file, char c) #include #endif -int +static int altos_fill(struct altos_file *file, int timeout) { int ret; @@ -663,7 +663,7 @@ altos_fill(struct altos_file *file, int timeout) return 0; } -int +PUBLIC int altos_getchar(struct altos_file *file, int timeout) { int ret; @@ -699,6 +699,9 @@ struct altos_file { unsigned char in_data[USB_BUF_SIZE]; int in_used; int in_read; + OVERLAPPED ov_read; + BOOL pend_read; + OVERLAPPED ov_write; }; PUBLIC struct altos_list * @@ -817,42 +820,72 @@ altos_list_finish(struct altos_list *list) } static int -altos_fill(struct altos_file *file, int timeout) +altos_queue_read(struct altos_file *file) { - DWORD result; DWORD got; - COMMTIMEOUTS timeouts; - - if (file->in_read < file->in_used) + if (file->pend_read) return LIBALTOS_SUCCESS; - file->in_read = file->in_used = 0; - if (timeout) - timeouts.ReadTotalTimeoutConstant = timeout; - else - timeouts.ReadTotalTimeoutConstant = 1000; + if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, &file->ov_read)) { + if (GetLastError() != ERROR_IO_PENDING) + return LIBALTOS_ERROR; + file->pend_read = TRUE; + } else { + file->pend_read = FALSE; + file->in_read = 0; + file->in_used = got; + } + return LIBALTOS_SUCCESS; +} - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; - timeouts.WriteTotalTimeoutMultiplier = 0; - timeouts.WriteTotalTimeoutConstant = 0; +static int +altos_wait_read(struct altos_file *file, int timeout) +{ + DWORD ret; + DWORD got; - if (!SetCommTimeouts(file->handle, &timeouts)) - printf("SetCommTimeouts failed %d\n", GetLastError()); + if (!file->pend_read) + return LIBALTOS_SUCCESS; - for (;;) { - if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, NULL)) { - result = GetLastError(); + if (!timeout) + timeout = INFINITE; + + ret = WaitForSingleObject(file->ov_read.hEvent, timeout); + switch (ret) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(file->handle, &file->ov_read, &got, FALSE)) return LIBALTOS_ERROR; - got = 0; - } + file->pend_read = FALSE; file->in_read = 0; file->in_used = got; - if (got) - return LIBALTOS_SUCCESS; - if (timeout) - return LIBALTOS_TIMEOUT; + break; + case WAIT_TIMEOUT: + return LIBALTOS_TIMEOUT; + break; + default: + return LIBALTOS_ERROR; } + return LIBALTOS_SUCCESS; +} + +static int +altos_fill(struct altos_file *file, int timeout) +{ + int ret; + + if (file->in_read < file->in_used) + return LIBALTOS_SUCCESS; + + file->in_read = file->in_used = 0; + + ret = altos_queue_read(file); + if (ret) + return ret; + ret = altos_wait_read(file, timeout); + if (ret) + return ret; + + return LIBALTOS_SUCCESS; } PUBLIC int @@ -861,12 +894,21 @@ altos_flush(struct altos_file *file) DWORD put; char *data = file->out_data; char used = file->out_used; - DWORD result; + DWORD ret; while (used) { - if (!WriteFile(file->handle, data, used, &put, NULL)) { - result = GetLastError(); - return LIBALTOS_ERROR; + if (!WriteFile(file->handle, data, used, &put, &file->ov_write)) { + if (GetLastError() != ERROR_IO_PENDING) + return LIBALTOS_ERROR; + ret = WaitForSingleObject(file->ov_write.hEvent, INFINITE); + switch (ret) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(file->handle, &file->ov_write, &put, FALSE)) + return LIBALTOS_ERROR; + break; + default: + return LIBALTOS_ERROR; + } } data += put; used -= put; @@ -881,6 +923,7 @@ altos_open(struct altos_device *device) struct altos_file *file = calloc (1, sizeof (struct altos_file)); char full_name[64]; DCB dcbSerialParams = {0}; + COMMTIMEOUTS timeouts; if (!file) return NULL; @@ -889,11 +932,21 @@ altos_open(struct altos_device *device) strcat(full_name, device->path); file->handle = CreateFile(full_name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL); + FILE_FLAG_OVERLAPPED, NULL); if (file->handle == INVALID_HANDLE_VALUE) { free(file); return NULL; } + file->ov_read.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + file->ov_write.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; + timeouts.ReadTotalTimeoutConstant = 1 << 30; /* almost forever */ + timeouts.WriteTotalTimeoutMultiplier = 0; + timeouts.WriteTotalTimeoutConstant = 0; + SetCommTimeouts(file->handle, &timeouts); + dcbSerialParams.DCBlength = sizeof(dcbSerialParams); if (!GetCommState(file->handle, &dcbSerialParams)) { CloseHandle(file->handle); -- cgit v1.2.3 From 38ac388baf8125c0644b868a7aaf8eba1bdf990d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 05:28:37 -0700 Subject: altosui: Build linux, mac and windows archives on Linux This adds 'fat' archives for each target OS. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 123 +++++++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 35 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 770abcf3..6514c608 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -39,40 +39,57 @@ CLASSFILES=\ AltosRomconfigUI.class \ AltosVoice.class -#FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 -#FREETTSLIB=$(FREETTSSRC)/lib -#FREETTSJAR=/usr/share/java/freetts.jar -#FREETTSJAR= \ -# cmudict04.jar \ -# cmulex.jar \ -# cmu_time_awb.jar \ -# cmutimelex.jar \ -# cmu_us_kal.jar \ -# en_us.jar \ -# freetts.jar +# where altosui.jar gets installed +ALTOSLIB=/usr/share/java + +# where freetts.jar is to be found +FREETTSLIB=/usr/share/java + +# all of the freetts files +FREETTSJAR= \ + $(FREETTSLIB)/cmudict04.jar \ + $(FREETTSLIB)/cmulex.jar \ + $(FREETTSLIB)/cmu_time_awb.jar \ + $(FREETTSLIB)/cmutimelex.jar \ + $(FREETTSLIB)/cmu_us_kal.jar \ + $(FREETTSLIB)/en_us.jar \ + $(FREETTSLIB)/freetts.jar + +# The current hex files +HEXLIB=../../src +HEXFILES = \ + $(HEXLIB)/telemetrum-v1.0.ihx \ + $(HEXLIB)/teledongle-v0.2.ihx JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation +ALTOSUIJAR = altosui.jar +FATJAR = fat/altosui.jar + OS:=$(shell uname) -ifeq ($(OS),Linux) -ALTOSUI_APP=altosui -endif +LINUX_APP=altosui + +DARWIN_ZIP=Altos-Mac.zip + +WINDOWS_ZIP=Altos-Windows.zip -ifeq ($(OS),Darwin) -ALTOSUI_APP=AltosUI.app/Contents/Resources/Java/altosui.jar -endif +LINUX_TGZ=Altos-Linux.tgz -all: altosui.jar $(ALTOSUI_APP) +all: $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) $(CLASSFILES): .java.class: javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java -altosui.jar: classes/altosui classes/libaltosJNI $(FREETTSJAR) $(CLASSFILES) Manifest.txt +altosui.jar: classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt cd ./classes && jar cfm ../$@ altosui/Manifest.txt altosui/*.class libaltosJNI/*.class +Manifest.txt: Makefile $(CLASSFILES) + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: $(FREETTSLIB)/freetts.jar' >> $@ + classes/altosui: mkdir -p classes ln -sf .. classes/altosui @@ -81,32 +98,68 @@ classes/libaltosJNI: mkdir -p classes ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI -#$(FREETTSJAR): -# ln -s $(FREETTSLIB)/$@ . - -ifeq ($(OS),Darwin) -RESOURCES=altosui.jar $(FREETTSJAR) ../libaltos/libaltos.dylib - -$(ALTOSUI_APP): $(RESOURCES) - mkdir -p AltosUI.app/Contents/Resources/Java - cp $(RESOURCES) AltosUI.app/Contents/Resources/Java - -endif - -ifeq ($(OS),Linux) altosui: echo "#!/bin/sh" > $@ echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ chmod +x ./altosui -install: altosui.jar altosui +fat/altosui: + echo "#!/bin/sh" > $@ + echo 'ME=`which "$0"`' >> $@ + echo 'DIR=`dirname "$ME"`' >> $@ + echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ + chmod +x $@ + +fat/altosui.jar: $(CLASSFILES) fat/classes/Manifest.txt + mkdir -p fat/classes + test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui + test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI + cd ./fat/classes && jar cfm ../../$@ Manifest.txt altosui/*.class libaltosJNI/*.class + +fat/classes/Manifest.txt: $(CLASSFILES) Makefile + mkdir -p fat/classes + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: freetts.jar" >> $@ + +install: altosui.jar altosui /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui - -endif clean: rm -f *.class altosui.jar rm -f AltosUI.app/Contents/Resources/Java/* rm -rf classes + rm -rf windows linux + +FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) + +LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui +$(LINUX_TGZ): $(LINUX_FILES) + rm $@ + mkdir -p linux/AltOS + rm -f linux/AltOS/* + cp $(LINUX_FILES) linux/AltOS + cd linux && tar czf ../$@ AltOS + +DARWIN_RESOURCES=$(FATJAR) $(FREETTSJAR) ../libaltos/libaltos.dylib +DARWIN_EXTRA=$(HEXFILES) +DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) + +$(DARWIN_ZIP): $(DARWIN_FILES) + rm $@ + cp -a AltosUI.app darwin/ + mkdir -p darwin/AltosUI.app/Contents/Resources/Java + cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java + mkdir -p darwin/AltOS + cp $(DARWIN_EXTRA) darwin/AltOS + cd darwin && zip -j -r ../$@ AltosUI.app AltOS + +WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf + +$(WINDOWS_ZIP): $(WINDOWS_FILES) + rm $@ + mkdir -p windows/AltOS + rm -f windows/AltOS/* + cp $(WINDOWS_FILES) windows/AltOS + cd windows && zip -j -r ../$@ AltOS -- cgit v1.2.3 From a94900b8862b99b4e317ea0ee3edd2a560f270c7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 05:48:23 -0700 Subject: altosui: build debian-style altosui too This adds the dependencies to make sure altosui and altosui.jar get built. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 6514c608..dcaf3ab0 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -76,7 +76,7 @@ WINDOWS_ZIP=Altos-Windows.zip LINUX_TGZ=Altos-Linux.tgz -all: $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) +all: altosui altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) $(CLASSFILES): @@ -88,7 +88,7 @@ altosui.jar: classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt Manifest.txt: Makefile $(CLASSFILES) echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTSLIB)/freetts.jar' >> $@ + echo "Class-Path: $(FREETTSLIB)/freetts.jar" >> $@ classes/altosui: mkdir -p classes -- cgit v1.2.3 From a9a8d23c877e6f6c76857b7c85e3d43b4da1db27 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 05:49:11 -0700 Subject: altosui: Devices with USB id 0x000a always get listed List 'unknown' AltusMetrum devices anytime the UI needs a device name. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDevice.java | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index 3daf0742..e62a0a7a 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -32,6 +32,7 @@ public class AltosDevice extends altos_device { System.err.println("Native library failed to load.\n" + e); } } + public final static int AltusMetrum = libaltosConstants.USB_PRODUCT_ALTUSMETRUM; public final static int TeleMetrum = libaltosConstants.USB_PRODUCT_TELEMETRUM; public final static int TeleDongle = libaltosConstants.USB_PRODUCT_TELEDONGLE; public final static int TeleTerra = libaltosConstants.USB_PRODUCT_TELETERRA; @@ -58,33 +59,23 @@ public class AltosDevice extends altos_device { public boolean matchProduct(int want_product) { + if (!isAltusMetrum()) + return false; + if (want_product == Any) return true; if (want_product == BaseStation) return matchProduct(TeleDongle) || matchProduct(TeleTerra); - if (!isAltusMetrum()) - return false; - int have_product = getProduct(); - if (want_product == have_product) + if (have_product == AltusMetrum) /* old devices match any request */ return true; - if (have_product != libaltosConstants.USB_PRODUCT_ALTUSMETRUM) - return false; - - String name = getName(); + if (want_product == have_product) + return true; - if (name == null) - return false; - if (want_product == libaltosConstants.USB_PRODUCT_TELEMETRUM) - return name.startsWith("TeleMetrum"); - if (want_product == libaltosConstants.USB_PRODUCT_TELEDONGLE) - return name.startsWith("TeleDongle"); - if (want_product == libaltosConstants.USB_PRODUCT_TELETERRA) - return name.startsWith("TeleTerra"); return false; } -- cgit v1.2.3 From cbc72399a0f4d7429df0189bcdae683dd491cb9e Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Mon, 30 Aug 2010 17:56:56 -0600 Subject: continue even if rm's don't have anything to do --- ao-tools/altosui/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index dcaf3ab0..d3b6970f 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -136,7 +136,7 @@ FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui $(LINUX_TGZ): $(LINUX_FILES) - rm $@ + rm -f $@ mkdir -p linux/AltOS rm -f linux/AltOS/* cp $(LINUX_FILES) linux/AltOS @@ -147,7 +147,7 @@ DARWIN_EXTRA=$(HEXFILES) DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) $(DARWIN_ZIP): $(DARWIN_FILES) - rm $@ + rm -f $@ cp -a AltosUI.app darwin/ mkdir -p darwin/AltosUI.app/Contents/Resources/Java cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java @@ -158,7 +158,7 @@ $(DARWIN_ZIP): $(DARWIN_FILES) WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ZIP): $(WINDOWS_FILES) - rm $@ + rm -f $@ mkdir -p windows/AltOS rm -f windows/AltOS/* cp $(WINDOWS_FILES) windows/AltOS -- cgit v1.2.3 From 81318e5b7179b0311ab099043ecb04a25d763750 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Mon, 30 Aug 2010 18:15:40 -0600 Subject: make invocation of 'install' pathless to work on more Unix variants --- ao-tools/altosui/Makefile | 6 +++--- ao-tools/libaltos/Makefile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index d3b6970f..ce627ec0 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -122,9 +122,9 @@ fat/classes/Manifest.txt: $(CLASSFILES) Makefile echo "Class-Path: freetts.jar" >> $@ install: altosui.jar altosui - /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar - /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 - /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui + install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 + install altosui $(DESTDIR)/usr/bin/altosui clean: rm -f *.class altosui.jar diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 201cf8e2..77ffa1b4 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -117,7 +117,7 @@ $(SWIG_WRAP): $(JNI_FILE) ifeq ($(OS),Linux) install: $(LIBNAME) - /usr/bin/install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) + install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) endif -- cgit v1.2.3 From 2a004d17a13b4ff52d892bfdecff8ad3d0823f7c Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Mon, 30 Aug 2010 19:37:17 -0600 Subject: don't build all the "fat" jar deliverables by default --- ao-tools/altosui/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index ce627ec0..5a8d7454 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -76,7 +76,8 @@ WINDOWS_ZIP=Altos-Windows.zip LINUX_TGZ=Altos-Linux.tgz -all: altosui altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) +all: altosui.jar $(LINUX_APP) +fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) $(CLASSFILES): -- cgit v1.2.3 From 775acb89660cdee2f3c54c38297baefe39f2414c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 22:24:09 -0700 Subject: altosui: missed AltosReader.class in the Makefile This caused clean builds to fail to make this file Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 5a8d7454..bf92b5d6 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -26,6 +26,7 @@ CLASSFILES=\ AltosLogfileChooser.class \ AltosParse.class \ AltosPreferences.class \ + AltosReader.class \ AltosRecord.class \ AltosSerialMonitor.class \ AltosSerial.class \ -- cgit v1.2.3 From a470315e5d822a69ef5304512cf73c604c88e481 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 20:14:51 -0700 Subject: altosui: Remove Manifest.txt from git repo as it's built now This file is built with appropriate contents for each different .jar file. Signed-off-by: Keith Packard --- ao-tools/altosui/Manifest.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 ao-tools/altosui/Manifest.txt (limited to 'ao-tools') diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt deleted file mode 100644 index 504d0de3..00000000 --- a/ao-tools/altosui/Manifest.txt +++ /dev/null @@ -1,2 +0,0 @@ -Main-Class: altosui.AltosUI -Class-Path: /usr/share/java/freetts.jar -- cgit v1.2.3 From 83552dfa0d38db9cdf3efc89e64e6c7896467856 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 2 Sep 2010 00:47:54 -0400 Subject: add distclean targets to libaltos and altosui to all Debian package to build --- ao-tools/altosui/Makefile | 2 ++ ao-tools/libaltos/Makefile | 2 ++ 2 files changed, 4 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index bf92b5d6..92922de3 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -134,6 +134,8 @@ clean: rm -rf classes rm -rf windows linux +distclean: clean + FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 77ffa1b4..cb767c85 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -106,6 +106,8 @@ clean: rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o rm -rf swig_bindings libaltosJNI +distclean: clean + $(JNI_FILE): libaltos.i0 $(HEADERS) mkdir -p $(SWIG_DIR) mkdir -p libaltosJNI -- cgit v1.2.3 From 3aafd70257b70b7c11ba9c55749157979bc61ea2 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 2 Sep 2010 00:52:04 -0400 Subject: more makefile distclean target work --- ao-tools/altosui/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 92922de3..85271039 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -135,6 +135,7 @@ clean: rm -rf windows linux distclean: clean + rm -f $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) -- cgit v1.2.3 From 59ff9180f11063c257746b895a167179b3a4ff7c Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 2 Sep 2010 00:53:16 -0400 Subject: and a few more distclean fixes --- ao-tools/altosui/Makefile | 1 + doc/Makefile | 2 ++ 2 files changed, 3 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 85271039..abf5704f 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -136,6 +136,7 @@ clean: distclean: clean rm -f $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) + rm -rf darwin fat FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) diff --git a/doc/Makefile b/doc/Makefile index f8048dce..e840ec41 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -26,6 +26,8 @@ telemetrum-doc.pdf: telemetrum-doc.fo clean: rm -f telemetrum-doc.html telemetrum-doc.pdf telemetrum-doc.fo +distclean: clean + indent: telemetrum-doc.xsl xmlindent -i 2 < telemetrum-doc.xsl > telemetrum-doc.new -- cgit v1.2.3 From 2f07ad14a16dbf1b75c71784ceae303825c90ade Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:43:22 -0700 Subject: altosui: Abort flashing if debug port isn't working Check each command going over the debug port and make sure it works as expected. This commit adds checks for initializing the clock, selecting the desired program counter and running the flash program. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlash.java | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index b7018555..a3e431cd 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -202,9 +202,13 @@ public class AltosFlash { debug.debug_instr(set_clkcon_fast); byte status; - do { + for (int times = 0; times < 20; times++) { + Thread.sleep(1); status = debug.debug_instr(get_sleep); - } while ((status & SLEEP_XOSC_STB) == 0); + if ((status & SLEEP_XOSC_STB) != 0) + return; + } + throw new IOException("Failed to initialize target clock"); } void action(String s, int percent) { @@ -221,6 +225,22 @@ public class AltosFlash { percent); } + void run(int pc) throws IOException, InterruptedException { + debug.set_pc(pc); + int set_pc = debug.get_pc(); + if (pc != set_pc) + throw new IOException("Failed to set target program counter"); + debug.resume(); + + for (int times = 0; times < 20; times++) { + byte status = debug.read_status(); + if ((status & AltosDebug.STATUS_CPU_HALTED) != 0) + return; + } + + throw new IOException("Failed to execute program on target"); + } + public void flash() throws IOException, FileNotFoundException, InterruptedException { if (!check_rom_config()) throw new IOException("Invalid rom config settings"); @@ -264,16 +284,7 @@ public class AltosFlash { this_time); debug.write_memory(flash_prog, flash_page); - debug.set_pc(flash_prog); - int pc = debug.get_pc(); - debug.resume(); - Thread.sleep(100); - for (int times = 0; times < 10; times++) { - byte status = debug.read_status(); - if ((status & AltosDebug.STATUS_CPU_HALTED) != 0) - break; - Thread.sleep(100); - } + run(flash_prog); byte[] check = debug.read_memory(flash_addr, this_time); for (int i = 0; i < this_time; i++) -- cgit v1.2.3 From 9a690c9795e8257d2a3225f905117681668a472f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:46:04 -0700 Subject: altosui: allow flashing to be canceled from the rom config dialog Was using the rom config class wrong, causing cancel actions to work just like 'ok' actions. Oops. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlashUI.java | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 73a97a6b..18795695 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -75,17 +75,17 @@ public class AltosFlashUI AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); romconfig_ui.set(flash.romconfig()); - romconfig_ui.showDialog(); - - AltosRomconfig romconfig = romconfig_ui.romconfig(); - if (romconfig == null || !romconfig.valid()) - return; - flash.set_romconfig(romconfig); - serial_value.setText(String.format("%d", - flash.romconfig().serial_number)); - file_value.setText(file.toString()); - setVisible(true); - flash.flash(); + AltosRomconfig romconfig = romconfig_ui.showDialog(); + + if (romconfig != null && romconfig.valid()) { + flash.set_romconfig(romconfig); + serial_value.setText(String.format("%d", + flash.romconfig().serial_number)); + file_value.setText(file.toString()); + setVisible(true); + flash.flash(); + flash = null; + } } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, "Cannot open image", @@ -97,6 +97,8 @@ public class AltosFlashUI file.toString(), JOptionPane.ERROR_MESSAGE); } catch (InterruptedException ie) { + } finally { + abort(); } dispose(); } -- cgit v1.2.3 From 5ee6cd41ed189c3166f76558ecada80917f40652 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:47:15 -0700 Subject: altosui: Hide internal rom config UI helper function This was getting mis-used by the flash UI causing the rom dialog 'cancel' button to work just like 'ok'. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosRomconfigUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java index bc511865..10b3af80 100644 --- a/ao-tools/altosui/AltosRomconfigUI.java +++ b/ao-tools/altosui/AltosRomconfigUI.java @@ -162,7 +162,7 @@ public class AltosRomconfigUI } } - public AltosRomconfig romconfig() { + AltosRomconfig romconfig() { try { return new AltosRomconfig(serial(), radio_calibration()); } catch (NumberFormatException ne) { -- cgit v1.2.3 From 8d8980f56a4f2c7d6f2ce667130706e0f04f8ded Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:56:12 -0700 Subject: altosui: Remove some debug printfs from AltosRomconfig class Signed-off-by: Keith Packard --- ao-tools/altosui/AltosRomconfig.java | 6 ------ 1 file changed, 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java index 8c9cb27a..22d2dbd3 100644 --- a/ao-tools/altosui/AltosRomconfig.java +++ b/ao-tools/altosui/AltosRomconfig.java @@ -57,7 +57,6 @@ public class AltosRomconfig { static void put_usb_serial(int value, byte[] bytes, int start) { int offset = start + 0xa; int string_num = 0; - System.out.printf("Put usb serial %d\n", value); while (offset < bytes.length && bytes[offset] != 0) { if (bytes[offset + 1] == AO_USB_DESC_STRING) { @@ -67,13 +66,10 @@ public class AltosRomconfig { } offset += ((int) bytes[offset]) & 0xff; } - System.out.printf("offset %d content %d\n", - offset, bytes[offset]); if (offset >= bytes.length || bytes[offset] == 0) return; int len = ((((int) bytes[offset]) & 0xff) - 2) / 2; String fmt = String.format("%%0%dd", len); - System.out.printf("existing serial length %d format %s\n", len, fmt); String s = String.format(fmt, value); if (s.length() != len) { @@ -90,14 +86,12 @@ public class AltosRomconfig { public AltosRomconfig(byte[] bytes, int offset) { version = get_int(bytes, offset + 0, 2); check = get_int(bytes, offset + 2, 2); - System.out.printf("version %d check %d\n", version, check); if (check == (~version & 0xffff)) { switch (version) { case 2: case 1: serial_number = get_int(bytes, offset + 4, 2); radio_calibration = get_int(bytes, offset + 6, 4); - System.out.printf("serial %d cal %d\n", serial_number, radio_calibration); valid = true; break; } -- cgit v1.2.3 From cff0d1ef6b338b3d5ad9450d4d5f95df934cb5e4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:56:34 -0700 Subject: altosui: Post error dialog on invalid ROM config values. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosRomconfigUI.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java index 10b3af80..2134975d 100644 --- a/ao-tools/altosui/AltosRomconfigUI.java +++ b/ao-tools/altosui/AltosRomconfigUI.java @@ -134,8 +134,17 @@ public class AltosRomconfigUI public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); - if (cmd.equals("ok")) + if (cmd.equals("ok")) { + AltosRomconfig romconfig = romconfig(); + if (romconfig == null || !romconfig.valid()) { + JOptionPane.showMessageDialog(this, + "Invalid serial number or radio calibration value", + "Invalid rom configuration", + JOptionPane.ERROR_MESSAGE); + return; + } selected = true; + } setVisible(false); } -- cgit v1.2.3 From 3b3aa448f3a0f44137f7530b04b58967ba5f22f5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 2 Sep 2010 21:11:29 -0700 Subject: altosui: build Mac OS .zip file to include paths Without the paths, the OS X zip file doesn't create a usable application structure. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index abf5704f..0f5d05c8 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -159,7 +159,7 @@ $(DARWIN_ZIP): $(DARWIN_FILES) cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java mkdir -p darwin/AltOS cp $(DARWIN_EXTRA) darwin/AltOS - cd darwin && zip -j -r ../$@ AltosUI.app AltOS + cd darwin && zip -r ../$@ AltosUI.app AltOS WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf -- cgit v1.2.3 From e5ef42c2b22c6639d90631dbbb588f9fd2494385 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 01:12:24 -0700 Subject: altosui: Report telemetry CRC errors in UI Telemetry CRC errors can signal problems with TeleMetrum or TeleDongle units, so report them in the UI. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCRCException.java | 26 ++++++++++++++++++++++++++ ao-tools/altosui/AltosLog.java | 1 + ao-tools/altosui/AltosSerial.java | 2 +- ao-tools/altosui/AltosTelemetry.java | 9 ++++++++- ao-tools/altosui/AltosTelemetryReader.java | 2 ++ ao-tools/altosui/AltosUI.java | 26 +++++++++++++++++--------- ao-tools/altosui/Makefile | 1 + 7 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 ao-tools/altosui/AltosCRCException.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCRCException.java b/ao-tools/altosui/AltosCRCException.java new file mode 100644 index 00000000..4a529bcf --- /dev/null +++ b/ao-tools/altosui/AltosCRCException.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +public class AltosCRCException extends Exception { + public int rssi; + + public AltosCRCException (int in_rssi) { + rssi = in_rssi; + } +} diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java index ec868b9c..2c241771 100644 --- a/ao-tools/altosui/AltosLog.java +++ b/ao-tools/altosui/AltosLog.java @@ -74,6 +74,7 @@ class AltosLog implements Runnable { open(telem); } } catch (ParseException pe) { + } catch (AltosCRCException ce) { } if (log_file != null) { log_file.write(line); diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 99ba3324..c3daf3b9 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -71,7 +71,7 @@ public class AltosSerial implements Runnable { for (int i = 0; i < line_count; i++) line = line + line_bytes[i]; } - if (line.startsWith("VERSION")) { + if (line.startsWith("VERSION") || line.startsWith("CRC")) { for (int e = 0; e < monitors.size(); e++) { LinkedBlockingQueue q = monitors.get(e); q.put(line); diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index bc62690b..be22dac6 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -23,6 +23,7 @@ import java.util.HashMap; import altosui.AltosConvert; import altosui.AltosRecord; import altosui.AltosGPS; +import altosui.AltosCRCException; /* * Telemetry data contents @@ -53,10 +54,16 @@ import altosui.AltosGPS; */ public class AltosTelemetry extends AltosRecord { - public AltosTelemetry(String line) throws ParseException { + public AltosTelemetry(String line) throws ParseException, AltosCRCException { String[] words = line.split("\\s+"); int i = 0; + if (words[i].equals("CRC") && words[i+1].equals("INVALID")) { + i += 2; + AltosParse.word(words[i++], "RSSI"); + rssi = AltosParse.parse_int(words[i++]); + throw new AltosCRCException(rssi); + } if (words[i].equals("CALL")) { version = 0; } else { diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index a3402f9c..fdedbde2 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -62,6 +62,8 @@ public class AltosTelemetryReader extends AltosReader { records.add(record); } catch (ParseException pe) { System.out.printf("parse exception %s\n", pe.getMessage()); + } catch (AltosCRCException ce) { + System.out.printf("crc error\n"); } } } catch (IOException io) { diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 5b48e26f..e3f61303 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -168,21 +168,17 @@ public class AltosUI extends JFrame { flightInfoModel[i].finish(); } - public void show(AltosState state) { + public void show(AltosState state, int crc_errors) { flightStatusModel.set(state); info_reset(); - if (state.gps_ready) - info_add_row(0, "Ground state", "%s", "ready"); - else - info_add_row(0, "Ground state", "wait (%d)", - state.gps_waiting); info_add_row(0, "Rocket state", "%s", state.data.state()); info_add_row(0, "Callsign", "%s", state.data.callsign); info_add_row(0, "Rocket serial", "%6d", state.data.serial); info_add_row(0, "Rocket flight", "%6d", state.data.flight); info_add_row(0, "RSSI", "%6d dBm", state.data.rssi); + info_add_row(0, "CRC Errors", "%6d", crc_errors); info_add_row(0, "Height", "%6.0f m", state.height); info_add_row(0, "Max height", "%6.0f m", state.max_height); info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration); @@ -197,6 +193,11 @@ public class AltosUI extends JFrame { if (state.gps == null) { info_add_row(1, "GPS", "not available"); } else { + if (state.gps_ready) + info_add_row(1, "GPS state", "%s", "ready"); + else + info_add_row(1, "GPS state", "wait (%d)", + state.gps_waiting); if (state.data.gps.locked) info_add_row(1, "GPS", " locked"); else if (state.data.gps.connected) @@ -362,7 +363,11 @@ public class AltosUI extends JFrame { String name; - AltosRecord read() throws InterruptedException, ParseException { return null; } + int crc_errors; + + void init() { } + + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { return null; } void close() { } @@ -387,11 +392,14 @@ public class AltosUI extends JFrame { old_state = state; state = new AltosState(record, state); update(state); - show(state); + show(state, crc_errors); tell(state, old_state); idle_thread.notice(state); } catch (ParseException pp) { System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); + } catch (AltosCRCException ce) { + ++crc_errors; + show(state, crc_errors); } } } catch (InterruptedException ee) { @@ -411,7 +419,7 @@ public class AltosUI extends JFrame { AltosSerial serial; LinkedBlockingQueue telem; - AltosRecord read() throws InterruptedException, ParseException { + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { return new AltosTelemetry(telem.take()); } diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 0f5d05c8..8509391e 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -7,6 +7,7 @@ CLASSFILES=\ AltosConfig.class \ AltosConfigUI.class \ AltosConvert.class \ + AltosCRCException.class \ AltosCSV.class \ AltosCSVUI.class \ AltosDebug.class \ -- cgit v1.2.3 From ba65e4aeb952a1cf49a77f1e24e235508fcea71f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 01:21:57 -0700 Subject: altosui: Deal with altos bug setting radio channel while monitoring If the monitoring thread is active, then setting the radio channel can sometimes cause the monitoring thread to get stuck. I'm not entirely sure why though. For now, work around the issue by making sure monitoring is off, and the monitoring thread has stopped, before changing the radio channel. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index c3daf3b9..c4a7ad76 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -186,10 +186,14 @@ public class AltosSerial implements Runnable { public void set_channel(int channel) { if (altos != null) { + if (monitor_mode) { + printf("m 0\n"); + flush_input(); + } + printf("c r %d\n", channel); if (monitor_mode) - printf("m 0\nc r %d\nm 1\n", channel); - else - printf("c r %d\n", channel); + printf("m 1\n"); + flush_input(); } } @@ -198,8 +202,10 @@ public class AltosSerial implements Runnable { if (altos != null) { if (monitor) printf("m 1\n"); - else + else { printf("m 0\n"); + flush_input(); + } } } -- cgit v1.2.3 From 71191ecef3ba0e00d0f8a7cd1a24982bfa44ec72 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 01:30:33 -0700 Subject: altosui: Allow 'connect to device' when already connected Opening another serial device involves shutting down the display thread (to reset its state) and spawning another one. Shutting down the display thread normally closes the serial device as a part of the process, and if this isn't done before the new serial device is opened, then the new serial device ends up getting closed too. Interrupting the display thread and waiting for it to stop before opening the new serial device solves the problem. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index e3f61303..e63a004c 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -441,6 +441,7 @@ public class AltosUI extends JFrame { if (device != null) { try { + stop_display(); serial_line.open(device); DeviceThread thread = new DeviceThread(serial_line); serial_line.set_channel(AltosPreferences.channel()); @@ -536,8 +537,12 @@ public class AltosUI extends JFrame { Thread display_thread; private void stop_display() { - if (display_thread != null && display_thread.isAlive()) + if (display_thread != null && display_thread.isAlive()) { display_thread.interrupt(); + try { + display_thread.join(); + } catch (InterruptedException ie) {} + } display_thread = null; } -- cgit v1.2.3 From d4f64e95e31e2335470efc15df2ab357b7d197f3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 11:48:55 -0700 Subject: Revert "altosui: Deal with altos bug setting radio channel while monitoring" This reverts commit ba65e4aeb952a1cf49a77f1e24e235508fcea71f. Testing the old code --- ao-tools/altosui/AltosSerial.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index c4a7ad76..c3daf3b9 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -186,14 +186,10 @@ public class AltosSerial implements Runnable { public void set_channel(int channel) { if (altos != null) { - if (monitor_mode) { - printf("m 0\n"); - flush_input(); - } - printf("c r %d\n", channel); if (monitor_mode) - printf("m 1\n"); - flush_input(); + printf("m 0\nc r %d\nm 1\n", channel); + else + printf("c r %d\n", channel); } } @@ -202,10 +198,8 @@ public class AltosSerial implements Runnable { if (altos != null) { if (monitor) printf("m 1\n"); - else { + else printf("m 0\n"); - flush_input(); - } } } -- cgit v1.2.3 From 16d8d6a8853d09f683b13f9cda3c3174a0aab130 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 12:31:05 -0700 Subject: altosui: Must flush serial line after configuring for telemetry Without flushing the configuration commands to the serial device, it never sees them as the telemetry input thread doesn't flush. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index c3daf3b9..bc35d6b8 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -101,7 +101,8 @@ public class AltosSerial implements Runnable { } public void flush_output() { - libaltos.altos_flush(altos); + if (altos != null) + libaltos.altos_flush(altos); } public void flush_input() { @@ -180,8 +181,8 @@ public class AltosSerial implements Runnable { input_thread = new Thread(this); input_thread.start(); print("~\nE 0\n"); + flush_output(); set_monitor(monitor_mode); - flush_input(); } public void set_channel(int channel) { @@ -190,6 +191,7 @@ public class AltosSerial implements Runnable { printf("m 0\nc r %d\nm 1\n", channel); else printf("c r %d\n", channel); + flush_output(); } } @@ -200,12 +202,15 @@ public class AltosSerial implements Runnable { printf("m 1\n"); else printf("m 0\n"); + flush_output(); } } public void set_callsign(String callsign) { - if (altos != null) + if (altos != null) { printf ("c c %s\n", callsign); + flush_output(); + } } public AltosSerial() { -- cgit v1.2.3 From 59798c6fd11502a9c8b66090c23ba50eb250692e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 12:43:45 -0700 Subject: altosui: Catch I/O errors on telemetry device, report to user This catches the USB device being unplugged and makes sure the user sees an error dialog in this case. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosLine.java | 30 ++++++++++++++++++++++++++++++ ao-tools/altosui/AltosLog.java | 15 +++++++++------ ao-tools/altosui/AltosSerial.java | 34 ++++++++++++++++++++++------------ ao-tools/altosui/AltosUI.java | 27 +++++++++++++++++++-------- ao-tools/altosui/Makefile | 1 + ao-tools/libaltos/libaltos.c | 15 ++++++++++++++- 6 files changed, 95 insertions(+), 27 deletions(-) create mode 100644 ao-tools/altosui/AltosLine.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosLine.java b/ao-tools/altosui/AltosLine.java new file mode 100644 index 00000000..86e9d4c6 --- /dev/null +++ b/ao-tools/altosui/AltosLine.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +public class AltosLine { + public String line; + + public AltosLine() { + line = null; + } + + public AltosLine(String s) { + line = s; + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java index 2c241771..f876beba 100644 --- a/ao-tools/altosui/AltosLog.java +++ b/ao-tools/altosui/AltosLog.java @@ -24,6 +24,7 @@ import java.text.ParseException; import java.util.concurrent.LinkedBlockingQueue; import altosui.AltosSerial; import altosui.AltosFile; +import altosui.AltosLine; /* * This creates a thread to capture telemetry data and write it to @@ -31,7 +32,7 @@ import altosui.AltosFile; */ class AltosLog implements Runnable { - LinkedBlockingQueue input_queue; + LinkedBlockingQueue input_queue; LinkedBlockingQueue pending_queue; int serial; int flight; @@ -64,9 +65,11 @@ class AltosLog implements Runnable { public void run () { try { for (;;) { - String line = input_queue.take(); + AltosLine line = input_queue.take(); + if (line.line == null) + continue; try { - AltosTelemetry telem = new AltosTelemetry(line); + AltosTelemetry telem = new AltosTelemetry(line.line); if (telem.serial != serial || telem.flight != flight || log_file == null) { close(); serial = telem.serial; @@ -77,11 +80,11 @@ class AltosLog implements Runnable { } catch (AltosCRCException ce) { } if (log_file != null) { - log_file.write(line); + log_file.write(line.line); log_file.write('\n'); log_file.flush(); } else - pending_queue.put(line); + pending_queue.put(line.line); } } catch (InterruptedException ie) { } catch (IOException ie) { @@ -94,7 +97,7 @@ class AltosLog implements Runnable { public AltosLog (AltosSerial s) { pending_queue = new LinkedBlockingQueue (); - input_queue = new LinkedBlockingQueue (); + input_queue = new LinkedBlockingQueue (); s.add_monitor(input_queue); serial = -1; flight = -1; diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index bc35d6b8..a1fc4371 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -27,10 +27,12 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.LinkedList; import java.util.Iterator; import altosui.AltosSerialMonitor; +import altosui.AltosLine; import libaltosJNI.libaltos; import libaltosJNI.altos_device; import libaltosJNI.SWIGTYPE_p_altos_file; import libaltosJNI.SWIGTYPE_p_altos_list; +import libaltosJNI.libaltosConstants; /* * This class reads from the serial port and places each received @@ -41,8 +43,8 @@ import libaltosJNI.SWIGTYPE_p_altos_list; public class AltosSerial implements Runnable { SWIGTYPE_p_altos_file altos; - LinkedList> monitors; - LinkedBlockingQueue reply_queue; + LinkedList> monitors; + LinkedBlockingQueue reply_queue; Thread input_thread; String line; byte[] line_bytes; @@ -57,7 +59,15 @@ public class AltosSerial implements Runnable { c = libaltos.altos_getchar(altos, 0); if (Thread.interrupted()) break; - if (c == -1) + if (c == libaltosConstants.LIBALTOS_ERROR) { + for (int e = 0; e < monitors.size(); e++) { + LinkedBlockingQueue q = monitors.get(e); + q.put(new AltosLine()); + } + reply_queue.put (new AltosLine()); + break; + } + if (c == libaltosConstants.LIBALTOS_TIMEOUT) continue; if (c == '\r') continue; @@ -73,12 +83,12 @@ public class AltosSerial implements Runnable { } if (line.startsWith("VERSION") || line.startsWith("CRC")) { for (int e = 0; e < monitors.size(); e++) { - LinkedBlockingQueue q = monitors.get(e); - q.put(line); + LinkedBlockingQueue q = monitors.get(e); + q.put(new AltosLine (line)); } } else { // System.out.printf("GOT: %s\n", line); - reply_queue.put(line); + reply_queue.put(new AltosLine (line)); } line_count = 0; line = ""; @@ -121,16 +131,16 @@ public class AltosSerial implements Runnable { public String get_reply() throws InterruptedException { flush_output(); - String line = reply_queue.take(); - return line; + AltosLine line = reply_queue.take(); + return line.line; } - public void add_monitor(LinkedBlockingQueue q) { + public void add_monitor(LinkedBlockingQueue q) { set_monitor(true); monitors.add(q); } - public void remove_monitor(LinkedBlockingQueue q) { + public void remove_monitor(LinkedBlockingQueue q) { monitors.remove(q); if (monitors.isEmpty()) set_monitor(false); @@ -218,7 +228,7 @@ public class AltosSerial implements Runnable { input_thread = null; line = ""; monitor_mode = false; - monitors = new LinkedList> (); - reply_queue = new LinkedBlockingQueue (); + monitors = new LinkedList> (); + reply_queue = new LinkedBlockingQueue (); } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index e63a004c..7e3fb7f9 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -44,6 +44,7 @@ import altosui.AltosChannelMenu; import altosui.AltosFlashUI; import altosui.AltosLogfileChooser; import altosui.AltosCSVUI; +import altosui.AltosLine; import libaltosJNI.*; @@ -169,6 +170,8 @@ public class AltosUI extends JFrame { } public void show(AltosState state, int crc_errors) { + if (state == null) + return; flightStatusModel.set(state); info_reset(); @@ -367,7 +370,7 @@ public class AltosUI extends JFrame { void init() { } - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { return null; } + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } void close() { } @@ -403,6 +406,11 @@ public class AltosUI extends JFrame { } } } catch (InterruptedException ee) { + } catch (IOException ie) { + JOptionPane.showMessageDialog(AltosUI.this, + String.format("Error reading from \"%s\"", name), + "Telemetry Read Error", + JOptionPane.ERROR_MESSAGE); } finally { close(); idle_thread.interrupt(); @@ -417,10 +425,13 @@ public class AltosUI extends JFrame { class DeviceThread extends DisplayThread { AltosSerial serial; - LinkedBlockingQueue telem; + LinkedBlockingQueue telem; - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { - return new AltosTelemetry(telem.take()); + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { + AltosLine l = telem.take(); + if (l.line == null) + throw new IOException("IO error"); + return new AltosTelemetry(l.line); } void close() { @@ -428,11 +439,11 @@ public class AltosUI extends JFrame { serial.remove_monitor(telem); } - public DeviceThread(AltosSerial s) { + public DeviceThread(AltosSerial s, String in_name) { serial = s; - telem = new LinkedBlockingQueue(); + telem = new LinkedBlockingQueue(); serial.add_monitor(telem); - name = "telemetry"; + name = in_name; } } @@ -443,7 +454,7 @@ public class AltosUI extends JFrame { try { stop_display(); serial_line.open(device); - DeviceThread thread = new DeviceThread(serial_line); + DeviceThread thread = new DeviceThread(serial_line, device.getPath()); serial_line.set_channel(AltosPreferences.channel()); serial_line.set_callsign(AltosPreferences.callsign()); run_display(thread); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 8509391e..cc9a440d 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -23,6 +23,7 @@ CLASSFILES=\ AltosGPS.class \ AltosGreatCircle.class \ AltosHexfile.class \ + AltosLine.class \ AltosLog.class \ AltosLogfileChooser.class \ AltosParse.class \ diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 059d2ae9..465f0ac8 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -576,6 +576,11 @@ altos_free(struct altos_file *file) PUBLIC int altos_flush(struct altos_file *file) { + if (file->out_used && 0) { + printf ("flush \""); + fwrite(file->out_data, 1, file->out_used, stdout); + printf ("\"\n"); + } while (file->out_used) { int ret; @@ -634,7 +639,7 @@ altos_fill(struct altos_file *file, int timeout) return LIBALTOS_ERROR; #ifdef USE_POLL fd[0].fd = file->fd; - fd[0].events = POLLIN; + fd[0].events = POLLIN|POLLERR|POLLHUP|POLLNVAL; fd[1].fd = file->pipe[0]; fd[1].events = POLLIN; ret = poll(fd, 2, timeout); @@ -644,6 +649,9 @@ altos_fill(struct altos_file *file, int timeout) } if (ret == 0) return LIBALTOS_TIMEOUT; + + if (fd[0].revents & (POLLHUP|POLLERR|POLLNVAL)) + return LIBALTOS_ERROR; if (fd[0].revents & POLLIN) #endif { @@ -660,6 +668,11 @@ altos_fill(struct altos_file *file, int timeout) #endif } } + if (file->in_used && 0) { + printf ("fill \""); + fwrite(file->in_data, 1, file->in_used, stdout); + printf ("\"\n"); + } return 0; } -- cgit v1.2.3 From ecb4a09535b6a8da0765010489a96e605dbdeb46 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 00:13:11 -0700 Subject: altosui: Add windows installer build using 'nsis' nsis happens to be packaged in debian, and it appears to build usable installers, which is all very cool. Signed-off-by: Keith Packard --- .../Instdrv/NSIS/Contrib/InstDrv/Example.nsi | 84 +++ .../Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe | Bin 0 -> 51831 bytes .../altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c | 704 +++++++++++++++++++++ .../Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp | 110 ++++ .../Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw | 29 + .../Instdrv/NSIS/Contrib/InstDrv/Readme.txt | 141 +++++ .../Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf | 137 ++++ .../Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys | Bin 0 -> 30464 bytes ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll | Bin 0 -> 6656 bytes ao-tools/altosui/Makefile | 10 +- ao-tools/altosui/altos-windows.nsi | 102 +++ 11 files changed, 1312 insertions(+), 5 deletions(-) create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys create mode 100644 ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll create mode 100644 ao-tools/altosui/altos-windows.nsi (limited to 'ao-tools') diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi new file mode 100644 index 00000000..3ed821eb --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi @@ -0,0 +1,84 @@ +# +# InstDrv Example, (c) 2003 Jan Kiszka (Jan Kiszka@web.de) +# + +Name "InstDrv.dll test" + +OutFile "InstDrv-Test.exe" + +ShowInstDetails show + +ComponentText "InstDrv Plugin Usage Example" + +Page components +Page instfiles + +Section "Install a Driver" InstDriver + InstDrv::InitDriverSetup /NOUNLOAD "{4d36e978-e325-11ce-bfc1-08002be10318}" "IrCOMM2k" + Pop $0 + DetailPrint "InitDriverSetup: $0" + + InstDrv::DeleteOemInfFiles /NOUNLOAD + Pop $0 + DetailPrint "DeleteOemInfFiles: $0" + StrCmp $0 "00000000" PrintInfNames ContInst1 + + PrintInfNames: + Pop $0 + DetailPrint "Deleted $0" + Pop $0 + DetailPrint "Deleted $0" + + ContInst1: + InstDrv::CreateDevice /NOUNLOAD + Pop $0 + DetailPrint "CreateDevice: $0" + + SetOutPath $TEMP + File "ircomm2k.inf" + File "ircomm2k.sys" + + InstDrv::InstallDriver /NOUNLOAD "$TEMP\ircomm2k.inf" + Pop $0 + DetailPrint "InstallDriver: $0" + StrCmp $0 "00000000" PrintReboot ContInst2 + + PrintReboot: + Pop $0 + DetailPrint "Reboot: $0" + + ContInst2: + InstDrv::CountDevices + Pop $0 + DetailPrint "CountDevices: $0" +SectionEnd + +Section "Uninstall the driver again" UninstDriver + InstDrv::InitDriverSetup /NOUNLOAD "{4d36e978-e325-11ce-bfc1-08002be10318}" "IrCOMM2k" + Pop $0 + DetailPrint "InitDriverSetup: $0" + + InstDrv::DeleteOemInfFiles /NOUNLOAD + Pop $0 + DetailPrint "DeleteOemInfFiles: $0" + StrCmp $0 "00000000" PrintInfNames ContUninst1 + + PrintInfNames: + Pop $0 + DetailPrint "Deleted $0" + Pop $0 + DetailPrint "Deleted $0" + + ContUninst1: + InstDrv::RemoveAllDevices + Pop $0 + DetailPrint "RemoveAllDevices: $0" + StrCmp $0 "00000000" PrintReboot ContUninst2 + + PrintReboot: + Pop $0 + DetailPrint "Reboot: $0" + + ContUninst2: + Delete "$SYSDIR\system32\ircomm2k.sys" +SectionEnd \ No newline at end of file diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe new file mode 100644 index 00000000..615bae15 Binary files /dev/null and b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe differ diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c new file mode 100644 index 00000000..efe866e9 --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c @@ -0,0 +1,704 @@ +/* + +InstDrv.dll - Installs or Removes Device Drivers + +Copyright 2003 Jan Kiszka (Jan.Kiszka@web.de) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute +it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment in the + product documentation would be appreciated but is not required. +2. Altered versions must be plainly marked as such, + and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any distribution. + +*/ + + +#include +#include +#include +#include "../exdll/exdll.h" + + +char paramBuf[1024]; +GUID devClass; +char hwIdBuf[1024]; +int initialized = 0; + + + +void* memset(void* dst, int val, unsigned int len) +{ + while (len-- > 0) + *((char *)dst)++ = val; + + return NULL; +} + + + +void* memcpy(void* dst, const void* src, unsigned int len) +{ + while (len-- > 0) + *((char *)dst)++ = *((char *)src)++; + + return NULL; +} + + + +int HexCharToInt(char c) +{ + if ((c >= '0') && (c <= '9')) + return c - '0'; + else if ((c >= 'a') && (c <= 'f')) + return c - 'a' + 10; + else if ((c >= 'A') && (c <= 'F')) + return c - 'A' + 10; + else + return -1; +} + + + +BOOLEAN HexStringToUInt(char* str, int width, void* valBuf) +{ + int i, val; + + + for (i = width - 4; i >= 0; i -= 4) + { + val = HexCharToInt(*str++); + if (val < 0) + return FALSE; + *(unsigned int *)valBuf += val << i; + } + + return TRUE; +} + + + +BOOLEAN StringToGUID(char* guidStr, GUID* pGuid) +{ + int i; + + + memset(pGuid, 0, sizeof(GUID)); + + if (*guidStr++ != '{') + return FALSE; + + if (!HexStringToUInt(guidStr, 32, &pGuid->Data1)) + return FALSE; + guidStr += 8; + + if (*guidStr++ != '-') + return FALSE; + + if (!HexStringToUInt(guidStr, 16, &pGuid->Data2)) + return FALSE; + guidStr += 4; + + if (*guidStr++ != '-') + return FALSE; + + if (!HexStringToUInt(guidStr, 16, &pGuid->Data3)) + return FALSE; + guidStr += 4; + + if (*guidStr++ != '-') + return FALSE; + + for (i = 0; i < 2; i++) + { + if (!HexStringToUInt(guidStr, 8, &pGuid->Data4[i])) + return FALSE; + guidStr += 2; + } + + if (*guidStr++ != '-') + return FALSE; + + for (i = 2; i < 8; i++) + { + if (!HexStringToUInt(guidStr, 8, &pGuid->Data4[i])) + return FALSE; + guidStr += 2; + } + + if (*guidStr++ != '}') + return FALSE; + + return TRUE; +} + + + +DWORD FindNextDevice(HDEVINFO devInfoSet, SP_DEVINFO_DATA* pDevInfoData, DWORD* pIndex) +{ + DWORD buffersize = 0; + LPTSTR buffer = NULL; + DWORD dataType; + DWORD result; + + + while (1) + { + if (!SetupDiEnumDeviceInfo(devInfoSet, (*pIndex)++, pDevInfoData)) + { + result = GetLastError(); + break; + } + + GetDeviceRegistryProperty: + if (!SetupDiGetDeviceRegistryProperty(devInfoSet, pDevInfoData, SPDRP_HARDWAREID, + &dataType, (PBYTE)buffer, buffersize, + &buffersize)) + { + result = GetLastError(); + + if (result == ERROR_INSUFFICIENT_BUFFER) + { + if (buffer != NULL) + LocalFree(buffer); + + buffer = (LPTSTR)LocalAlloc(LPTR, buffersize); + + if (buffer == NULL) + break; + + goto GetDeviceRegistryProperty; + } + else if (result == ERROR_INVALID_DATA) + continue; // ignore invalid entries + else + break; // break on other errors + } + + if (lstrcmpi(buffer, hwIdBuf) == 0) + { + result = 0; + break; + } + } + + if (buffer != NULL) + LocalFree(buffer); + + return result; +} + + + +DWORD FindFirstDevice(HWND hwndParent, const GUID* pDevClass, const LPTSTR hwId, + HDEVINFO* pDevInfoSet, SP_DEVINFO_DATA* pDevInfoData, + DWORD *pIndex, DWORD flags) +{ + DWORD result; + + + *pDevInfoSet = SetupDiGetClassDevs((GUID*)pDevClass, NULL, hwndParent, flags); + if (*pDevInfoSet == INVALID_HANDLE_VALUE) + return GetLastError(); + + pDevInfoData->cbSize = sizeof(SP_DEVINFO_DATA); + *pIndex = 0; + + result = FindNextDevice(*pDevInfoSet, pDevInfoData, pIndex); + + if (result != 0) + SetupDiDestroyDeviceInfoList(*pDevInfoSet); + + return result; +} + + + +/* + * InstDrv::InitDriverSetup devClass drvHWID + * + * devClass - GUID of the driver's device setup class + * drvHWID - Hardware ID of the supported device + * + * Return: + * result - error message, empty on success + */ +void __declspec(dllexport) InitDriverSetup(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + EXDLL_INIT(); + + /* convert class GUID */ + popstring(paramBuf); + + if (!StringToGUID(paramBuf, &devClass)) + { + popstring(paramBuf); + pushstring("Invalid GUID!"); + return; + } + + /* get hardware ID */ + memset(hwIdBuf, 0, sizeof(hwIdBuf)); + popstring(hwIdBuf); + + initialized = 1; + pushstring(""); +} + + + +/* + * InstDrv::CountDevices + * + * Return: + * result - Number of installed devices the driver supports + */ +void __declspec(dllexport) CountDevices(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfoSet; + SP_DEVINFO_DATA devInfoData; + int count = 0; + char countBuf[16]; + DWORD index; + DWORD result; + + + EXDLL_INIT(); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + result = FindFirstDevice(hwndParent, &devClass, hwIdBuf, &devInfoSet, &devInfoData, + &index, DIGCF_PRESENT); + if (result != 0) + { + pushstring("0"); + return; + } + + do + { + count++; + } while (FindNextDevice(devInfoSet, &devInfoData, &index) == 0); + + SetupDiDestroyDeviceInfoList(devInfoSet); + + wsprintf(countBuf, "%d", count); + pushstring(countBuf); +} + + + +/* + * InstDrv::CreateDevice + * + * Return: + * result - Windows error code + */ +void __declspec(dllexport) CreateDevice(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfoSet; + SP_DEVINFO_DATA devInfoData; + DWORD result = 0; + char resultBuf[16]; + + + EXDLL_INIT(); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + devInfoSet = SetupDiCreateDeviceInfoList(&devClass, hwndParent); + if (devInfoSet == INVALID_HANDLE_VALUE) + { + wsprintf(resultBuf, "%08X", GetLastError()); + pushstring(resultBuf); + return; + } + + devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); + if (!SetupDiCreateDeviceInfo(devInfoSet, hwIdBuf, &devClass, NULL, + hwndParent, DICD_GENERATE_ID, &devInfoData)) + { + result = GetLastError(); + goto InstallCleanup; + } + + if (!SetupDiSetDeviceRegistryProperty(devInfoSet, &devInfoData, SPDRP_HARDWAREID, + hwIdBuf, (lstrlen(hwIdBuf)+2)*sizeof(TCHAR))) + { + result = GetLastError(); + goto InstallCleanup; + } + + if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, devInfoSet, &devInfoData)) + result = GetLastError(); + + InstallCleanup: + SetupDiDestroyDeviceInfoList(devInfoSet); + + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +/* + * InstDrv::InstallDriver infPath + * + * Return: + * result - Windows error code + * reboot - non-zero if reboot is required + */ +void __declspec(dllexport) InstallDriver(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + char resultBuf[16]; + BOOL reboot; + + + EXDLL_INIT(); + popstring(paramBuf); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + if (!UpdateDriverForPlugAndPlayDevices(hwndParent, hwIdBuf, paramBuf, + INSTALLFLAG_FORCE, &reboot)) + { + wsprintf(resultBuf, "%08X", GetLastError()); + pushstring(resultBuf); + } + else + { + wsprintf(resultBuf, "%d", reboot); + pushstring(resultBuf); + pushstring("00000000"); + } +} + + + +/* + * InstDrv::DeleteOemInfFiles + * + * Return: + * result - Windows error code + * oeminf - Path of the deleted devices setup file (oemXX.inf) + * oempnf - Path of the deleted devices setup file (oemXX.pnf) + */ +void __declspec(dllexport) DeleteOemInfFiles(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfo; + SP_DEVINFO_DATA devInfoData; + SP_DRVINFO_DATA drvInfoData; + SP_DRVINFO_DETAIL_DATA drvInfoDetail; + DWORD index; + DWORD result; + char resultBuf[16]; + + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + result = FindFirstDevice(NULL, &devClass, hwIdBuf, &devInfo, &devInfoData, &index, 0); + if (result != 0) + goto Cleanup1; + + if (!SetupDiBuildDriverInfoList(devInfo, &devInfoData, SPDIT_COMPATDRIVER)) + { + result = GetLastError(); + goto Cleanup2; + } + + drvInfoData.cbSize = sizeof(SP_DRVINFO_DATA); + drvInfoDetail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA); + + if (!SetupDiEnumDriverInfo(devInfo, &devInfoData, SPDIT_COMPATDRIVER, 0, &drvInfoData)) + { + result = GetLastError(); + goto Cleanup3; + } + + if (!SetupDiGetDriverInfoDetail(devInfo, &devInfoData, &drvInfoData, + &drvInfoDetail, sizeof(drvInfoDetail), NULL)) + { + result = GetLastError(); + + if (result != ERROR_INSUFFICIENT_BUFFER) + goto Cleanup3; + + result = 0; + } + + pushstring(drvInfoDetail.InfFileName); + if (!DeleteFile(drvInfoDetail.InfFileName)) + result = GetLastError(); + else + { + index = lstrlen(drvInfoDetail.InfFileName); + if (index > 3) + { + lstrcpy(drvInfoDetail.InfFileName+index-3, "pnf"); + pushstring(drvInfoDetail.InfFileName); + if (!DeleteFile(drvInfoDetail.InfFileName)) + result = GetLastError(); + } + } + + Cleanup3: + SetupDiDestroyDriverInfoList(devInfo, &devInfoData, SPDIT_COMPATDRIVER); + + Cleanup2: + SetupDiDestroyDeviceInfoList(devInfo); + + Cleanup1: + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +/* + * InstDrv::RemoveAllDevices + * + * Return: + * result - Windows error code + * reboot - non-zero if reboot is required + */ +void __declspec(dllexport) RemoveAllDevices(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfo; + SP_DEVINFO_DATA devInfoData; + DWORD index; + DWORD result; + char resultBuf[16]; + BOOL reboot = FALSE; + SP_DEVINSTALL_PARAMS instParams; + + + EXDLL_INIT(); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + result = FindFirstDevice(NULL, &devClass, hwIdBuf, &devInfo, &devInfoData, &index, 0); + if (result != 0) + goto Cleanup1; + + do + { + if (!SetupDiCallClassInstaller(DIF_REMOVE, devInfo, &devInfoData)) + { + result = GetLastError(); + break; + } + + instParams.cbSize = sizeof(instParams); + if (!reboot && + SetupDiGetDeviceInstallParams(devInfo, &devInfoData, &instParams) && + ((instParams.Flags & (DI_NEEDRESTART|DI_NEEDREBOOT)) != 0)) + { + reboot = TRUE; + } + + result = FindNextDevice(devInfo, &devInfoData, &index); + } while (result == 0); + + SetupDiDestroyDeviceInfoList(devInfo); + + Cleanup1: + if ((result == 0) || (result == ERROR_NO_MORE_ITEMS)) + { + wsprintf(resultBuf, "%d", reboot); + pushstring(resultBuf); + pushstring("00000000"); + } + else + { + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); + } +} + + + +/* + * InstDrv::StartSystemService serviceName + * + * Return: + * result - Windows error code + */ +void __declspec(dllexport) StartSystemService(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + SC_HANDLE managerHndl; + SC_HANDLE svcHndl; + SERVICE_STATUS svcStatus; + DWORD oldCheckPoint; + DWORD result; + char resultBuf[16]; + + + EXDLL_INIT(); + popstring(paramBuf); + + managerHndl = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (managerHndl == NULL) + { + result = GetLastError(); + goto Cleanup1; + } + + svcHndl = OpenService(managerHndl, paramBuf, SERVICE_START | SERVICE_QUERY_STATUS); + if (svcHndl == NULL) + { + result = GetLastError(); + goto Cleanup2; + } + + if (!StartService(svcHndl, 0, NULL) || !QueryServiceStatus(svcHndl, &svcStatus)) + { + result = GetLastError(); + goto Cleanup3; + } + + while (svcStatus.dwCurrentState == SERVICE_START_PENDING) + { + oldCheckPoint = svcStatus.dwCheckPoint; + + Sleep(svcStatus.dwWaitHint); + + if (!QueryServiceStatus(svcHndl, &svcStatus)) + { + result = GetLastError(); + break; + } + + if (oldCheckPoint >= svcStatus.dwCheckPoint) + { + if ((svcStatus.dwCurrentState == SERVICE_STOPPED) && + (svcStatus.dwWin32ExitCode != 0)) + result = svcStatus.dwWin32ExitCode; + else + result = ERROR_SERVICE_REQUEST_TIMEOUT; + } + } + + if (svcStatus.dwCurrentState == SERVICE_RUNNING) + result = 0; + + Cleanup3: + CloseServiceHandle(svcHndl); + + Cleanup2: + CloseServiceHandle(managerHndl); + + Cleanup1: + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +/* + * InstDrv::StopSystemService serviceName + * + * Return: + * result - Windows error code + */ +void __declspec(dllexport) StopSystemService(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + SC_HANDLE managerHndl; + SC_HANDLE svcHndl; + SERVICE_STATUS svcStatus; + DWORD oldCheckPoint; + DWORD result; + char resultBuf[16]; + + + EXDLL_INIT(); + popstring(paramBuf); + + managerHndl = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (managerHndl == NULL) + { + result = GetLastError(); + goto Cleanup1; + } + + svcHndl = OpenService(managerHndl, paramBuf, SERVICE_STOP | SERVICE_QUERY_STATUS); + if (svcHndl == NULL) + { + result = GetLastError(); + goto Cleanup2; + } + + if (!ControlService(svcHndl, SERVICE_CONTROL_STOP, &svcStatus)) + { + result = GetLastError(); + goto Cleanup3; + } + + while (svcStatus.dwCurrentState == SERVICE_STOP_PENDING) + { + oldCheckPoint = svcStatus.dwCheckPoint; + + Sleep(svcStatus.dwWaitHint); + + if (!QueryServiceStatus(svcHndl, &svcStatus)) + { + result = GetLastError(); + break; + } + + if (oldCheckPoint >= svcStatus.dwCheckPoint) + { + result = ERROR_SERVICE_REQUEST_TIMEOUT; + break; + } + } + + if (svcStatus.dwCurrentState == SERVICE_STOPPED) + result = 0; + + Cleanup3: + CloseServiceHandle(svcHndl); + + Cleanup2: + CloseServiceHandle(managerHndl); + + Cleanup1: + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + return TRUE; +} diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp new file mode 100644 index 00000000..874e66c7 --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="InstDrv" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=InstDrv - Win32 Debug +!MESSAGE Dies ist kein gltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE +!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und fhren Sie den Befehl +!MESSAGE +!MESSAGE NMAKE /f "InstDrv.mak". +!MESSAGE +!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben +!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: +!MESSAGE +!MESSAGE NMAKE /f "InstDrv.mak" CFG="InstDrv - Win32 Debug" +!MESSAGE +!MESSAGE Fr die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "InstDrv - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library") +!MESSAGE "InstDrv - Win32 Debug" (basierend auf "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "InstDrv - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O1 /I "C:\Programme\WINDDK\3790\inc\ddk\w2k" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib setupapi.lib newdev.lib /nologo /entry:"_DllMainCRTStartup" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/InstDrv.dll" /libpath:"C:\Programme\WINDDK\3790\lib\w2k\i386" /opt:nowin98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "InstDrv - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"_DllMainCRTStartup" /dll /debug /machine:I386 /pdbtype:sept +# SUBTRACT LINK32 /nodefaultlib + +!ENDIF + +# Begin Target + +# Name "InstDrv - Win32 Release" +# Name "InstDrv - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\InstDrv.c +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Ressourcendateien" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw new file mode 100644 index 00000000..b3d02f0e --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELSCHT WERDEN! + +############################################################################### + +Project: "InstDrv"=.\InstDrv.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt new file mode 100644 index 00000000..e5877aa6 --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt @@ -0,0 +1,141 @@ +InstDrv.dll version 0.2 - Installs or Removes Device Drivers +------------------------------------------------------------ + + +The plugin helps you to create NSIS scripts for installing device drivers or +removing them again. It can count installed device instances, create new ones +or delete all supported device. InstDrv works on Windows 2000 or later. + + + +InstDrv::InitDriverSetup devClass drvHWID +Return: result + +To start processing a driver, first call this function. devClass is the GUID +of the device class the driver supports, drvHWID is the device hardware ID. If +you don't know what these terms mean, you may want to take a look at the +Windows DDK. This function returns an empty string on success, otherwise an +error message. + +InitDriverSetup has to be called every time after the plugin dll has been +(re-)loaded, or if you want to switch to a different driver. + + + +InstDrv::CountDevices +Return: number + +This call returns the number of installed and supported devices of the driver. + + + +InstDrv::CreateDevice +Return: result + +To create a new deviced node which the driver has to support, use this +function. You may even call it multiple times for more than one instance. The +return value is the Windows error code (in hex). Use CreateDevice before +installing or updating the driver itself. + + + +InstDrv::InstallDriver infPath +Return: result + reboot + +InstallDriver installs or updates a device driver as specified in the .inf +setup script. It returns a Windows error code (in hex) and, on success, a flag +signalling if a system reboot is required. + + + +InstDrv::DeleteOemInfFiles +Return: result + oeminf + oempnf + +DeleteOemInfFiles tries to clean up the Windows inf directory by deleting the +oemXX.inf and oemXX.pnf files associated with the drivers. It returns a +Windows error code (in hex) and, on success, the names of the deleted files. +This functions requires that at least one device instance is still present. +So, call it before you remove the devices itself. You should also call it +before updating a driver. This avoids that the inf directory gets slowly +messed up with useless old setup scripts (which does NOT really accelerate +Windows). The error code which comes up when no device is installed is +"00000103". + + + +InstDrv::RemoveAllDevices +Return: result + reboot + +This functions deletes all devices instances the driver supported. It returns +a Windows error code (in hex) and, on success, a flag signalling if the system +needs to be rebooted. You additionally have to remove the driver binaries from +the system paths. + + + +InstDrv::StartSystemService serviceName +Return: result + +Call this function to start the provided system service. The function blocks +until the service is started or the system reported a timeout. The return value +is the Windows error code (in hex). + + + +InstDrv::StopSystemService serviceName +Return: result + +This function tries to stop the provided system service. It blocks until the +service has been shut down or the system reported a timeout. The return value +is the Windows error code (in hex). + + + +Example.nsi + +The example script installs or removes the virtual COM port driver of IrCOMM2k +(2.0.0-alpha8, see www.ircomm2k.de/english). The driver and its setup script +are only included for demonstration purposes, they do not work without the +rest of IrCOMM2k (but they also do not cause any harm). + + + +Building the Source Code + +To build the plugin from the source code, some include files and libraries +which come with the Windows DDK are required. + + + +History + + 0.2 - fixed bug when calling InitDriverSetup the second time + - added StartSystemService and StopSystemService + + 0.1 - first release + + + +License + +Copyright 2003 Jan Kiszka (Jan.Kiszka@web.de) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute +it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment in the + product documentation would be appreciated but is not required. +2. Altered versions must be plainly marked as such, + and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any distribution. diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf new file mode 100644 index 00000000..ccda1d87 --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf @@ -0,0 +1,137 @@ +; IrCOMM2k.inf +; +; Installation file for the Virtual Infrared-COM-Port +; +; (c) Copyright 2001, 2002 Jan Kiszka +; + +[Version] +Signature="$Windows NT$" +Provider=%JK% +Class=Ports +ClassGUID={4d36e978-e325-11ce-bfc1-08002be10318} +;DriverVer=03/26/2002,1.2.1.0 + +[DestinationDirs] +IrCOMM2k.Copy2Drivers = 12 +IrCOMM2k.Copy2Winnt = 10 +IrCOMM2k.Copy2System32 = 11 +IrCOMM2k.Copy2Help = 18 + + +; +; Driver information +; + +[Manufacturer] +%JK% = JK.Mfg + +[JK.Mfg] +%JK.DeviceDescIrCOMM% = IrCOMM2k_inst,IrCOMM2k + + +; +; General installation section +; + +[IrCOMM2k_inst] +CopyFiles = IrCOMM2k.Copy2Drivers ;,IrCOMM2k.Copy2System32,IrCOMM2k.Copy2Help,IrCOMM2k.Copy2Winnt +;AddReg = IrCOMM2k_inst_AddReg + + +; +; File sections +; + +[IrCOMM2k.Copy2Drivers] +ircomm2k.sys,,,2 + +;[IrCOMM2k.Copy2System32] +;ircomm2k.exe,,,2 +;ircomm2k.dll,,,2 + +;[IrCOMM2k.Copy2Help] +;ircomm2k.hlp,,,2 + +;[IrCOMM2k.Copy2Winnt] +;IrCOMM2k-Setup.exe,Setup.exe,,2 + + +; +; Service Installation +; + +[IrCOMM2k_inst.Services] +AddService = IrCOMM2k,0x00000002,IrCOMM2k_DriverService_Inst,IrCOMM2k_DriverEventLog_Inst +;AddService = IrCOMM2kSvc,,IrCOMM2k_Service_Inst + +[IrCOMM2k_DriverService_Inst] +DisplayName = %IrCOMM2k.DrvName% +ServiceType = 1 ; SERVICE_KERNEL_DRIVER +StartType = 3 ; SERVICE_DEMAND_START +ErrorControl = 0 ; SERVICE_ERROR_IGNORE +ServiceBinary = %12%\ircomm2k.sys + +;[IrCOMM2k_Service_Inst] +;DisplayName = %IrCOMM2k.SvcName% +;Description = %IrCOMM2k.SvcDesc% +;ServiceType = 0x00000120 ; SERVICE_WIN32_SHARE_PROCESS, SERVICE_INTERACTIVE_PROCESS +;StartType = 2 ; SERVICE_AUTO_START +;ErrorControl = 0 ; SERVICE_ERROR_IGNORE +;ServiceBinary = %11%\ircomm2k.exe +;Dependencies = IrCOMM2k +;AddReg = IrCOMM2kSvcAddReg + + +[IrCOMM2k_inst.nt.HW] +AddReg=IrCOMM2kHwAddReg + +[IrCOMM2kHwAddReg] +HKR,,PortSubClass,REG_BINARY,0x00000001 +;HKR,,TimeoutScaling,REG_DWORD,0x00000001 +;HKR,,StatusLines,REG_DWORD,0x00000000 + +;[IrCOMM2k_inst_AddReg] +;HKR,,EnumPropPages32,,"ircomm2k.dll,IrCOMM2kPropPageProvider" +;HKLM,%UNINSTALL_KEY%,DisplayIcon,0x00020000,"%windir%\IrCOMM2k-Setup.exe" +;HKLM,%UNINSTALL_KEY%,DisplayName,,"IrCOMM2k 1.2.1 " +;HKLM,%UNINSTALL_KEY%,DisplayVersion,,"1.2.1" +;HKLM,%UNINSTALL_KEY%,HelpLink,,"http://www.ircomm2k.de" +;HKLM,%UNINSTALL_KEY%,Publisher,,%JK% +;HKLM,%UNINSTALL_KEY%,UninstallString,0x00020000,"%windir%\IrCOMM2k-Setup.exe" + +;[IrCOMM2kSvcAddReg] +;HKR,Parameters,ActiveConnectOnly,REG_DWORD,0x00000000 + + +[IrCOMM2k_DriverEventLog_Inst] +AddReg = IrCOMM2k_DriverEventLog_AddReg + +[IrCOMM2k_DriverEventLog_AddReg] +HKR,,EventMessageFile,REG_EXPAND_SZ,"%SystemRoot%\System32\IoLogMsg.dll;%SystemRoot%\System32\drivers\ircomm2k.sys" +HKR,,TypesSupported,REG_DWORD,7 + + +[Strings] + +; +; Non-Localizable Strings +; + +REG_SZ = 0x00000000 +REG_MULTI_SZ = 0x00010000 +REG_EXPAND_SZ = 0x00020000 +REG_BINARY = 0x00000001 +REG_DWORD = 0x00010001 +SERVICEROOT = "System\CurrentControlSet\Services" +UNINSTALL_KEY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrCOMM2k" + +; +; Localizable Strings +; + +JK = "Jan Kiszka" +JK.DeviceDescIrCOMM = "Virtueller Infrarot-Kommunikationsanschluss" +IrCOMM2k.DrvName = "Virtueller Infrarot-Kommunikationsanschluss" +;IrCOMM2k.SvcName = "Virtueller Infrarot-Kommunikationsanschlu, Dienstprogramm" +;IrCOMM2k.SvcDesc = "Bildet ber Infarot einen Kommunikationsanschlu nach." diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys new file mode 100644 index 00000000..7882583b Binary files /dev/null and b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys differ diff --git a/ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll b/ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll new file mode 100644 index 00000000..482e955e Binary files /dev/null and b/ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll differ diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index cc9a440d..58acb26e 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -75,12 +75,12 @@ LINUX_APP=altosui DARWIN_ZIP=Altos-Mac.zip -WINDOWS_ZIP=Altos-Windows.zip +WINDOWS_EXE=Altos-Windows.exe LINUX_TGZ=Altos-Linux.tgz all: altosui.jar $(LINUX_APP) -fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) +fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) $(CLASSFILES): @@ -137,7 +137,7 @@ clean: rm -rf windows linux distclean: clean - rm -f $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) + rm -f $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) rm -rf darwin fat FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) @@ -165,9 +165,9 @@ $(DARWIN_ZIP): $(DARWIN_FILES) WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf -$(WINDOWS_ZIP): $(WINDOWS_FILES) +$(WINDOWS_EXE): $(WINDOWS_FILES) altos-install.nsi rm -f $@ mkdir -p windows/AltOS rm -f windows/AltOS/* cp $(WINDOWS_FILES) windows/AltOS - cd windows && zip -j -r ../$@ AltOS + makensis altos-windows.nsi diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi new file mode 100644 index 00000000..abb0823b --- /dev/null +++ b/ao-tools/altosui/altos-windows.nsi @@ -0,0 +1,102 @@ +!addplugindir Instdrv/NSIS/Plugins + +Name "Altus Metrum Installer" + +OutFile "Altos-Windows.exe" + +; Default install directory +InstallDir "$PROGRAMFILES\AltusMetrum" + +; Tell the installer where to re-install a new version +InstallDirRegKey HKLM "Software\AltusMetrum" "Install_Dir" + +LicenseText "GNU General Public License Version 2" +LicenseData "../../COPYING" + +; Need admin privs for Vista or Win7 +RequestExecutionLevel admin + +ShowInstDetails Show + +ComponentText "Altus Metrum Software and Driver Installer" + +; Pages to present + +Page license +Page components +Page directory +Page instfiles + +UninstPage uninstConfirm +UninstPage instfiles + +; And the stuff to install + +Section "Install Driver" InstDriver + InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} "Altus Metrum" + Pop $0 + DetailPrint "InitDriverSetup: $0" + + InstDrv::DeleteOemInfFiles /NOUNLOAD + InstDrv::CreateDevice /NOUNLOAD + SetOutPath $TEMP + File "../../telemetrum.inf" + InstDrv::InstallDriver /NOUNLOAD "$TEMP\telemetrum.inf" +SectionEnd + +Section "AltosUI Application" + SetOutPath $INSTDIR + + File "windows/AltOS/*.jar" + File "windows/AltOS/*.dll" + + CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" +SectionEnd + +Section "AltosUI Desktop Shortcut" + CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui.jar" +SectionEnd + +Section "TeleMetrum and TeleDongle Firmware" + + SetOutPath $INSTDIR + + File "windows/AltOS/telemetrum-v1.0.ihx" + File "windows/AltOS/teledongle-v0.2.ihx" + +SectionEnd + +Section "Uninstaller" + + ; Deal with the uninstaller + + SetOutPath $INSTDIR + + ; Write the install path to the registry + WriteRegStr HKLM SOFTWARE\AltusMetrum "Install_Dir" "$INSTDIR" + + ; Write the uninstall keys for windows + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "DisplayName" "Altus Metrum" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "UninstallString" '"$INSTDIR\uninstall.exe"' + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoModify" "1" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoRepair" "1" + + WriteUninstaller "uninstall.exe" +SectionEnd + +Section "Uninstall" + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" + DeleteRegKey HKLM "Software\AltusMetrum" + + Delete "$INSTDIR\*.*" + RMDir "$INSTDIR" + + ; Remove devices + InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} "Altus Metrum" + InstDrv::DeleteOemInfFiles /NOUNLOAD + InstDrv::RemoveAllDevices + + ; Remove shortcuts, if any + Delete "$SMPROGRAMS\AltusMetrum.lnk" + Delete "$DESKTOP\AltusMetrum.lnk" +SectionEnd -- cgit v1.2.3 From c0988ddbf104ea729090c2e7e2a28cc6dc9e90f6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 00:14:15 -0700 Subject: altosui: ignore built files --- ao-tools/altosui/.gitignore | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/.gitignore b/ao-tools/altosui/.gitignore index 59913193..63672058 100644 --- a/ao-tools/altosui/.gitignore +++ b/ao-tools/altosui/.gitignore @@ -1,2 +1,14 @@ +windows/ +linux/ +darwin/ +fat/ +Manifest.txt +libaltosJNI +classes +altosui +Altos-Linux.tgz +Altos-Mac.zip +Altos-Windows.exe +*.jar *.class altosui -- cgit v1.2.3 From f550677df016070430ed38bfa2b2be33f1b8c40a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 00:16:41 -0700 Subject: altosui: oops. renamed the nsis file to altos-windows.nsi And forgot to change the dependency in the Makefile Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 58acb26e..92f0e690 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -165,7 +165,7 @@ $(DARWIN_ZIP): $(DARWIN_FILES) WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf -$(WINDOWS_EXE): $(WINDOWS_FILES) altos-install.nsi +$(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi rm -f $@ mkdir -p windows/AltOS rm -f windows/AltOS/* -- cgit v1.2.3 From e844e8a0695e27af6f8e3e37a5e3bcc865b862e3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 01:13:42 -0700 Subject: altosui: Add icons to application and Windows menus. Use the altus-metrum icon for an application icon and a windows start menu/desktop icon. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 4 ++++ ao-tools/altosui/Makefile | 19 ++++++++++++++----- ao-tools/altosui/altos-windows.nsi | 6 ++++-- 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 7e3fb7f9..eb376be4 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -75,6 +75,10 @@ public class AltosUI extends JFrame { String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; Object[][] statusData = { { "0", "pad", "-50", "0" } }; + java.net.URL imgURL = AltosUI.class.getResource("/images/altus-metrum-16x16.jpg"); + if (imgURL != null) + setIconImage(new ImageIcon(imgURL).getImage()); + AltosPreferences.init(this); vbox = Box.createVerticalBox(); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 92f0e690..90621f36 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -42,6 +42,9 @@ CLASSFILES=\ AltosRomconfigUI.class \ AltosVoice.class +JAVA_ICON=../../icon/altus-metrum-16x16.jpg +WINDOWS_ICON=../../icon/altus-metrum.ico + # where altosui.jar gets installed ALTOSLIB=/usr/share/java @@ -87,8 +90,8 @@ $(CLASSFILES): .java.class: javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java -altosui.jar: classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt - cd ./classes && jar cfm ../$@ altosui/Manifest.txt altosui/*.class libaltosJNI/*.class +altosui.jar: classes/images classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt + cd ./classes && jar cfm ../$@ altosui/Manifest.txt images/* altosui/*.class libaltosJNI/*.class Manifest.txt: Makefile $(CLASSFILES) echo 'Main-Class: altosui.AltosUI' > $@ @@ -102,6 +105,10 @@ classes/libaltosJNI: mkdir -p classes ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI +classes/images: + mkdir -p classes/images + ln -sf ../../$(JAVA_ICON) classes/images + altosui: echo "#!/bin/sh" > $@ echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ @@ -114,11 +121,13 @@ fat/altosui: echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ chmod +x $@ -fat/altosui.jar: $(CLASSFILES) fat/classes/Manifest.txt +fat/altosui.jar: $(CLASSFILES) $(JAVA_ICON) fat/classes/Manifest.txt mkdir -p fat/classes test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui + mkdir -p fat/classes/images + cp $(JAVA_ICON) fat/classes/images test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI - cd ./fat/classes && jar cfm ../../$@ Manifest.txt altosui/*.class libaltosJNI/*.class + cd ./fat/classes && jar cfm ../../$@ Manifest.txt images/* altosui/*.class libaltosJNI/*.class fat/classes/Manifest.txt: $(CLASSFILES) Makefile mkdir -p fat/classes @@ -163,7 +172,7 @@ $(DARWIN_ZIP): $(DARWIN_FILES) cp $(DARWIN_EXTRA) darwin/AltOS cd darwin && zip -r ../$@ AltosUI.app AltOS -WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf +WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ICON) $(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi rm -f $@ diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi index abb0823b..5ac708f9 100644 --- a/ao-tools/altosui/altos-windows.nsi +++ b/ao-tools/altosui/altos-windows.nsi @@ -50,11 +50,13 @@ Section "AltosUI Application" File "windows/AltOS/*.jar" File "windows/AltOS/*.dll" - CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" + File "windows/AltOS/*.ico" + + CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd Section "AltosUI Desktop Shortcut" - CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui.jar" + CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd Section "TeleMetrum and TeleDongle Firmware" -- cgit v1.2.3 From 887b11f6b9c81b9f15348d54017e700ca7dc5e55 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 17:27:17 -0700 Subject: Use autotools for altosui and libaltos This switches from hand-written Makefiles to automake with libtool for these parts of the system. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 2 +- ao-tools/altosui/Makefile | 182 ---------------------------------- ao-tools/altosui/Makefile-standalone | 182 ++++++++++++++++++++++++++++++++++ ao-tools/altosui/Makefile.am | 165 ++++++++++++++++++++++++++++++ ao-tools/altosui/altos-windows.nsi | 20 ++-- ao-tools/altosui/altosui-fat | 4 + ao-tools/libaltos/.gitignore | 12 +++ ao-tools/libaltos/Makefile | 126 ----------------------- ao-tools/libaltos/Makefile-standalone | 126 +++++++++++++++++++++++ ao-tools/libaltos/Makefile.am | 27 +++++ configure.ac | 39 +++++++- 11 files changed, 566 insertions(+), 319 deletions(-) delete mode 100644 ao-tools/altosui/Makefile create mode 100644 ao-tools/altosui/Makefile-standalone create mode 100644 ao-tools/altosui/Makefile.am create mode 100755 ao-tools/altosui/altosui-fat create mode 100644 ao-tools/libaltos/.gitignore delete mode 100644 ao-tools/libaltos/Makefile create mode 100644 ao-tools/libaltos/Makefile-standalone create mode 100644 ao-tools/libaltos/Makefile.am (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index eb376be4..37625e8e 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -75,7 +75,7 @@ public class AltosUI extends JFrame { String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; Object[][] statusData = { { "0", "pad", "-50", "0" } }; - java.net.URL imgURL = AltosUI.class.getResource("/images/altus-metrum-16x16.jpg"); + java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg"); if (imgURL != null) setIconImage(new ImageIcon(imgURL).getImage()); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile deleted file mode 100644 index 90621f36..00000000 --- a/ao-tools/altosui/Makefile +++ /dev/null @@ -1,182 +0,0 @@ -.SUFFIXES: .java .class - -CLASSPATH=classes:./*:/usr/share/java/* -CLASSFILES=\ - Altos.class \ - AltosChannelMenu.class \ - AltosConfig.class \ - AltosConfigUI.class \ - AltosConvert.class \ - AltosCRCException.class \ - AltosCSV.class \ - AltosCSVUI.class \ - AltosDebug.class \ - AltosEepromDownload.class \ - AltosEepromMonitor.class \ - AltosEepromReader.class \ - AltosEepromRecord.class \ - AltosFile.class \ - AltosFlash.class \ - AltosFlashUI.class \ - AltosFlightInfoTableModel.class \ - AltosFlightStatusTableModel.class \ - AltosGPS.class \ - AltosGreatCircle.class \ - AltosHexfile.class \ - AltosLine.class \ - AltosLog.class \ - AltosLogfileChooser.class \ - AltosParse.class \ - AltosPreferences.class \ - AltosReader.class \ - AltosRecord.class \ - AltosSerialMonitor.class \ - AltosSerial.class \ - AltosState.class \ - AltosTelemetry.class \ - AltosTelemetryReader.class \ - AltosUI.class \ - AltosDevice.class \ - AltosDeviceDialog.class \ - AltosRomconfig.class \ - AltosRomconfigUI.class \ - AltosVoice.class - -JAVA_ICON=../../icon/altus-metrum-16x16.jpg -WINDOWS_ICON=../../icon/altus-metrum.ico - -# where altosui.jar gets installed -ALTOSLIB=/usr/share/java - -# where freetts.jar is to be found -FREETTSLIB=/usr/share/java - -# all of the freetts files -FREETTSJAR= \ - $(FREETTSLIB)/cmudict04.jar \ - $(FREETTSLIB)/cmulex.jar \ - $(FREETTSLIB)/cmu_time_awb.jar \ - $(FREETTSLIB)/cmutimelex.jar \ - $(FREETTSLIB)/cmu_us_kal.jar \ - $(FREETTSLIB)/en_us.jar \ - $(FREETTSLIB)/freetts.jar - -# The current hex files -HEXLIB=../../src -HEXFILES = \ - $(HEXLIB)/telemetrum-v1.0.ihx \ - $(HEXLIB)/teledongle-v0.2.ihx - -JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation - -ALTOSUIJAR = altosui.jar -FATJAR = fat/altosui.jar - -OS:=$(shell uname) - -LINUX_APP=altosui - -DARWIN_ZIP=Altos-Mac.zip - -WINDOWS_EXE=Altos-Windows.exe - -LINUX_TGZ=Altos-Linux.tgz - -all: altosui.jar $(LINUX_APP) -fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) - -$(CLASSFILES): - -.java.class: - javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java - -altosui.jar: classes/images classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt - cd ./classes && jar cfm ../$@ altosui/Manifest.txt images/* altosui/*.class libaltosJNI/*.class - -Manifest.txt: Makefile $(CLASSFILES) - echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTSLIB)/freetts.jar" >> $@ - -classes/altosui: - mkdir -p classes - ln -sf .. classes/altosui - -classes/libaltosJNI: - mkdir -p classes - ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI - -classes/images: - mkdir -p classes/images - ln -sf ../../$(JAVA_ICON) classes/images - -altosui: - echo "#!/bin/sh" > $@ - echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ - chmod +x ./altosui - -fat/altosui: - echo "#!/bin/sh" > $@ - echo 'ME=`which "$0"`' >> $@ - echo 'DIR=`dirname "$ME"`' >> $@ - echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ - chmod +x $@ - -fat/altosui.jar: $(CLASSFILES) $(JAVA_ICON) fat/classes/Manifest.txt - mkdir -p fat/classes - test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui - mkdir -p fat/classes/images - cp $(JAVA_ICON) fat/classes/images - test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI - cd ./fat/classes && jar cfm ../../$@ Manifest.txt images/* altosui/*.class libaltosJNI/*.class - -fat/classes/Manifest.txt: $(CLASSFILES) Makefile - mkdir -p fat/classes - echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: freetts.jar" >> $@ - -install: altosui.jar altosui - install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar - install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 - install altosui $(DESTDIR)/usr/bin/altosui - -clean: - rm -f *.class altosui.jar - rm -f AltosUI.app/Contents/Resources/Java/* - rm -rf classes - rm -rf windows linux - -distclean: clean - rm -f $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) - rm -rf darwin fat - -FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) - -LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui -$(LINUX_TGZ): $(LINUX_FILES) - rm -f $@ - mkdir -p linux/AltOS - rm -f linux/AltOS/* - cp $(LINUX_FILES) linux/AltOS - cd linux && tar czf ../$@ AltOS - -DARWIN_RESOURCES=$(FATJAR) $(FREETTSJAR) ../libaltos/libaltos.dylib -DARWIN_EXTRA=$(HEXFILES) -DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) - -$(DARWIN_ZIP): $(DARWIN_FILES) - rm -f $@ - cp -a AltosUI.app darwin/ - mkdir -p darwin/AltosUI.app/Contents/Resources/Java - cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java - mkdir -p darwin/AltOS - cp $(DARWIN_EXTRA) darwin/AltOS - cd darwin && zip -r ../$@ AltosUI.app AltOS - -WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ICON) - -$(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi - rm -f $@ - mkdir -p windows/AltOS - rm -f windows/AltOS/* - cp $(WINDOWS_FILES) windows/AltOS - makensis altos-windows.nsi diff --git a/ao-tools/altosui/Makefile-standalone b/ao-tools/altosui/Makefile-standalone new file mode 100644 index 00000000..90621f36 --- /dev/null +++ b/ao-tools/altosui/Makefile-standalone @@ -0,0 +1,182 @@ +.SUFFIXES: .java .class + +CLASSPATH=classes:./*:/usr/share/java/* +CLASSFILES=\ + Altos.class \ + AltosChannelMenu.class \ + AltosConfig.class \ + AltosConfigUI.class \ + AltosConvert.class \ + AltosCRCException.class \ + AltosCSV.class \ + AltosCSVUI.class \ + AltosDebug.class \ + AltosEepromDownload.class \ + AltosEepromMonitor.class \ + AltosEepromReader.class \ + AltosEepromRecord.class \ + AltosFile.class \ + AltosFlash.class \ + AltosFlashUI.class \ + AltosFlightInfoTableModel.class \ + AltosFlightStatusTableModel.class \ + AltosGPS.class \ + AltosGreatCircle.class \ + AltosHexfile.class \ + AltosLine.class \ + AltosLog.class \ + AltosLogfileChooser.class \ + AltosParse.class \ + AltosPreferences.class \ + AltosReader.class \ + AltosRecord.class \ + AltosSerialMonitor.class \ + AltosSerial.class \ + AltosState.class \ + AltosTelemetry.class \ + AltosTelemetryReader.class \ + AltosUI.class \ + AltosDevice.class \ + AltosDeviceDialog.class \ + AltosRomconfig.class \ + AltosRomconfigUI.class \ + AltosVoice.class + +JAVA_ICON=../../icon/altus-metrum-16x16.jpg +WINDOWS_ICON=../../icon/altus-metrum.ico + +# where altosui.jar gets installed +ALTOSLIB=/usr/share/java + +# where freetts.jar is to be found +FREETTSLIB=/usr/share/java + +# all of the freetts files +FREETTSJAR= \ + $(FREETTSLIB)/cmudict04.jar \ + $(FREETTSLIB)/cmulex.jar \ + $(FREETTSLIB)/cmu_time_awb.jar \ + $(FREETTSLIB)/cmutimelex.jar \ + $(FREETTSLIB)/cmu_us_kal.jar \ + $(FREETTSLIB)/en_us.jar \ + $(FREETTSLIB)/freetts.jar + +# The current hex files +HEXLIB=../../src +HEXFILES = \ + $(HEXLIB)/telemetrum-v1.0.ihx \ + $(HEXLIB)/teledongle-v0.2.ihx + +JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation + +ALTOSUIJAR = altosui.jar +FATJAR = fat/altosui.jar + +OS:=$(shell uname) + +LINUX_APP=altosui + +DARWIN_ZIP=Altos-Mac.zip + +WINDOWS_EXE=Altos-Windows.exe + +LINUX_TGZ=Altos-Linux.tgz + +all: altosui.jar $(LINUX_APP) +fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) + +$(CLASSFILES): + +.java.class: + javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java + +altosui.jar: classes/images classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt + cd ./classes && jar cfm ../$@ altosui/Manifest.txt images/* altosui/*.class libaltosJNI/*.class + +Manifest.txt: Makefile $(CLASSFILES) + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: $(FREETTSLIB)/freetts.jar" >> $@ + +classes/altosui: + mkdir -p classes + ln -sf .. classes/altosui + +classes/libaltosJNI: + mkdir -p classes + ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI + +classes/images: + mkdir -p classes/images + ln -sf ../../$(JAVA_ICON) classes/images + +altosui: + echo "#!/bin/sh" > $@ + echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ + chmod +x ./altosui + +fat/altosui: + echo "#!/bin/sh" > $@ + echo 'ME=`which "$0"`' >> $@ + echo 'DIR=`dirname "$ME"`' >> $@ + echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ + chmod +x $@ + +fat/altosui.jar: $(CLASSFILES) $(JAVA_ICON) fat/classes/Manifest.txt + mkdir -p fat/classes + test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui + mkdir -p fat/classes/images + cp $(JAVA_ICON) fat/classes/images + test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI + cd ./fat/classes && jar cfm ../../$@ Manifest.txt images/* altosui/*.class libaltosJNI/*.class + +fat/classes/Manifest.txt: $(CLASSFILES) Makefile + mkdir -p fat/classes + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: freetts.jar" >> $@ + +install: altosui.jar altosui + install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 + install altosui $(DESTDIR)/usr/bin/altosui + +clean: + rm -f *.class altosui.jar + rm -f AltosUI.app/Contents/Resources/Java/* + rm -rf classes + rm -rf windows linux + +distclean: clean + rm -f $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) + rm -rf darwin fat + +FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) + +LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui +$(LINUX_TGZ): $(LINUX_FILES) + rm -f $@ + mkdir -p linux/AltOS + rm -f linux/AltOS/* + cp $(LINUX_FILES) linux/AltOS + cd linux && tar czf ../$@ AltOS + +DARWIN_RESOURCES=$(FATJAR) $(FREETTSJAR) ../libaltos/libaltos.dylib +DARWIN_EXTRA=$(HEXFILES) +DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) + +$(DARWIN_ZIP): $(DARWIN_FILES) + rm -f $@ + cp -a AltosUI.app darwin/ + mkdir -p darwin/AltosUI.app/Contents/Resources/Java + cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java + mkdir -p darwin/AltOS + cp $(DARWIN_EXTRA) darwin/AltOS + cd darwin && zip -r ../$@ AltosUI.app AltOS + +WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ICON) + +$(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi + rm -f $@ + mkdir -p windows/AltOS + rm -f windows/AltOS/* + cp $(WINDOWS_FILES) windows/AltOS + makensis altos-windows.nsi diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am new file mode 100644 index 00000000..20c8b26d --- /dev/null +++ b/ao-tools/altosui/Makefile.am @@ -0,0 +1,165 @@ +JAVAROOT=classes + +CLASSPATH_ENV=CLASSPATH="classes/altosui/*:../libaltos/libaltosJNI/*:$(FREETTS)/*:/usr/share/java/*" + +altosui_JAVA = \ + AltosChannelMenu.java \ + AltosConfig.java \ + AltosConfigUI.java \ + AltosConvert.java \ + AltosCRCException.java \ + AltosCSV.java \ + AltosCSVUI.java \ + AltosDebug.java \ + AltosDeviceDialog.java \ + AltosDevice.java \ + AltosEepromDownload.java \ + AltosEepromMonitor.java \ + AltosEepromReader.java \ + AltosEepromRecord.java \ + AltosFile.java \ + AltosFlash.java \ + AltosFlashUI.java \ + AltosFlightInfoTableModel.java \ + AltosFlightStatusTableModel.java \ + AltosGPS.java \ + AltosGreatCircle.java \ + AltosHexfile.java \ + Altos.java \ + AltosLine.java \ + AltosLogfileChooser.java \ + AltosLog.java \ + AltosParse.java \ + AltosPreferences.java \ + AltosReader.java \ + AltosRecord.java \ + AltosRomconfig.java \ + AltosRomconfigUI.java \ + AltosSerial.java \ + AltosSerialMonitor.java \ + AltosState.java \ + AltosTelemetry.java \ + AltosTelemetryReader.java \ + AltosUI.java \ + AltosVoice.java + +FREETTS_CLASS= \ + cmudict04.jar \ + cmulex.jar \ + cmu_time_awb.jar \ + cmutimelex.jar \ + cmu_us_kal.jar \ + en_us.jar \ + freetts.jar + +LIBALTOS= \ + libaltos.so \ + libaltos.dylib \ + altos.dll + +JAR=altosui.jar + +FATJAR=altosui-fat.jar + +# Icons +JAVA_ICON=$(top_srcdir)/icon/altus-metrum-16x16.jpg +WINDOWS_ICON=$(top_srcdir)/icon/altus-metrum.ico + +# Firmware +FIRMWARE_TD=$(top_srcdir)/src/teledongle-v0.2.ihx +FIRMWARE_TM=$(top_srcdir)/src/telemetrum-v1.0.ihx +FIRMWARE=$(FIRMWARE_TM) $(FIRMWARE_TD) + +# Distribution targets +LINUX_DIST=Altos-Linux-$(VERSION).tar.bz2 +MACOSX_DIST=Altos-Mac-$(VERSION).zip +WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe + +FAT_FILES=$(FATJAR) $(FREETTS_CLASS) + +LINUX_FILES=$(FAT_FILES) libaltos.so + +MACOSX_FILES=$(FAT_FILES) libaltos.dylib +MACOSX_EXTRA=$(FIRMWARE) + +WINDOWS_FILES=$(FAT_FILES) altos.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) + +all-local: classes/altosui $(JAR) $(FATJAR) + +clean-local: + -rm -rf classes/altosui $(JAR) $(FATJAR) \ + $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) $(FREETTS_CLASS) \ + $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ + altosui altosui-test macosx linux + +fat: $(FATJAR) $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) + +altosuidir=$(datadir)/java + +install-altosuiJAVA: altosui.jar + @$(NORMAL_INSTALL) + test -z "$(altosuidir)" || $(MKDIR_P) "$(DESTDIR)$(altosuidir)" + echo " $(INSTALL_DATA)" "$<" "'$(DESTDIR)$(altosuidir)/altosui.jar'"; \ + $(INSTALL_DATA) "$<" "$(DESTDIR)$(altosuidir)" + +classes/altosui: + mkdir -p classes/altosui + +$(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) + jar cfm $@ Manifest.txt \ + -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ + -C classes altosui \ + -C ../libaltos libaltosJNI + +$(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(LIBALTOS) $(JAVA_ICON) + jar cfm $@ Manifest-fat.txt \ + -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ + -C classes altosui \ + -C ../libaltos libaltosJNI + +Manifest.txt: Makefile + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: $(FREETTS)/freetts.jar" >> $@ + +Manifest-fat.txt: + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: freetts.jar" >> $@ + +altosui: Makefile + echo "#!/bin/sh" > $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="$(libdir)" -jar "$(altosuidir)/altosui.jar"' >> $@ + chmod +x $@ + +altosui-test: Makefile + echo "#!/bin/sh" > $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos" -jar altosui.jar' >> $@ + chmod +x $@ + +$(LIBALTOS): + -rm -f "$@" + $(LN_S) ../libaltos/"$@" . + +$(FREETTS_CLASS): Makefile + -rm -f "$@" + $(LN_S) "$(FREETTS)"/"$@" . + +$(LINUX_DIST): $(LINUX_FILES) + -rm -f $@ + -rm -rf linux + mkdir -p linux/AltOS + cp -a $(LINUX_FILES) linux/AltOS + tar cjf $@ -C linux AltOS + +$(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) + -rm -f $@ + -rm -rf macosx + mkdir macosx + cp -a AltosUI.app macosx/ + mkdir -p macosx/AltOS macosx/AltosUI.app/Contents/Resources/Java + cp -a $(MACOSX_FILES) macosx/AltosUI.app/Contents/Resources/Java + cp -a $(MACOSX_EXTRA) macosx/AltOS + cd macosx && zip -r ../$@ AltosUI.app AltOS + +$(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi + -rm -f $@ + makensis -Oaltos-windows.log "-XOutFile $@" altos-windows.nsi \ No newline at end of file diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi index 5ac708f9..6f38ac0e 100644 --- a/ao-tools/altosui/altos-windows.nsi +++ b/ao-tools/altosui/altos-windows.nsi @@ -2,8 +2,6 @@ Name "Altus Metrum Installer" -OutFile "Altos-Windows.exe" - ; Default install directory InstallDir "$PROGRAMFILES\AltusMetrum" @@ -47,10 +45,18 @@ SectionEnd Section "AltosUI Application" SetOutPath $INSTDIR - File "windows/AltOS/*.jar" - File "windows/AltOS/*.dll" + File "altosui.jar" + File "cmudict04.jar" + File "cmulex.jar" + File "cmu_time_awb.jar" + File "cmutimelex.jar" + File "cmu_us_kal.jar" + File "en_us.jar" + File "freetts.jar" + + File "*.dll" - File "windows/AltOS/*.ico" + File "../../icon/*.ico" CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd @@ -63,8 +69,8 @@ Section "TeleMetrum and TeleDongle Firmware" SetOutPath $INSTDIR - File "windows/AltOS/telemetrum-v1.0.ihx" - File "windows/AltOS/teledongle-v0.2.ihx" + File "../../src/telemetrum-v1.0/telemetrum-v1.0.ihx" + File "../../src/teledongle-v0.2/teledongle-v0.2.ihx" SectionEnd diff --git a/ao-tools/altosui/altosui-fat b/ao-tools/altosui/altosui-fat new file mode 100755 index 00000000..a95b78b8 --- /dev/null +++ b/ao-tools/altosui/altosui-fat @@ -0,0 +1,4 @@ +#!/bin/sh +me=`which "$0"` +dir=`dirname "$me"` +exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui.jar diff --git a/ao-tools/libaltos/.gitignore b/ao-tools/libaltos/.gitignore new file mode 100644 index 00000000..c490e6f8 --- /dev/null +++ b/ao-tools/libaltos/.gitignore @@ -0,0 +1,12 @@ +*.so +*.lo +*.la +*.java +*.class +.libs/ +classlibaltos.stamp +libaltos_wrap.c +libaltosJNI +cjnitest +libaltos.swig +swig_bindings/ diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile deleted file mode 100644 index cb767c85..00000000 --- a/ao-tools/libaltos/Makefile +++ /dev/null @@ -1,126 +0,0 @@ -OS:=$(shell uname) - -# -# Linux -# -ifeq ($(OS),Linux) - -JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include - -OS_LIB_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) - -OS_APP_CFLAGS=$(OS_LIB_CFLAGS) - -OS_LDFLAGS= - -LIBNAME=libaltos.so -EXEEXT= -endif - -# -# Darwin (Mac OS X) -# -ifeq ($(OS),Darwin) - -OS_LIB_CFLAGS=\ - -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ - --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ - -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ - -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ - -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers -OS_APP_CFLAGS=$(OS_LIB_CFLAGS) - -OS_LDFLAGS =\ - -framework IOKit -framework CoreFoundation - -LIBNAME=libaltos.dylib -EXEEXT= - -endif - -# -# Windows -# -ifneq (,$(findstring MINGW,$(OS))) - -CC=gcc - -OS_LIB_CFLAGS = -DWINDOWS -mconsole -DBUILD_DLL -OS_APP_CFLAGS = -DWINDOWS -mconsole - -OS_LDFLAGS = -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lole32 \ - -ladvapi32 -lcomctl32 -mconsole -Wl,--add-stdcall-alias - -LIBNAME=altos.dll - -EXEEXT=.exe - -endif - -.SUFFIXES: .java .class - -CLASSPATH=".:jnitest/*:libaltosJNI:/usr/share/java/*" - -SWIG_DIR=swig_bindings/java -SWIG_FILE=$(SWIG_DIR)/libaltos.swig -SWIG_WRAP=$(SWIG_DIR)/libaltos_wrap.c - -JNI_DIR=libaltosJNI -JNI_FILE=$(JNI_DIR)/libaltosJNI.java -JNI_SRCS=$(JNI_FILE) \ - $(JNI_DIR)/SWIGTYPE_p_altos_file.java \ - $(JNI_DIR)/SWIGTYPE_p_altos_list.java \ - $(JNI_DIR)/altos_device.java \ - $(JNI_DIR)/libaltos.java - -JAVAFILES=\ - $(JNI_SRCS) - -CLASSFILES = $(JAVAFILES:%.java=%.class) - -JAVAFLAGS=-Xlint:unchecked - -CJNITEST=cjnitest$(EXEEXT) - -all: $(LIBNAME) $(CJNITEST) $(CLASSFILES) - -.java.class: - javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java - -CFLAGS=$(OS_LIB_CFLAGS) -O -I. - -LDFLAGS=$(OS_LDFLAGS) - -HEADERS=libaltos.h -SRCS = libaltos.c $(SWIG_WRAP) -OBJS = $(SRCS:%.c=%.o) -LIBS = $(DARWIN_LIBS) - -$(CJNITEST): cjnitest.c $(LIBNAME) - $(CC) -o $@ $(OS_APP_CFLAGS) cjnitest.c $(LIBNAME) $(LIBS) $(LDFLAGS) - -$(LIBNAME): $(OBJS) - $(CC) -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) - -clean: - rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o - rm -rf swig_bindings libaltosJNI - -distclean: clean - -$(JNI_FILE): libaltos.i0 $(HEADERS) - mkdir -p $(SWIG_DIR) - mkdir -p libaltosJNI - sed 's;//%;%;' libaltos.i0 $(HEADERS) > $(SWIG_FILE) - swig -java -package libaltosJNI $(SWIG_FILE) - cp swig_bindings/java/*.java libaltosJNI - -$(SWIG_WRAP): $(JNI_FILE) - -ifeq ($(OS),Linux) -install: $(LIBNAME) - install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) - -endif - -.NOTPARALLEL: diff --git a/ao-tools/libaltos/Makefile-standalone b/ao-tools/libaltos/Makefile-standalone new file mode 100644 index 00000000..4e438050 --- /dev/null +++ b/ao-tools/libaltos/Makefile-standalone @@ -0,0 +1,126 @@ +OS:=$(shell uname) + +# +# Linux +# +ifeq ($(OS),Linux) + +JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include + +OS_LIB_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) + +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) + +OS_LDFLAGS= + +LIBNAME=libaltos.so +EXEEXT= +endif + +# +# Darwin (Mac OS X) +# +ifeq ($(OS),Darwin) + +OS_LIB_CFLAGS=\ + -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ + --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ + -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ + -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ + -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) + +OS_LDFLAGS =\ + -framework IOKit -framework CoreFoundation + +LIBNAME=libaltos.dylib +EXEEXT= + +endif + +# +# Windows +# +ifneq (,$(findstring MINGW,$(OS))) + +CC=gcc + +OS_LIB_CFLAGS = -DWINDOWS -mconsole -DBUILD_DLL +OS_APP_CFLAGS = -DWINDOWS -mconsole + +OS_LDFLAGS = -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lole32 \ + -ladvapi32 -lcomctl32 -mconsole -Wl,--add-stdcall-alias + +LIBNAME=altos.dll + +EXEEXT=.exe + +endif + +.SUFFIXES: .java .class + +CLASSPATH=".:jnitest/*:libaltosJNI:/usr/share/java/*" + +SWIG_DIR=swig_bindings/java +SWIG_FILE=$(SWIG_DIR)/libaltos.swig +SWIG_WRAP=$(SWIG_DIR)/libaltos_wrap.c + +JNI_DIR=libaltosJNI +JNI_FILE=$(JNI_DIR)/libaltosJNI.java +JNI_SRCS=$(JNI_FILE) \ + $(JNI_DIR)/SWIGTYPE_p_altos_file.java \ + $(JNI_DIR)/SWIGTYPE_p_altos_list.java \ + $(JNI_DIR)/altos_device.java \ + $(JNI_DIR)/libaltos.java + +JAVAFILES=\ + $(JNI_SRCS) + +CLASSFILES = $(JAVAFILES:%.java=%.class) + +JAVAFLAGS=-Xlint:unchecked + +CJNITEST=cjnitest$(EXEEXT) + +all: $(LIBNAME) $(CJNITEST) $(CLASSFILES) + +.java.class: + javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java + +CFLAGS=$(OS_LIB_CFLAGS) -O -I. + +LDFLAGS=$(OS_LDFLAGS) + +HEADERS=libaltos.h +SRCS = libaltos.c $(SWIG_WRAP) +OBJS = $(SRCS:%.c=%.o) +LIBS = $(DARWIN_LIBS) + +$(CJNITEST): cjnitest.c $(LIBNAME) + $(CC) -o $@ $(OS_APP_CFLAGS) cjnitest.c $(LIBNAME) $(LIBS) $(LDFLAGS) + +$(LIBNAME): $(OBJS) + $(CC) -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) + +clean: + rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o + rm -rf swig_bindings libaltosJNI + +distclean: clean + +$(JNI_FILE): libaltos.i0 $(HEADERS) + mkdir -p $(SWIG_DIR) + mkdir -p libaltosJNI + sed 's;//%;%;' libaltos.i0 $(HEADERS) > $(SWIG_FILE) + swig -java -package libaltosJNI $(SWIG_FILE) + cp swig_bindings/java/*.java libaltosJNI + +$(SWIG_WRAP): $(JNI_FILE) + +ifeq ($(OS),Linux) +install: $(LIBNAME) + install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) + +endif + +.NOTPARALLEL: diff --git a/ao-tools/libaltos/Makefile.am b/ao-tools/libaltos/Makefile.am new file mode 100644 index 00000000..2f1d6fca --- /dev/null +++ b/ao-tools/libaltos/Makefile.am @@ -0,0 +1,27 @@ +JAVAC=javac +AM_CFLAGS="-I$(JVM_INCLUDE)" + +lib_LTLIBRARIES=libaltos.la + +libaltos_la_SOURCES=\ + libaltos.c + +HFILES=libaltos.h + +SWIG_FILE=libaltos.swig + +CLASSDIR=libaltosJNI + +$(SWIG_FILE): libaltos.i0 $(HFILES) + sed 's;//%;%;' libaltos.i0 $(HFILES) > $(SWIG_FILE) + +all-local: classlibaltos.stamp + +classlibaltos.stamp: $(SWIG_FILE) + swig -java -package libaltosJNI $(SWIG_FILE) + mkdir -p libaltosJNI + $(JAVAC) -d . $(AM_JAVACFLAGS) $(JAVACFLAGS) *.java && \ + touch classlibaltos.stamp + +clean-local: + -rm -rf libaltosJNI *.class *.java classlibaltos.stamp $(SWIG_FILE) \ No newline at end of file diff --git a/configure.ac b/configure.ac index fafc6b34..19ae0ac8 100644 --- a/configure.ac +++ b/configure.ac @@ -17,19 +17,50 @@ dnl 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. dnl dnl Process this file with autoconf to create configure. -AC_INIT(COPYING) - -AM_INIT_AUTOMAKE(altos, 0.1) +AC_PREREQ(2.57) +AC_INIT([altos], 0.7.1) +AC_CONFIG_SRCDIR([src/ao.h]) +AM_INIT_AUTOMAKE([foreign dist-bzip2]) AM_MAINTAINER_MODE +VERSION_DASH=`echo $VERSION | sed 's/\./-/g'` +AC_SUBST(VERSION_DASH) + dnl ========================================================================== AM_CONFIG_HEADER(config.h) +AC_ARG_WITH(freetts, AS_HELP_STRING([--with-freetts=PATH], + [Set freetts class path (default /usr/share/java)]), + [FREETTS=$withval], [FREETTS=/usr/share/java]) + +AC_SUBST(FREETTS) + +AC_ARG_WITH(jvm, AS_HELP_STRING([--with-jvm-include=PATH], + [Set jvm include path for jni builds (default searches in /usr/lib/jvm)]), + [JVM_INCLUDE=$withval], [JVM_INCLUDE=auto]) + +if test "x$JVM_INCLUDE" = "xauto"; then + AC_MSG_CHECKING([JVM include files]) + for jvm in default-java java-6-openjdk java-6-sun; do + if test "x$JVM_INCLUDE" = "xauto"; then + INCLUDE="/usr/lib/jvm/$jvm/include" + if test -f "$INCLUDE"/jni.h; then + JVM_INCLUDE="$INCLUDE" + fi + fi + done + if test "x$JVM_INCLUDE" = "xauto"; then + AC_MSG_ERROR([no JVM include files found]) + fi + AC_MSG_RESULT([$JVM_INCLUDE]) +fi + AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_RANLIB +AC_PROG_LIBTOOL PKG_PROG_PKG_CONFIG CFLAGS="-g" @@ -92,5 +123,7 @@ ao-tools/ao-list/Makefile ao-tools/ao-load/Makefile ao-tools/ao-postflight/Makefile ao-tools/ao-view/Makefile +ao-tools/libaltos/Makefile +ao-tools/altosui/Makefile ao-utils/Makefile ]) -- cgit v1.2.3 From aed59e1c057c13e28fd368dc2592aa4628211097 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 17:59:11 -0700 Subject: Add version numbers to released files. Set version to 0.7.1 Instead of using git revision counts for version numbers, use explicit versions numbers configured in the configure.ac file. Expose published files with version numbers. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 8 ++++---- ao-tools/altosui/altos-windows.nsi | 4 ++-- configure.ac | 2 +- src/Makefile | 2 ++ src/Makefile.proto | 6 ++---- src/Version.in | 1 + src/teledongle-v0.1/.gitignore | 2 +- src/teledongle-v0.1/Makefile.defs | 2 +- src/teledongle-v0.2/.gitignore | 2 +- src/teledongle-v0.2/Makefile.defs | 2 +- src/telemetrum-v0.1-sirf/.gitignore | 2 +- src/telemetrum-v0.1-sirf/Makefile.defs | 2 +- src/telemetrum-v0.1-sky/.gitignore | 2 +- src/telemetrum-v0.1-sky/Makefile.defs | 2 +- src/telemetrum-v1.0/.gitignore | 2 +- src/telemetrum-v1.0/Makefile.defs | 2 +- src/tidongle/.gitignore | 2 +- src/tidongle/Makefile.defs | 2 +- 18 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 src/Version.in (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 20c8b26d..ed7e2f76 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -66,8 +66,8 @@ JAVA_ICON=$(top_srcdir)/icon/altus-metrum-16x16.jpg WINDOWS_ICON=$(top_srcdir)/icon/altus-metrum.ico # Firmware -FIRMWARE_TD=$(top_srcdir)/src/teledongle-v0.2.ihx -FIRMWARE_TM=$(top_srcdir)/src/telemetrum-v1.0.ihx +FIRMWARE_TD=$(top_srcdir)/src/teledongle-v0.2-$(VERSION).ihx +FIRMWARE_TM=$(top_srcdir)/src/telemetrum-v1.0-$(VERSION).ihx FIRMWARE=$(FIRMWARE_TM) $(FIRMWARE_TD) # Distribution targets @@ -77,7 +77,7 @@ WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe FAT_FILES=$(FATJAR) $(FREETTS_CLASS) -LINUX_FILES=$(FAT_FILES) libaltos.so +LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) MACOSX_FILES=$(FAT_FILES) libaltos.dylib MACOSX_EXTRA=$(FIRMWARE) @@ -162,4 +162,4 @@ $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) $(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi -rm -f $@ - makensis -Oaltos-windows.log "-XOutFile $@" altos-windows.nsi \ No newline at end of file + makensis -Oaltos-windows.log "-XOutFile $@" "-DVERSION=$(VERSION)" altos-windows.nsi \ No newline at end of file diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi index 6f38ac0e..c8539a5c 100644 --- a/ao-tools/altosui/altos-windows.nsi +++ b/ao-tools/altosui/altos-windows.nsi @@ -69,8 +69,8 @@ Section "TeleMetrum and TeleDongle Firmware" SetOutPath $INSTDIR - File "../../src/telemetrum-v1.0/telemetrum-v1.0.ihx" - File "../../src/teledongle-v0.2/teledongle-v0.2.ihx" + File "../../src/telemetrum-v1.0/telemetrum-v1.0-${VERSION}.ihx" + File "../../src/teledongle-v0.2/teledongle-v0.2-${VERSION}.ihx" SectionEnd diff --git a/configure.ac b/configure.ac index 19ae0ac8..d376af3f 100644 --- a/configure.ac +++ b/configure.ac @@ -59,7 +59,6 @@ fi AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S -AC_PROG_RANLIB AC_PROG_LIBTOOL PKG_PROG_PKG_CONFIG @@ -126,4 +125,5 @@ ao-tools/ao-view/Makefile ao-tools/libaltos/Makefile ao-tools/altosui/Makefile ao-utils/Makefile +src/Version ]) diff --git a/src/Makefile b/src/Makefile index 24f562e1..95d24425 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,6 +4,8 @@ # CC=sdcc +include Version + SUBDIRS=telemetrum-v1.0 teledongle-v0.2 telemetrum-v0.1-sky telemetrum-v0.1-sirf teledongle-v0.1 tidongle test all: all-recursive diff --git a/src/Makefile.proto b/src/Makefile.proto index 59a3b8a6..b23eb257 100644 --- a/src/Makefile.proto +++ b/src/Makefile.proto @@ -10,7 +10,7 @@ vpath ao-make-product.5c .. CC=sdcc ifndef VERSION -VERSION=$(shell git describe) +include ../Version endif CFLAGS=--model-small --debug --opt-code-speed @@ -214,11 +214,9 @@ all: ../$(PROG) ../altitude.h: make-altitude nickle $< > $@ -ao_product.h: ao-make-product.5c always +ao_product.h: ao-make-product.5c ../Version $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ -always: - ao_product.rel: ao_product.c ao_product.h $(call quiet,CC) -c $(CFLAGS) -D PRODUCT_DEFS='\"ao_product.h\"' -o$@ $< diff --git a/src/Version.in b/src/Version.in new file mode 100644 index 00000000..aff9490b --- /dev/null +++ b/src/Version.in @@ -0,0 +1 @@ +VERSION=@VERSION@ diff --git a/src/teledongle-v0.1/.gitignore b/src/teledongle-v0.1/.gitignore index 96c802bd..9826814b 100644 --- a/src/teledongle-v0.1/.gitignore +++ b/src/teledongle-v0.1/.gitignore @@ -1,2 +1,2 @@ -teledongle-v0.1 +teledongle-v0.1* ao_product.h diff --git a/src/teledongle-v0.1/Makefile.defs b/src/teledongle-v0.1/Makefile.defs index be7741d8..ceb80b7a 100644 --- a/src/teledongle-v0.1/Makefile.defs +++ b/src/teledongle-v0.1/Makefile.defs @@ -1,4 +1,4 @@ -PROG = teledongle-v0.1.ihx +PROG = teledongle-v0.1-$(VERSION).ihx SRC = \ $(TD_SRC) \ diff --git a/src/teledongle-v0.2/.gitignore b/src/teledongle-v0.2/.gitignore index af79a766..f6ea8c6c 100644 --- a/src/teledongle-v0.2/.gitignore +++ b/src/teledongle-v0.2/.gitignore @@ -1,2 +1,2 @@ -teledongle-v0.2 +teledongle-v0.2* ao_product.h diff --git a/src/teledongle-v0.2/Makefile.defs b/src/teledongle-v0.2/Makefile.defs index cbec7805..ea9713b6 100644 --- a/src/teledongle-v0.2/Makefile.defs +++ b/src/teledongle-v0.2/Makefile.defs @@ -1,4 +1,4 @@ -PROG = teledongle-v0.2.ihx +PROG = teledongle-v0.2-$(VERSION).ihx SRC = \ $(TD_SRC) \ diff --git a/src/telemetrum-v0.1-sirf/.gitignore b/src/telemetrum-v0.1-sirf/.gitignore index 6d584f36..7698f5aa 100644 --- a/src/telemetrum-v0.1-sirf/.gitignore +++ b/src/telemetrum-v0.1-sirf/.gitignore @@ -1,2 +1,2 @@ -telemetrum-v0.1-sirf +telemetrum-v0.1-sirf* ao_product.h diff --git a/src/telemetrum-v0.1-sirf/Makefile.defs b/src/telemetrum-v0.1-sirf/Makefile.defs index 2ce6e6ed..a7310fbc 100644 --- a/src/telemetrum-v0.1-sirf/Makefile.defs +++ b/src/telemetrum-v0.1-sirf/Makefile.defs @@ -1,4 +1,4 @@ -PROG = telemetrum-v0.1-sirf.ihx +PROG = telemetrum-v0.1-sirf-$(VERSION).ihx SRC = \ $(TM_BASE_SRC) \ diff --git a/src/telemetrum-v0.1-sky/.gitignore b/src/telemetrum-v0.1-sky/.gitignore index 5a9fafb5..d25d7ad9 100644 --- a/src/telemetrum-v0.1-sky/.gitignore +++ b/src/telemetrum-v0.1-sky/.gitignore @@ -1,2 +1,2 @@ -telemetrum-v0.1-sky +telemetrum-v0.1-sky* ao_product.h diff --git a/src/telemetrum-v0.1-sky/Makefile.defs b/src/telemetrum-v0.1-sky/Makefile.defs index 098ac547..000287ba 100644 --- a/src/telemetrum-v0.1-sky/Makefile.defs +++ b/src/telemetrum-v0.1-sky/Makefile.defs @@ -1,4 +1,4 @@ -PROG = telemetrum-v0.1-sky.ihx +PROG = telemetrum-v0.1-sky-$(VERSION).ihx SRC = \ $(TM_BASE_SRC) \ diff --git a/src/telemetrum-v1.0/.gitignore b/src/telemetrum-v1.0/.gitignore index 76228093..c2212151 100644 --- a/src/telemetrum-v1.0/.gitignore +++ b/src/telemetrum-v1.0/.gitignore @@ -1,2 +1,2 @@ -telemetrum-v0.2 +telemetrum-* ao_product.h diff --git a/src/telemetrum-v1.0/Makefile.defs b/src/telemetrum-v1.0/Makefile.defs index 624ce6e8..010578df 100644 --- a/src/telemetrum-v1.0/Makefile.defs +++ b/src/telemetrum-v1.0/Makefile.defs @@ -1,4 +1,4 @@ -PROG = telemetrum-v1.0.ihx +PROG = telemetrum-v1.0-$(VERSION).ihx SRC = \ $(TM_BASE_SRC) \ diff --git a/src/tidongle/.gitignore b/src/tidongle/.gitignore index 3323f640..3888a0f9 100644 --- a/src/tidongle/.gitignore +++ b/src/tidongle/.gitignore @@ -1,2 +1,2 @@ -tidongle +tidongle* ao_product.h diff --git a/src/tidongle/Makefile.defs b/src/tidongle/Makefile.defs index fdd51732..0e13cb20 100644 --- a/src/tidongle/Makefile.defs +++ b/src/tidongle/Makefile.defs @@ -1,4 +1,4 @@ -PROG = tidongle.ihx +PROG = tidongle-$(VERSION).ihx SRC = \ $(TI_SRC) -- cgit v1.2.3 From 044fd27449c70474f51b99dec25fd23d3c03a559 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 18:20:45 -0700 Subject: altosui: Fix windows installer to ship correct files Was shipping altosui.jar instead of altosui-fat.jar Signed-off-by: Keith Packard --- ao-tools/altosui/.gitignore | 15 ++++++++++----- ao-tools/altosui/Makefile.am | 7 ++++--- ao-tools/altosui/altos-windows.nsi | 6 +++--- ao-tools/libaltos/Makefile.am | 1 + 4 files changed, 18 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/.gitignore b/ao-tools/altosui/.gitignore index 63672058..89be1d53 100644 --- a/ao-tools/altosui/.gitignore +++ b/ao-tools/altosui/.gitignore @@ -1,14 +1,19 @@ windows/ linux/ -darwin/ +macosx/ fat/ Manifest.txt +Manifest-fat.txt libaltosJNI classes altosui -Altos-Linux.tgz -Altos-Mac.zip -Altos-Windows.exe +altosui-test +classaltosui.stamp +Altos-Linux-*.tar.bz2 +Altos-Mac-*.zip +Altos-Windows-*.exe +*.dll +*.dylib +*.so *.jar *.class -altosui diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index ed7e2f76..13bceae2 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -1,4 +1,5 @@ JAVAROOT=classes +AM_JAVACFLAGS=-encoding UTF-8 CLASSPATH_ENV=CLASSPATH="classes/altosui/*:../libaltos/libaltosJNI/*:$(FREETTS)/*:/usr/share/java/*" @@ -77,14 +78,14 @@ WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe FAT_FILES=$(FATJAR) $(FREETTS_CLASS) -LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) +LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) altosui-fat MACOSX_FILES=$(FAT_FILES) libaltos.dylib MACOSX_EXTRA=$(FIRMWARE) WINDOWS_FILES=$(FAT_FILES) altos.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) -all-local: classes/altosui $(JAR) $(FATJAR) +all-local: classes/altosui $(JAR) $(FATJAR) altosui altosui-test clean-local: -rm -rf classes/altosui $(JAR) $(FATJAR) \ @@ -139,7 +140,7 @@ $(LIBALTOS): -rm -f "$@" $(LN_S) ../libaltos/"$@" . -$(FREETTS_CLASS): Makefile +$(FREETTS_CLASS): -rm -f "$@" $(LN_S) "$(FREETTS)"/"$@" . diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi index c8539a5c..6ebec214 100644 --- a/ao-tools/altosui/altos-windows.nsi +++ b/ao-tools/altosui/altos-windows.nsi @@ -45,7 +45,7 @@ SectionEnd Section "AltosUI Application" SetOutPath $INSTDIR - File "altosui.jar" + File "altosui-fat.jar" File "cmudict04.jar" File "cmulex.jar" File "cmu_time_awb.jar" @@ -58,11 +58,11 @@ Section "AltosUI Application" File "../../icon/*.ico" - CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" + CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui-fat.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd Section "AltosUI Desktop Shortcut" - CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" + CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui-fat.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd Section "TeleMetrum and TeleDongle Firmware" diff --git a/ao-tools/libaltos/Makefile.am b/ao-tools/libaltos/Makefile.am index 2f1d6fca..4d29d80e 100644 --- a/ao-tools/libaltos/Makefile.am +++ b/ao-tools/libaltos/Makefile.am @@ -1,5 +1,6 @@ JAVAC=javac AM_CFLAGS="-I$(JVM_INCLUDE)" +AM_JAVACFLAGS=-encoding UTF-8 lib_LTLIBRARIES=libaltos.la -- cgit v1.2.3 From 828e9e4c68e3ac90b6ba2e9fd5f131a9975f7e4a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 18:39:58 -0700 Subject: altosui: Fix up Mac OSX .zip file Must contain 'altosui.jar' instead of altosui-fat.jar. Also, was using 'cp -a' instead of 'cp -p' which made files represented by symlinks not end up in the archive. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 13bceae2..65a3cf9a 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -157,8 +157,9 @@ $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) mkdir macosx cp -a AltosUI.app macosx/ mkdir -p macosx/AltOS macosx/AltosUI.app/Contents/Resources/Java - cp -a $(MACOSX_FILES) macosx/AltosUI.app/Contents/Resources/Java - cp -a $(MACOSX_EXTRA) macosx/AltOS + cp -p $(FATJAR) macosx/AltosUI.app/Contents/Resources/Java/altosui.jar + cp -p $(FREETTS_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java + cp -p $(MACOSX_EXTRA) macosx/AltOS cd macosx && zip -r ../$@ AltosUI.app AltOS $(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi -- cgit v1.2.3 From c3a17c71a45207dd715d537704f161de9219f0d7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 18:49:22 -0700 Subject: altosui: Fix linux fat distribution Again, use 'cp -p' instead of 'cp -a' to get files into the archive instead of links. Also, make the shell script 'altosui' instead of 'altosui-fat'. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 9 ++++++--- ao-tools/altosui/altosui-fat | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 65a3cf9a..bc8dbc0d 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -78,7 +78,8 @@ WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe FAT_FILES=$(FATJAR) $(FREETTS_CLASS) -LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) altosui-fat +LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) +LINUX_EXTRA=altosui-fat MACOSX_FILES=$(FAT_FILES) libaltos.dylib MACOSX_EXTRA=$(FIRMWARE) @@ -144,11 +145,13 @@ $(FREETTS_CLASS): -rm -f "$@" $(LN_S) "$(FREETTS)"/"$@" . -$(LINUX_DIST): $(LINUX_FILES) +$(LINUX_DIST): $(LINUX_FILES) $(LINUX_EXTRA) -rm -f $@ -rm -rf linux mkdir -p linux/AltOS - cp -a $(LINUX_FILES) linux/AltOS + cp -p $(LINUX_FILES) linux/AltOS + cp -p altosui-fat linux/AltOS/altosui + chmod +x linux/AltOS/altosui tar cjf $@ -C linux AltOS $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) diff --git a/ao-tools/altosui/altosui-fat b/ao-tools/altosui/altosui-fat index a95b78b8..9e5a8f15 100755 --- a/ao-tools/altosui/altosui-fat +++ b/ao-tools/altosui/altosui-fat @@ -1,4 +1,4 @@ #!/bin/sh me=`which "$0"` dir=`dirname "$me"` -exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui.jar +exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui-fat.jar -- cgit v1.2.3 From eb0e7a59f0806734a4c959a3ce7c57f71cbe3986 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 00:57:38 -0700 Subject: altosui: Return AO_LOG_INVALID instead of exception for eeprom files When an eeprom file contains an invalid line, just return AO_LOG_INVALID instead of throwing an exception. This allows us to replay and parse files with extraneous serial communication. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromRecord.java | 99 ++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 45 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromRecord.java b/ao-tools/altosui/AltosEepromRecord.java index 4d0817ab..95cbe015 100644 --- a/ao-tools/altosui/AltosEepromRecord.java +++ b/ao-tools/altosui/AltosEepromRecord.java @@ -47,7 +47,7 @@ public class AltosEepromRecord { public String data; public boolean tick_valid; - public AltosEepromRecord (String line) throws ParseException { + public AltosEepromRecord (String line) { tick_valid = false; tick = 0; a = 0; @@ -55,52 +55,61 @@ public class AltosEepromRecord { data = null; if (line == null) { cmd = Altos.AO_LOG_INVALID; + data = ""; } else { - String[] tokens = line.split("\\s+"); + try { + String[] tokens = line.split("\\s+"); - if (tokens[0].length() == 1) { - if (tokens.length != 4) - throw new ParseException(line, 0); - 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 = Altos.AO_LOG_CONFIG_VERSION; - data = tokens[2]; - } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { - cmd = Altos.AO_LOG_MAIN_DEPLOY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { - cmd = Altos.AO_LOG_APOGEE_DELAY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { - cmd = Altos.AO_LOG_RADIO_CHANNEL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Callsign:")) { - cmd = Altos.AO_LOG_CALLSIGN; - data = tokens[1].replaceAll("\"",""); - } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { - cmd = Altos.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 = Altos.AO_LOG_RADIO_CAL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("manufacturer")) { - cmd = Altos.AO_LOG_MANUFACTURER; - data = tokens[1]; - } else if (tokens[0].equals("product")) { - cmd = Altos.AO_LOG_PRODUCT; - data = tokens[1]; - } else if (tokens[0].equals("serial-number")) { - cmd = Altos.AO_LOG_SERIAL_NUMBER; - a = Integer.parseInt(tokens[1]); - } else if (tokens[0].equals("software-version")) { - cmd = Altos.AO_LOG_SOFTWARE_VERSION; - data = tokens[1]; - } else { + if (tokens[0].length() == 1) { + if (tokens.length != 4) { + cmd = Altos.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 = Altos.AO_LOG_CONFIG_VERSION; + data = tokens[2]; + } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { + cmd = Altos.AO_LOG_MAIN_DEPLOY; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { + cmd = Altos.AO_LOG_APOGEE_DELAY; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { + cmd = Altos.AO_LOG_RADIO_CHANNEL; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Callsign:")) { + cmd = Altos.AO_LOG_CALLSIGN; + data = tokens[1].replaceAll("\"",""); + } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { + cmd = Altos.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 = Altos.AO_LOG_RADIO_CAL; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("manufacturer")) { + cmd = Altos.AO_LOG_MANUFACTURER; + data = tokens[1]; + } else if (tokens[0].equals("product")) { + cmd = Altos.AO_LOG_PRODUCT; + data = tokens[1]; + } else if (tokens[0].equals("serial-number")) { + cmd = Altos.AO_LOG_SERIAL_NUMBER; + a = Integer.parseInt(tokens[1]); + } else if (tokens[0].equals("software-version")) { + cmd = Altos.AO_LOG_SOFTWARE_VERSION; + data = tokens[1]; + } else { + cmd = Altos.AO_LOG_INVALID; + data = line; + } + } catch (NumberFormatException ne) { cmd = Altos.AO_LOG_INVALID; data = line; } -- cgit v1.2.3 From b2aa689bf3d61e4a3ebe7c828162d1be20aad0f6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 00:59:54 -0700 Subject: altosui: Remove debugging printf from AltosEepromReader These were in place while validing the GPS data reconstruction code that handles eeprom files missing the first GPS date line due to the record overwriting bug in old firmware versions. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 0705d44e..e2a780ac 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -177,12 +177,6 @@ public class AltosEepromReader extends AltosReader { state.gps.date_valid = (flags & Altos.AO_GPS_DATE_VALID) != 0; state.gps.nsat = (flags & Altos.AO_GPS_NUM_SAT_MASK) >> Altos.AO_GPS_NUM_SAT_SHIFT; - System.out.printf("GPS %2d:%02d:%02d%s%s%s %d\n", - state.gps.hour, state.gps.minute, state.gps.second, - state.gps.connected ? " connected" : "", - state.gps.locked ? " locked" : "", - state.gps.date_valid ? " date_valid" : "", - state.gps.nsat); break; case Altos.AO_LOG_GPS_LAT: int lat32 = record.a | (record.b << 16); @@ -306,10 +300,6 @@ public class AltosEepromReader extends AltosReader { int new_hours = (new_minutes / 60); int new_hour = (new_hours % 24); - System.out.printf("Synthesizing time good %2d:%02d:%02d bad %2d:%02d:%02d\n", - hour, minute, second, - new_hour, new_minute, new_second); - bad.a = new_hour + (new_minute << 8); bad.b = new_second + (flags << 8); } @@ -365,13 +355,9 @@ public class AltosEepromReader extends AltosReader { if (record.cmd == Altos.AO_LOG_GPS_TIME) { last_gps_time = record; if (missing_time) { - System.out.printf("Going back to clean up broken GPS time records\n"); Iterator iterator = records.iterator(); while (iterator.hasNext()) { AltosOrderedRecord old = iterator.next(); - if (old.cmd == Altos.AO_LOG_GPS_TIME) { - System.out.printf("Old time record %d, %d\n", old.a, old.b); - } if (old.cmd == Altos.AO_LOG_GPS_TIME && old.a == -1 && old.b == -1) { @@ -389,10 +375,9 @@ public class AltosEepromReader extends AltosReader { -1, -1, index-1); if (last_gps_time != null) update_time(last_gps_time, add_gps_time); - else { - System.out.printf("early GPS missing time\n"); + else missing_time = true; - } + records.add(add_gps_time); record.index = index++; } -- cgit v1.2.3 From 2d58f319a7c1a6a8ccc6a539722009996ba886ab Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:01:10 -0700 Subject: altosui: Eeprom files contain only one date; save it. While reading eeprom files, the GPS record is reconstructed each time the system sees the first GPS log item (the time field), but as the date isn't repeated, we need to copy it from the old GPS data record. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index e2a780ac..ac54ff44 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -116,7 +116,7 @@ public class AltosEepromReader extends AltosReader { if (last_reported) return null; last_reported = true; - return state; + return new AltosRecord(state); } record = record_iterator.next(); @@ -167,7 +167,15 @@ public class AltosEepromReader extends AltosReader { break; case Altos.AO_LOG_GPS_TIME: gps_tick = state.tick; + AltosGPS old = state.gps; state.gps = new AltosGPS(); + + /* 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); @@ -197,7 +205,7 @@ public class AltosEepromReader extends AltosReader { } break; case Altos.AO_LOG_GPS_DATE: - state.gps.year = record.a & 0xff; + state.gps.year = (record.a & 0xff) + 2000; state.gps.month = record.a >> 8; state.gps.day = record.b & 0xff; break; @@ -334,6 +342,8 @@ public class AltosEepromReader extends AltosReader { AltosOrderedRecord record = new AltosOrderedRecord(line, index++, tick); if (record == null) break; + if (record.cmd == Altos.AO_LOG_INVALID) + continue; tick = record.tick; if (!saw_boost && record.cmd == Altos.AO_LOG_STATE && record.a >= Altos.ao_flight_boost) -- cgit v1.2.3 From 3d99584fcfe43b22e8581874e0ac77ce3d635d48 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:03:18 -0700 Subject: altosui: Add elevation and range data to main display Reported by voice, it's useful to see these on the display as well. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 37625e8e..6a1814ff 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -231,11 +231,19 @@ public class AltosUI extends JFrame { if (state.npad > 0) { if (state.from_pad != null) { - info_add_row(1, "Distance from pad", "%6.0f m", state.from_pad.distance); - info_add_row(1, "Direction from pad", "%6.0f°", state.from_pad.bearing); + info_add_row(1, "Distance from pad", "%6d m", + (int) (state.from_pad.distance + 0.5)); + info_add_row(1, "Direction from pad", "%6d°", + (int) (state.from_pad.bearing + 0.5)); + info_add_row(1, "Elevation from pad", "%6d°", + (int) (state.elevation + 0.5)); + info_add_row(1, "Range from pad", "%6d m", + (int) (state.range + 0.5)); } else { info_add_row(1, "Distance from pad", "unknown"); info_add_row(1, "Direction from pad", "unknown"); + info_add_row(1, "Elevation from pad", "unknown"); + info_add_row(1, "Range from pad", "unknown"); } info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); -- cgit v1.2.3 From 6205547ec7191aab0259a8449520e966a96129e6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:08:50 -0700 Subject: altosui: When replay thread is interrupted, don't make final report Normally, the replay process makes one final report after the file has been parsed. However, if the reading process is interrupted to display something else, this report is just annoying, so don't make it. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 6a1814ff..49153766 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -384,11 +384,12 @@ public class AltosUI extends JFrame { AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } - void close() { } + void close(boolean interrupted) { } void update(AltosState state) throws InterruptedException { } public void run() { + boolean interrupted = false; String line; AltosState state = null; AltosState old_state = null; @@ -418,14 +419,18 @@ public class AltosUI extends JFrame { } } } catch (InterruptedException ee) { + interrupted = true; } catch (IOException ie) { JOptionPane.showMessageDialog(AltosUI.this, String.format("Error reading from \"%s\"", name), "Telemetry Read Error", JOptionPane.ERROR_MESSAGE); } finally { - close(); + close(interrupted); idle_thread.interrupt(); + try { + idle_thread.join(); + } catch (InterruptedException ie) {} } } @@ -446,7 +451,7 @@ public class AltosUI extends JFrame { return new AltosTelemetry(l.line); } - void close() { + void close(boolean interrupted) { serial.close(); serial.remove_monitor(telem); } @@ -530,8 +535,9 @@ public class AltosUI extends JFrame { return null; } - public void close () { - report(); + public void close (boolean interrupted) { + if (!interrupted) + report(); } public ReplayThread(AltosReader in_reader, String in_name) { -- cgit v1.2.3 From 410ba89eef9c9817eef81b702966cb88820ff7c4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:13:01 -0700 Subject: altosui: Start idle thread after the rocket leaves the pad This makes the first altitude report time consistently 10 seconds after launch, instead of some random time depending on when the rocket launched relative to the time the device connection was made. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 49153766..fbce5e14 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -277,6 +277,7 @@ public class AltosUI extends JFrame { class IdleThread extends Thread { + boolean started; private AltosState state; int reported_landing; @@ -346,6 +347,10 @@ public class AltosUI extends JFrame { public void notice(AltosState new_state) { AltosState old_state = state; state = new_state; + if (!started && state.state > Altos.ao_flight_pad) { + started = true; + start(); + } if (old_state != null && old_state.state != state.state) report(false); } @@ -398,7 +403,6 @@ public class AltosUI extends JFrame { info_reset(); info_finish(); - idle_thread.start(); try { for (;;) { try { -- cgit v1.2.3 From 4dec5c36702d76dc95beada7c1d3222a638a2cbb Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:19:11 -0700 Subject: altosui: Add AltosVoice.drain() to wait for queued speech to finish drain() blocks until all pending phrases have been processed, allowing the UI code to avoid pending data that will end up stale by the time it is emitted. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosVoice.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java index ebe9d5a8..ac13ee14 100644 --- a/ao-tools/altosui/AltosVoice.java +++ b/ao-tools/altosui/AltosVoice.java @@ -27,6 +27,7 @@ public class AltosVoice implements Runnable { Voice voice; LinkedBlockingQueue phrases; Thread thread; + boolean busy; final static String voice_name = "kevin16"; @@ -35,15 +36,30 @@ public class AltosVoice implements Runnable { for (;;) { String s = phrases.take(); voice.speak(s); + synchronized(this) { + if (phrases.isEmpty()) { + busy = false; + notifyAll(); + } + } } } catch (InterruptedException e) { } } + public synchronized void drain() throws InterruptedException { + while (busy) + wait(); + } + public void speak_always(String s) { try { - if (voice != null) - phrases.put(s); + if (voice != null) { + synchronized(this) { + busy = true; + phrases.put(s); + } + } } catch (InterruptedException e) { } } @@ -58,6 +74,7 @@ public class AltosVoice implements Runnable { } public AltosVoice () { + busy = false; voice_manager = VoiceManager.getInstance(); voice = voice_manager.getVoice(voice_name); if (voice != null) { -- cgit v1.2.3 From 9941b05a1d03dafd6cd899b5fe999ed769efb1d6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:21:14 -0700 Subject: altosui: Prevent voice altitude data from queueing up When flight status changes rapidly, the queue of voice data can get quite long. This change does two things -- first, it remembers when the altitude reporting happens due to flight events and delays the periodic reporting until a suitable time after that, second it ensures that the voice data has all been delivered before generating a new altitude report. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 58 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index fbce5e14..3aaeb888 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -280,6 +280,8 @@ public class AltosUI extends JFrame { boolean started; private AltosState state; int reported_landing; + int report_interval; + long report_time; public synchronized void report(boolean last) { if (state == null) @@ -331,51 +333,88 @@ public class AltosUI extends JFrame { } } + long now () { + return System.currentTimeMillis(); + } + + void set_report_time() { + report_time = now() + report_interval; + } + public void run () { reported_landing = 0; state = null; + report_interval = 10000; try { for (;;) { - Thread.sleep(20000); + set_report_time(); + for (;;) { + voice.drain(); + synchronized (this) { + long sleep_time = report_time - now(); + if (sleep_time <= 0) + break; + wait(sleep_time); + } + } report(false); } } catch (InterruptedException ie) { + try { + voice.drain(); + } catch (InterruptedException iie) { } } } - public void notice(AltosState new_state) { + public synchronized void notice(AltosState new_state, boolean spoken) { AltosState old_state = state; state = new_state; if (!started && state.state > Altos.ao_flight_pad) { started = true; start(); } - if (old_state != null && old_state.state != state.state) - report(false); + + if (state.state < Altos.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(); } } - private void tell(AltosState state, AltosState old_state) { + private boolean tell(AltosState state, AltosState old_state) { + boolean ret = false; if (old_state == null || old_state.state != state.state) { voice.speak(state.data.state()); if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && state.state > Altos.ao_flight_boost) { voice.speak("max speed: %d meters per second.", (int) (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: %d meters.", (int) (state.max_height + 0.5)); + ret = true; } } if (old_state == null || old_state.gps_ready != state.gps_ready) { - if (state.gps_ready) + if (state.gps_ready) { voice.speak("GPS ready"); - else if (old_state != null) + ret = true; + } + else if (old_state != null) { voice.speak("GPS lost"); + ret = true; + } } old_state = state; + return ret; } class DisplayThread extends Thread { @@ -398,6 +437,7 @@ public class AltosUI extends JFrame { String line; AltosState state = null; AltosState old_state = null; + boolean told; idle_thread = new IdleThread(); @@ -413,8 +453,8 @@ public class AltosUI extends JFrame { state = new AltosState(record, state); update(state); show(state, crc_errors); - tell(state, old_state); - idle_thread.notice(state); + told = tell(state, old_state); + idle_thread.notice(state, told); } catch (ParseException pp) { System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); } catch (AltosCRCException ce) { -- cgit v1.2.3 From 38e1d87c8d449866faac026577fefa9a118428cb Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:23:53 -0700 Subject: altosui: Use local .class files in the classpath This ensures that compiling only a few changed files will locate the old .class files instead of using a stale .jar file. --- ao-tools/altosui/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index bc8dbc0d..98482823 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -1,7 +1,7 @@ JAVAROOT=classes AM_JAVACFLAGS=-encoding UTF-8 -CLASSPATH_ENV=CLASSPATH="classes/altosui/*:../libaltos/libaltosJNI/*:$(FREETTS)/*:/usr/share/java/*" +CLASSPATH_ENV=CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" altosui_JAVA = \ AltosChannelMenu.java \ -- cgit v1.2.3 From 6c653a4cba5fef8d49261cf1c024f3e86e9058c6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:52:36 -0700 Subject: altosui: Record flight number when scanning file, not when running The very first record in the eeprom is the flight number, but it is time-stamped with the 'boost' time, and so it gets sorted until much later, delaying the return of data until the rocket enters boost mode. This drops all of the nice pad GPS and state date on the floor. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index ac54ff44..86bbaee0 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -130,9 +130,7 @@ public class AltosEepromReader extends AltosReader { state.tick = record.tick; switch (record.cmd) { case Altos.AO_LOG_FLIGHT: - state.ground_accel = record.a; - state.flight = record.b; - seen |= seen_flight; + /* recorded when first read from the file */ break; case Altos.AO_LOG_SENSOR: state.accel = record.a; @@ -351,6 +349,11 @@ public class AltosEepromReader extends AltosReader { saw_boost = true; boost_tick = tick; } + if (record.cmd == Altos.AO_LOG_FLIGHT) { + state.ground_accel = record.a; + state.flight = record.b; + seen |= seen_flight; + } /* Two firmware bugs caused the loss of some GPS data. * The flight date would never be recorded, and often -- cgit v1.2.3 From b61fec225ada6a9e252e4c7920101ee18c77cbdc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:55:56 -0700 Subject: altosui: eeprom files place 'boost' time in the flight number record. Instead of looking for the first state change record, use the Flight record to get the boost tick. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 86bbaee0..cb82f9a9 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -101,8 +101,6 @@ public class AltosEepromReader extends AltosReader { int gps_tick; - boolean saw_boost; - int boost_tick; boolean saw_gps_date; @@ -343,15 +341,10 @@ public class AltosEepromReader extends AltosReader { if (record.cmd == Altos.AO_LOG_INVALID) continue; tick = record.tick; - if (!saw_boost && record.cmd == Altos.AO_LOG_STATE && - record.a >= Altos.ao_flight_boost) - { - saw_boost = true; - boost_tick = tick; - } if (record.cmd == Altos.AO_LOG_FLIGHT) { state.ground_accel = record.a; state.flight = record.b; + boost_tick = tick; seen |= seen_flight; } -- cgit v1.2.3 From 3d49d5f69b41c27003dbc5ccf1899014bd13bd99 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 02:05:06 -0700 Subject: altosui: ensure that 'altosui' script is installed. Pass arguments along. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 6 ++++-- ao-tools/altosui/altosui-fat | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 98482823..dd4b31e6 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -3,6 +3,8 @@ AM_JAVACFLAGS=-encoding UTF-8 CLASSPATH_ENV=CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" +bin_SCRIPTS=altosui + altosui_JAVA = \ AltosChannelMenu.java \ AltosConfig.java \ @@ -129,12 +131,12 @@ Manifest-fat.txt: altosui: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="$(libdir)" -jar "$(altosuidir)/altosui.jar"' >> $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="$(libdir)" -jar "$(altosuidir)/altosui.jar" "$$@"' >> $@ chmod +x $@ altosui-test: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos" -jar altosui.jar' >> $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos" -jar altosui.jar "$$*"' >> $@ chmod +x $@ $(LIBALTOS): diff --git a/ao-tools/altosui/altosui-fat b/ao-tools/altosui/altosui-fat index 9e5a8f15..95b1c051 100755 --- a/ao-tools/altosui/altosui-fat +++ b/ao-tools/altosui/altosui-fat @@ -1,4 +1,4 @@ #!/bin/sh me=`which "$0"` dir=`dirname "$me"` -exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui-fat.jar +exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui-fat.jar "$@" -- cgit v1.2.3 From 16980b848651a6b20a0b458446f0a19fb517539d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 15:10:25 -0700 Subject: altosui: Add explicit requirement to create classes directory The implicit ordering doesn't appear reliable. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index dd4b31e6..4bb67c97 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -91,8 +91,8 @@ WINDOWS_FILES=$(FAT_FILES) altos.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON all-local: classes/altosui $(JAR) $(FATJAR) altosui altosui-test clean-local: - -rm -rf classes/altosui $(JAR) $(FATJAR) \ - $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) $(FREETTS_CLASS) \ + -rm -rf classes $(JAR) $(FATJAR) \ + $(LINUX_DIST) $(MACOSX_DIST) windows $(WINDOWS_DIST) $(FREETTS_CLASS) \ $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ altosui altosui-test macosx linux @@ -109,6 +109,11 @@ install-altosuiJAVA: altosui.jar classes/altosui: mkdir -p classes/altosui +classaltosui.stamp: classes + +classes: + mkdir -p classes + $(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) jar cfm $@ Manifest.txt \ -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ -- cgit v1.2.3 From b456bd9d7bcd9d968e43c38eeb6fa6ad8c58f895 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 15:11:41 -0700 Subject: altosui: fix telemetrum.inf FFFE:000A product names on AMD64 and ia64 This appears to matter to Vista. Dunno why. Signed-off-by: Keith Packard --- ao-tools/altosui/altos-windows.nsi | 3 +++ telemetrum.inf | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi index 6ebec214..37777fd6 100644 --- a/ao-tools/altosui/altos-windows.nsi +++ b/ao-tools/altosui/altos-windows.nsi @@ -40,6 +40,9 @@ Section "Install Driver" InstDriver SetOutPath $TEMP File "../../telemetrum.inf" InstDrv::InstallDriver /NOUNLOAD "$TEMP\telemetrum.inf" + + SetOutPath $INSTDIR + File "../../telemetrum.inf" SectionEnd Section "AltosUI Application" diff --git a/telemetrum.inf b/telemetrum.inf index 0a81084b..0d1a5534 100755 --- a/telemetrum.inf +++ b/telemetrum.inf @@ -6,7 +6,7 @@ Signature = "$Windows NT$" Class = Modem ClassGUID ={4D36E96D-E325-11CE-BFC1-08002BE10318} Provider = %Mfg% -DriverVer = 08/05/2010,3.1.0.41 +DriverVer = 08/05/2010,7.1.0.0 [Manufacturer] %Mfg% = Models, NTx86, NTamd64, NTia64 @@ -18,13 +18,13 @@ DriverVer = 08/05/2010,3.1.0.41 %TeleTerra% = TELEMETRUM, USB\VID_FFFE&PID_000D [Models.NTamd64] -%TeleMetrum% = TELEMETRUM, USB\VID_FFFE&PID_000A +%AltusMetrum% = TELEMETRUM, USB\VID_FFFE&PID_000A %TeleMetrum% = TELEMETRUM, USB\VID_FFFE&PID_000B %TeleDongle% = TELEMETRUM, USB\VID_FFFE&PID_000C %TeleTerra% = TELEMETRUM, USB\VID_FFFE&PID_000D [Models.NTia64] -%TeleMetrum% = TELEMETRUM, USB\VID_FFFE&PID_000A +%AltusMetrum% = TELEMETRUM, USB\VID_FFFE&PID_000A %TeleMetrum% = TELEMETRUM, USB\VID_FFFE&PID_000B %TeleDongle% = TELEMETRUM, USB\VID_FFFE&PID_000C %TeleTerra% = TELEMETRUM, USB\VID_FFFE&PID_000D @@ -40,7 +40,7 @@ ExcludeFromSelect=USB\VID_FFFE&PID_000D [Strings] Mfg = "altusmetrum.org" -AltusMetrum = "Unknown AltusMetrum Device" +AltusMetrum = "AltusMetrum" TeleMetrum = "TeleMetrum" TeleDongle = "TeleDongle" TeleTerra = "TeleTerra" -- cgit v1.2.3 From 737a64c57a8f979f51c3fa6b3f214520c736cf8a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 15:22:14 -0700 Subject: altosui: hack to make JAVAROOT directory get created before javac runs This ensures that the JAVAROOT directory gets created by adding it to the variable used to set the CLASSPATH environment value. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 4bb67c97..f224dace 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -1,7 +1,7 @@ JAVAROOT=classes AM_JAVACFLAGS=-encoding UTF-8 -CLASSPATH_ENV=CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" +CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" bin_SCRIPTS=altosui @@ -109,11 +109,6 @@ install-altosuiJAVA: altosui.jar classes/altosui: mkdir -p classes/altosui -classaltosui.stamp: classes - -classes: - mkdir -p classes - $(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) jar cfm $@ Manifest.txt \ -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ -- cgit v1.2.3 From 6c0ae7e966a81ece35bccbe89d626a58afe899a2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 15:25:18 -0700 Subject: altosui: remove FATJAR from all-local to avoid building fat .jar file the fat .jar file is used in non-native builds to run from a directory containing all of the freetts jar files along with the altosui jar file. We don't want this on a real install where freetts is installed separately. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index f224dace..760e662d 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -88,7 +88,7 @@ MACOSX_EXTRA=$(FIRMWARE) WINDOWS_FILES=$(FAT_FILES) altos.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) -all-local: classes/altosui $(JAR) $(FATJAR) altosui altosui-test +all-local: classes/altosui $(JAR) altosui altosui-test clean-local: -rm -rf classes $(JAR) $(FATJAR) \ -- cgit v1.2.3 From 4224a7526e51eb8fbf1f0a31bae7ee68c6385095 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 17:52:46 -0700 Subject: altosui: Store libaltos.so in $(libdir)/altos It's not a public library, so hide it away in a subdirectory. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 6 ++++-- ao-tools/libaltos/Makefile.am | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 760e662d..804e0c74 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -1,6 +1,8 @@ JAVAROOT=classes AM_JAVACFLAGS=-encoding UTF-8 +altoslibdir=$(libdir)/altos + CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" bin_SCRIPTS=altosui @@ -131,12 +133,12 @@ Manifest-fat.txt: altosui: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="$(libdir)" -jar "$(altosuidir)/altosui.jar" "$$@"' >> $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="$(altoslibdir)" -jar "$(altosuidir)/altosui.jar" "$$@"' >> $@ chmod +x $@ altosui-test: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos" -jar altosui.jar "$$*"' >> $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos/.libs" -jar altosui.jar "$$@"' >> $@ chmod +x $@ $(LIBALTOS): diff --git a/ao-tools/libaltos/Makefile.am b/ao-tools/libaltos/Makefile.am index 4d29d80e..388d2104 100644 --- a/ao-tools/libaltos/Makefile.am +++ b/ao-tools/libaltos/Makefile.am @@ -1,11 +1,22 @@ JAVAC=javac -AM_CFLAGS="-I$(JVM_INCLUDE)" +AM_CFLAGS=-DLINUX -DPOSIX_TTY -I$(JVM_INCLUDE) AM_JAVACFLAGS=-encoding UTF-8 -lib_LTLIBRARIES=libaltos.la +altoslibdir=$(libdir)/altos + +altoslib_LTLIBRARIES=libaltos.la + +libaltos_la_LDFLAGS = -version-info 1:0:1 libaltos_la_SOURCES=\ - libaltos.c + libaltos.c \ + libaltos_wrap.c + +noinst_PROGRAMS=cjnitest + +cjnitest_LDADD=libaltos.la + +LIBS= HFILES=libaltos.h @@ -18,6 +29,8 @@ $(SWIG_FILE): libaltos.i0 $(HFILES) all-local: classlibaltos.stamp +libaltos_wrap.c: classlibaltos.stamp + classlibaltos.stamp: $(SWIG_FILE) swig -java -package libaltosJNI $(SWIG_FILE) mkdir -p libaltosJNI @@ -25,4 +38,4 @@ classlibaltos.stamp: $(SWIG_FILE) touch classlibaltos.stamp clean-local: - -rm -rf libaltosJNI *.class *.java classlibaltos.stamp $(SWIG_FILE) \ No newline at end of file + -rm -rf libaltosJNI *.class *.java classlibaltos.stamp $(SWIG_FILE) libaltos_wrap.c -- cgit v1.2.3 From 8ee3464d8064ebe1694c7b20177878c0d9961451 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 17:54:41 -0700 Subject: altosui: Display error dialog when AltOS JNI library can't be loaded Having an error dialog appear at application startup seems better than simply failing to present the device dialog later on. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDevice.java | 77 ++++++++++++++++++++++++++------- ao-tools/altosui/AltosDeviceDialog.java | 13 ++++-- ao-tools/altosui/AltosUI.java | 14 ++++++ 3 files changed, 85 insertions(+), 19 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index e62a0a7a..9ae522c2 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -22,20 +22,67 @@ import libaltosJNI.*; public class AltosDevice extends altos_device { - static boolean initialized = false; - static { - try { - System.loadLibrary("altos"); - libaltos.altos_init(); + static public boolean initialized = false; + static public boolean loaded_library = false; + + public static boolean load_library() { + if (!initialized) { + try { + System.loadLibrary("altos"); + libaltos.altos_init(); + loaded_library = true; + } catch (UnsatisfiedLinkError e) { + loaded_library = false; + } initialized = true; - } catch (UnsatisfiedLinkError e) { - System.err.println("Native library failed to load.\n" + e); } + return loaded_library; + } + + static int usb_product_altusmetrum() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_ALTUSMETRUM; + return 0x000a; + } + + static int usb_product_altusmetrum_min() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MIN; + return 0x000a; + } + + static int usb_product_altusmetrum_max() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MAX; + return 0x000d; + } + + static int usb_product_telemetrum() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_TELEMETRUM; + return 0x000b; + } + + static int usb_product_teledongle() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_ALTUSMETRUM; + return 0x000c; + } + + static int usb_product_teleterra() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_ALTUSMETRUM; + return 0x000d; } - public final static int AltusMetrum = libaltosConstants.USB_PRODUCT_ALTUSMETRUM; - public final static int TeleMetrum = libaltosConstants.USB_PRODUCT_TELEMETRUM; - public final static int TeleDongle = libaltosConstants.USB_PRODUCT_TELEDONGLE; - public final static int TeleTerra = libaltosConstants.USB_PRODUCT_TELETERRA; + + public final static int AltusMetrum = usb_product_altusmetrum(); + public final static int TeleMetrum = usb_product_telemetrum(); + public final static int TeleDongle = usb_product_teledongle(); + public final static int TeleTerra = usb_product_teleterra(); + public final static int AltusMetrumMin = usb_product_altusmetrum_min(); + public final static int AltusMetrumMax = usb_product_altusmetrum_max(); + + public final static int Any = 0x10000; public final static int BaseStation = 0x10000 + 1; @@ -48,11 +95,11 @@ public class AltosDevice extends altos_device { } public boolean isAltusMetrum() { - if (getVendor() != libaltosConstants.USB_VENDOR_ALTUSMETRUM) + if (getVendor() != AltusMetrum) return false; - if (getProduct() < libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MIN) + if (getProduct() < AltusMetrumMin) return false; - if (getProduct() > libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MAX) + if (getProduct() > AltusMetrumMax) return false; return true; } @@ -80,7 +127,7 @@ public class AltosDevice extends altos_device { } static AltosDevice[] list(int product) { - if (!initialized) + if (!load_library()) return null; SWIGTYPE_p_altos_list list = libaltos.altos_list_start(); diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java index 3df4c6eb..ec78e288 100644 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -49,10 +49,15 @@ public class AltosDeviceDialog extends JDialog implements ActionListener { dialog.setVisible(true); return value; } else { - JOptionPane.showMessageDialog(frame, - "No AltOS devices available", - "No AltOS devices", - JOptionPane.ERROR_MESSAGE); + /* check for missing altos JNI library, which + * will put up its own error dialog + */ + if (AltosUI.load_library(frame)) { + JOptionPane.showMessageDialog(frame, + "No AltOS devices available", + "No AltOS devices", + JOptionPane.ERROR_MESSAGE); + } return null; } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 3aaeb888..ca587b25 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -70,8 +70,22 @@ public class AltosUI extends JFrame { public AltosVoice voice = new AltosVoice(); + public static boolean load_library(Frame frame) { + if (!AltosDevice.load_library()) { + JOptionPane.showMessageDialog(frame, + String.format("No AltOS library in \"%s\"", + System.getProperty("java.library.path","")), + "Cannot load device access library", + JOptionPane.ERROR_MESSAGE); + return false; + } + return true; + } + public AltosUI() { + load_library(null); + String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; Object[][] statusData = { { "0", "pad", "-50", "0" } }; -- cgit v1.2.3 From 1ac3d7e3ba52d1b0dc834eaa5d7886c730eaf307 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 9 Sep 2010 20:34:22 -0600 Subject: initial cut at an altosui man page --- ao-tools/altosui/Makefile.am | 4 +++- ao-tools/altosui/altosui.1 | 16 +++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 804e0c74..3e0d7c9b 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -1,6 +1,8 @@ JAVAROOT=classes AM_JAVACFLAGS=-encoding UTF-8 +man_MANS=altosui.1 + altoslibdir=$(libdir)/altos CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" @@ -171,4 +173,4 @@ $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) $(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi -rm -f $@ - makensis -Oaltos-windows.log "-XOutFile $@" "-DVERSION=$(VERSION)" altos-windows.nsi \ No newline at end of file + makensis -Oaltos-windows.log "-XOutFile $@" "-DVERSION=$(VERSION)" altos-windows.nsi diff --git a/ao-tools/altosui/altosui.1 b/ao-tools/altosui/altosui.1 index c3130fce..57fa4489 100644 --- a/ao-tools/altosui/altosui.1 +++ b/ao-tools/altosui/altosui.1 @@ -16,7 +16,7 @@ .\" 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. .\" .\" -.TH AO-VIEW 1 "altosui" "" +.TH ALTOSUI 1 "altosui" "" .SH NAME altosui \- Rocket flight monitor .SH SYNOPSIS @@ -24,21 +24,23 @@ altosui \- Rocket flight monitor .SH DESCRIPTION .I altosui connects to a TeleDongle or TeleMetrum device through a USB serial device. -It provides a user interface to monitor, record and review rocket flight data. +It provides a menu-oriented +user interface to monitor, record and review rocket flight data. .SH USAGE When connected to a TeleDongle device, altosui turns on the radio receiver and listens for telemetry packets. It displays the received telemetry data, and reports flight status via voice synthesis. All received telemetry information is recorded to a file. .P -When connected to a TeleMetrum device, altosui downloads the eeprom -data and stores it in a file. +When connected to a TeleMetrum device, altosui can be used to configure the +TeleMetrum, and to downloads the eeprom data and store it in a file. +.P +A number of other menu options exist, including the ability to export flight +data in different formats. .SH FILES All data log files are recorded into a user-specified directory -(default ~/AltOS). Files are named using the current date, the serial +(default ~/TeleMetrum). Files are named using the current date, the serial number of the reporting device, the flight number recorded in the data and either '.telem' for telemetry data or '.eeprom' for eeprom data. -.SH "SEE ALSO" -ao-view(1), ao-load(1), ao-eeprom(1) .SH AUTHOR Keith Packard -- cgit v1.2.3 From 48f57997452e17564e28fe3e37403f6f63d32dea Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 20:24:42 -0700 Subject: altosui: conflating USB product and vendor IDs is a bad idea We've now got a USB vendor ID called 'altusmetrum' for generic altusmetrum devices (old USB ID 0x000A) while the general vendor name for all devices is 'altusmetrum' as well. This patch splits vendors and products into separate name spaces, products are prefixed with product_ and vendor with (oddly) vendor_. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 4 +-- ao-tools/altosui/AltosDevice.java | 52 ++++++++++++++++++++----------- ao-tools/altosui/AltosEepromDownload.java | 4 +-- ao-tools/altosui/AltosFlashUI.java | 2 +- ao-tools/altosui/AltosUI.java | 3 +- 5 files changed, 41 insertions(+), 24 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 3d970748..7b6cd78c 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -238,12 +238,12 @@ public class AltosConfig implements Runnable, ActionListener { version = new string_ref("unknown"); product = new string_ref("unknown"); - device = AltosDeviceDialog.show(owner, AltosDevice.Any); + device = AltosDeviceDialog.show(owner, AltosDevice.product_any); serial_line = new AltosSerial(); if (device != null) { try { serial_line.open(device); - if (!device.matchProduct(AltosDevice.TeleMetrum)) + if (!device.matchProduct(AltosDevice.product_telemetrum)) remote = true; config_thread = new Thread(this); config_thread.start(); diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index 9ae522c2..d671031d 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -39,6 +39,12 @@ public class AltosDevice extends altos_device { return loaded_library; } + static int usb_vendor_altusmetrum() { + if (load_library()) + return libaltosConstants.USB_VENDOR_ALTUSMETRUM; + return 0x000a; + } + static int usb_product_altusmetrum() { if (load_library()) return libaltosConstants.USB_PRODUCT_ALTUSMETRUM; @@ -65,26 +71,27 @@ public class AltosDevice extends altos_device { static int usb_product_teledongle() { if (load_library()) - return libaltosConstants.USB_PRODUCT_ALTUSMETRUM; + return libaltosConstants.USB_PRODUCT_TELEDONGLE; return 0x000c; } static int usb_product_teleterra() { if (load_library()) - return libaltosConstants.USB_PRODUCT_ALTUSMETRUM; + return libaltosConstants.USB_PRODUCT_TELETERRA; return 0x000d; } - public final static int AltusMetrum = usb_product_altusmetrum(); - public final static int TeleMetrum = usb_product_telemetrum(); - public final static int TeleDongle = usb_product_teledongle(); - public final static int TeleTerra = usb_product_teleterra(); - public final static int AltusMetrumMin = usb_product_altusmetrum_min(); - public final static int AltusMetrumMax = usb_product_altusmetrum_max(); + public final static int vendor_altusmetrum = usb_vendor_altusmetrum(); + public final static int product_altusmetrum = usb_product_altusmetrum(); + public final static int product_telemetrum = usb_product_telemetrum(); + public final static int product_teledongle = usb_product_teledongle(); + public final static int product_teleterra = usb_product_teleterra(); + public final static int product_altusmetrum_min = usb_product_altusmetrum_min(); + public final static int product_altusmetrum_max = usb_product_altusmetrum_max(); - public final static int Any = 0x10000; - public final static int BaseStation = 0x10000 + 1; + public final static int product_any = 0x10000; + public final static int product_basestation = 0x10000 + 1; public String toString() { String name = getName(); @@ -95,29 +102,34 @@ public class AltosDevice extends altos_device { } public boolean isAltusMetrum() { - if (getVendor() != AltusMetrum) + if (getVendor() != vendor_altusmetrum) return false; - if (getProduct() < AltusMetrumMin) + if (getProduct() < product_altusmetrum_min) return false; - if (getProduct() > AltusMetrumMax) + if (getProduct() > product_altusmetrum_max) return false; return true; } public boolean matchProduct(int want_product) { + System.out.printf("vendor %x product %x want %x\n", + getVendor(), getProduct(), want_product); + System.out.printf("vendor_altusmetrum: %d\n", vendor_altusmetrum); + System.out.printf("telemetrum: %d\n", product_telemetrum); + if (!isAltusMetrum()) return false; - if (want_product == Any) + if (want_product == product_any) return true; - if (want_product == BaseStation) - return matchProduct(TeleDongle) || matchProduct(TeleTerra); + if (want_product == product_basestation) + return matchProduct(product_teledongle) || matchProduct(product_teleterra); int have_product = getProduct(); - if (have_product == AltusMetrum) /* old devices match any request */ + if (have_product == product_altusmetrum) /* old devices match any request */ return true; if (want_product == have_product) @@ -127,19 +139,23 @@ public class AltosDevice extends altos_device { } static AltosDevice[] list(int product) { - if (!load_library()) + if (!load_library()) { + System.out.printf("no library\n"); return null; + } SWIGTYPE_p_altos_list list = libaltos.altos_list_start(); ArrayList device_list = new ArrayList(); if (list != null) { + System.out.printf("got device list\n"); SWIGTYPE_p_altos_file file; for (;;) { AltosDevice device = new AltosDevice(); if (libaltos.altos_list_next(list, device) == 0) break; + System.out.printf("got device\n"); if (device.matchProduct(product)) device_list.add(device); } diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 6dbbd3eb..a7f64904 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -254,7 +254,7 @@ public class AltosEepromDownload implements Runnable { public AltosEepromDownload(JFrame given_frame) { frame = given_frame; - device = AltosDeviceDialog.show(frame, AltosDevice.Any); + device = AltosDeviceDialog.show(frame, AltosDevice.product_any); serial_line = new AltosSerial(); remote = false; @@ -262,7 +262,7 @@ public class AltosEepromDownload implements Runnable { if (device != null) { try { serial_line.open(device); - if (!device.matchProduct(AltosDevice.TeleMetrum)) + if (!device.matchProduct(AltosDevice.product_telemetrum)) remote = true; eeprom_thread = new Thread(this); eeprom_thread.start(); diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 18795695..5ed417da 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -187,7 +187,7 @@ public class AltosFlashUI build_dialog(); - debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.Any); + debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.product_any); if (debug_dongle == null) return; diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index ca587b25..edee146d 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -523,7 +523,8 @@ public class AltosUI extends JFrame { } private void ConnectToDevice() { - AltosDevice device = AltosDeviceDialog.show(AltosUI.this, AltosDevice.BaseStation); + AltosDevice device = AltosDeviceDialog.show(AltosUI.this, + AltosDevice.product_basestation); if (device != null) { try { -- cgit v1.2.3 From 72a5c1258db92d0ddd660bfa875e8e55cab47af7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 20:39:41 -0700 Subject: altosui: Remove some debug printfs. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDevice.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index d671031d..f646305b 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -113,11 +113,6 @@ public class AltosDevice extends altos_device { public boolean matchProduct(int want_product) { - System.out.printf("vendor %x product %x want %x\n", - getVendor(), getProduct(), want_product); - System.out.printf("vendor_altusmetrum: %d\n", vendor_altusmetrum); - System.out.printf("telemetrum: %d\n", product_telemetrum); - if (!isAltusMetrum()) return false; @@ -139,23 +134,19 @@ public class AltosDevice extends altos_device { } static AltosDevice[] list(int product) { - if (!load_library()) { - System.out.printf("no library\n"); + if (!load_library()) return null; - } SWIGTYPE_p_altos_list list = libaltos.altos_list_start(); ArrayList device_list = new ArrayList(); if (list != null) { - System.out.printf("got device list\n"); SWIGTYPE_p_altos_file file; for (;;) { AltosDevice device = new AltosDevice(); if (libaltos.altos_list_next(list, device) == 0) break; - System.out.printf("got device\n"); if (device.matchProduct(product)) device_list.add(device); } -- cgit v1.2.3 From dd2b77b2a516a055f29191dcdfeb727e637aae86 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 20:59:29 -0700 Subject: altosui: libaltos.so is built with libtool -- it's in ../libaltos/.libs It used to be in ../libaltos Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 3e0d7c9b..56e6d7ae 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -143,7 +143,15 @@ altosui-test: Makefile echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos/.libs" -jar altosui.jar "$$@"' >> $@ chmod +x $@ -$(LIBALTOS): +libaltos.so: + -rm -f "$@" + $(LN_S) ../libaltos/.libs/"$@" . + +libaltos.dylib: + -rm -f "$@" + $(LN_S) ../libaltos/"$@" . + +altos.dll: -rm -f "$@" $(LN_S) ../libaltos/"$@" . -- cgit v1.2.3 From 2d5e48c5dc0e822fdf430f43804c1e5e79fdbf84 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 21:28:10 -0700 Subject: Add --with-fat-dir configure option to publish finished stand-alone bits --with-fat-dir specifies a directory to copy the finished linux/macosx/windows stand-alone ("fat") packages to. A sub-directory will be created under the specified directory based on the product version number and the files copied there. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 24 ++++++++++++++++++++++++ configure.ac | 8 ++++++++ 2 files changed, 32 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 56e6d7ae..fa391889 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -102,6 +102,30 @@ clean-local: fat: $(FATJAR) $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) +if FATINSTALL + +FATTARGET=$(FATDIR)/$(VERSION) + +LINUX_DIST_TARGET=$(FATTARGET)/$(LINUX_DIST) +MACOSX_DIST_TARGET=$(FATTARGET)/$(MACOSX_DIST) +WINDOWS_DIST_TARGET=$(FATTARGET)/$(WINDOWS_DIST) + +fat: $(LINUX_DIST_TARGET) $(MACOSX_DIST_TARGET) $(WINDOWS_DIST_TARGET) + +$(LINUX_DIST_TARGET): $(LINUX_DIST) + mkdir -p $(FATTARGET) + cp -p $< $@ + +$(MACOSX_DIST_TARGET): $(MACOSX_DIST) + mkdir -p $(FATTARGET) + cp -p $< $@ + +$(WINDOWS_DIST_TARGET): $(WINDOWS_DIST) + mkdir -p $(FATTARGET) + cp -p $< $@ + +endif + altosuidir=$(datadir)/java install-altosuiJAVA: altosui.jar diff --git a/configure.ac b/configure.ac index 61c03b18..4bf8f7fe 100644 --- a/configure.ac +++ b/configure.ac @@ -58,6 +58,14 @@ fi AC_SUBST(JVM_INCLUDE) +AC_ARG_WITH(fat-dir, AS_HELP_STRING([--with-fat-dir=PATH], + [Set the directory to install the 'fat' distribution files to (defaults to not installing)]), + [FATDIR=$withval], [FATDIR=none]) + +AM_CONDITIONAL(FATINSTALL, [test "x$FATDIR" != "xnone"]) + +AC_SUBST(FATDIR) + AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S -- cgit v1.2.3 From af200f5b84555de0556b52146379f3934774a3f3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 22:30:48 -0700 Subject: altosui: Fix telemetry file reader to handle tick count wrapping The telemetry reader was ignoring tick count wrapping, so you'd see time go backwards in jumps. Not useful. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosTelemetryReader.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index fdedbde2..ae9682ab 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -41,6 +41,7 @@ public class AltosTelemetryReader extends AltosReader { public AltosTelemetryReader (FileInputStream input) { boolean saw_boost = false; + int current_tick = 0; records = new LinkedList (); @@ -51,9 +52,20 @@ public class AltosTelemetryReader extends AltosReader { break; } try { + System.out.printf("%s\n", line); AltosTelemetry record = new AltosTelemetry(line); if (record == null) break; + if (records.isEmpty()) { + current_tick = record.tick; + } else { + int tick = record.tick | (current_tick & ~ 0xffff); + if (tick < current_tick - 0x1000) + tick += 0x10000; + current_tick = tick; + record.tick = current_tick; + } + System.out.printf("\tRSSI %d tick %d\n", record.rssi, record.tick); if (!saw_boost && record.state >= Altos.ao_flight_boost) { saw_boost = true; -- cgit v1.2.3 From 8b0b584cd0ca7542e65aac0c7897ad7ab4115122 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 22:55:47 -0700 Subject: altosui: Remove debug printfs from AltosTelemetryReader Signed-off-by: Keith Packard --- ao-tools/altosui/AltosTelemetryReader.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index ae9682ab..3564a0a5 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -52,7 +52,6 @@ public class AltosTelemetryReader extends AltosReader { break; } try { - System.out.printf("%s\n", line); AltosTelemetry record = new AltosTelemetry(line); if (record == null) break; @@ -65,7 +64,6 @@ public class AltosTelemetryReader extends AltosReader { current_tick = tick; record.tick = current_tick; } - System.out.printf("\tRSSI %d tick %d\n", record.rssi, record.tick); if (!saw_boost && record.state >= Altos.ao_flight_boost) { saw_boost = true; -- cgit v1.2.3 From 67b6952f7126704478ede5575e5e938d18fcc329 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 23:04:14 -0700 Subject: altosui: Fill in time value of last Eeprom record read from file The last record is handled separately, and was missing the code to compute the time. Sigh. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index cb82f9a9..f1d6a6a7 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -114,7 +114,9 @@ public class AltosEepromReader extends AltosReader { if (last_reported) return null; last_reported = true; - return new AltosRecord(state); + AltosRecord r = new AltosRecord(state); + r.time = (r.tick - boost_tick) / 100.0; + return r; } record = record_iterator.next(); -- cgit v1.2.3 From 9d0e89e8ad8926dc8371fa809835a580ae49711d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Sep 2010 23:04:59 -0700 Subject: altosui: Stop parsing eeprom file after hitting 'landed' state Sometimes there are additional records found in the eeprom file; the reader is mostly worried about not losing anything, so it reads as much as it can. However, the last record written for any flight is the 'landed' record, so we can stop looking at the file after hitting that. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index f1d6a6a7..4cc8536a 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -391,6 +391,11 @@ public class AltosEepromReader extends AltosReader { } } records.add(record); + + /* Bail after reading the 'landed' record; we're all done */ + if (record.cmd == Altos.AO_LOG_STATE && + record.a == Altos.ao_flight_landed) + break; } } catch (IOException io) { } catch (ParseException pe) { -- cgit v1.2.3 From 7e053ae1f2d09347123ac9fa79e46645378b4c70 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 10 Sep 2010 10:42:35 -0600 Subject: make the column headers comma separated, too, so they align with the data --- ao-tools/altosui/AltosCSV.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index 4ce8e30e..07fa371f 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -86,7 +86,7 @@ public class AltosCSV { */ void write_general_header() { - out.printf("version serial flight call time rssi"); + out.printf("version,serial,flight,call,time,rssi"); } void write_general(AltosRecord record) { @@ -97,7 +97,7 @@ public class AltosCSV { } void write_flight_header() { - out.printf("state state_name"); + out.printf("state,state_name"); } void write_flight(AltosRecord record) { @@ -105,7 +105,7 @@ public class AltosCSV { } void write_basic_header() { - out.printf("acceleration pressure altitude height accel_speed baro_speed temperature battery_voltage drogue_voltage main_voltage"); + out.printf("acceleration,pressure,altitude,height,accel_speed,baro_speed,temperature,battery_voltage,drogue_voltage,main_voltage"); } void write_basic(AltosRecord record) { @@ -123,7 +123,7 @@ public class AltosCSV { } void write_gps_header() { - out.printf("connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_range pad_az pad_el"); + out.printf("connected,locked,nsat,latitude,longitude,altitude,year,month,day,hour,minute,second,pad_dist,pad_range,pad_az,pad_el"); } void write_gps(AltosRecord record) { @@ -155,10 +155,10 @@ public class AltosCSV { } void write_header() { - out.printf("# "); write_general_header(); - out.printf(" "); write_flight_header(); - out.printf(" "); write_basic_header(); - out.printf(" "); write_gps_header(); + out.printf("#"); write_general_header(); + out.printf(","); write_flight_header(); + out.printf(","); write_basic_header(); + out.printf(","); write_gps_header(); out.printf ("\n"); } -- cgit v1.2.3 From 7f2204e0832b14b1edca4266a2cbc272141ecc2b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 10 Sep 2010 20:55:05 -0700 Subject: altosui: set default .csv file name in file save dialog This uses setSelectedFile to specify which output filename to make the default in the save dialog. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSVUI.java | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSVUI.java b/ao-tools/altosui/AltosCSVUI.java index 2d812361..643d4112 100644 --- a/ao-tools/altosui/AltosCSVUI.java +++ b/ao-tools/altosui/AltosCSVUI.java @@ -56,6 +56,7 @@ public class AltosCSVUI path = path.substring(0,dot); path = path.concat(".csv"); csv_chooser = new JFileChooser(path); + csv_chooser.setSelectedFile(new File(path)); int ret = csv_chooser.showSaveDialog(frame); if (ret == JFileChooser.APPROVE_OPTION) { try { -- cgit v1.2.3 From b9623f8ef26491e9fa14e2478295fe6f5cbbd87f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 10 Sep 2010 21:07:14 -0700 Subject: altosui: Remember directory containing firmware files Instead of forcing the user to navigate to the firmware directory each time, this remembers the previous directory and starts there. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlashUI.java | 7 +++++++ ao-tools/altosui/AltosPreferences.java | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 5ed417da..86f57a5f 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -194,6 +194,10 @@ public class AltosFlashUI JFileChooser hexfile_chooser = new JFileChooser(); + File firmwaredir = AltosPreferences.firmwaredir(); + if (firmwaredir != null) + hexfile_chooser.setCurrentDirectory(firmwaredir); + hexfile_chooser.setDialogTitle("Select Flash Image"); hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx")); int returnVal = hexfile_chooser.showOpenDialog(frame); @@ -203,6 +207,9 @@ public class AltosFlashUI file = hexfile_chooser.getSelectedFile(); + if (file != null) + AltosPreferences.set_firmwaredir(file.getParentFile()); + thread = new Thread(this); thread.start(); } diff --git a/ao-tools/altosui/AltosPreferences.java b/ao-tools/altosui/AltosPreferences.java index 690f8f1e..52627563 100644 --- a/ao-tools/altosui/AltosPreferences.java +++ b/ao-tools/altosui/AltosPreferences.java @@ -40,6 +40,9 @@ class AltosPreferences { /* callsign preference name */ final static String callsignPreference = "CALLSIGN"; + /* firmware directory preference name */ + final static String firmwaredirPreference = "FIRMWARE"; + /* Default logdir is ~/TeleMetrum */ final static String logdirName = "TeleMetrum"; @@ -55,8 +58,12 @@ class AltosPreferences { /* Voice preference */ static boolean voice; + /* Callsign preference */ static String callsign; + /* Firmware directory */ + static File firmwaredir; + public static void init(Component ui) { preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); @@ -78,6 +85,12 @@ class AltosPreferences { voice = preferences.getBoolean(voicePreference, true); callsign = preferences.get(callsignPreference,"N0CALL"); + + String firmwaredir_string = preferences.get(firmwaredirPreference, null); + if (firmwaredir_string != null) + firmwaredir = new File(firmwaredir_string); + else + firmwaredir = null; } static void flush_preferences() { @@ -173,4 +186,16 @@ class AltosPreferences { public static String callsign() { return callsign; } + + public static void set_firmwaredir(File new_firmwaredir) { + firmwaredir = new_firmwaredir; + synchronized (preferences) { + preferences.put(firmwaredirPreference, firmwaredir.getPath()); + flush_preferences(); + } + } + + public static File firmwaredir() { + return firmwaredir; + } } -- cgit v1.2.3 From 61590b8729831cb138b2ba6b88802c208d114753 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 15 Sep 2010 06:51:05 +1000 Subject: Add graphing. --- ao-tools/altosui/AltosCsvReader.java | 113 +++++++++++ ao-tools/altosui/AltosDataPoint.java | 29 +++ ao-tools/altosui/AltosGraph.java | 27 +++ ao-tools/altosui/AltosGraphDataChooser.java | 77 +++++++ ao-tools/altosui/AltosGraphTime.java | 222 ++++++++++++++++++++ ao-tools/altosui/AltosGraphUI.java | 301 ++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 17 +- 7 files changed, 785 insertions(+), 1 deletion(-) create mode 100644 ao-tools/altosui/AltosCsvReader.java create mode 100644 ao-tools/altosui/AltosDataPoint.java create mode 100644 ao-tools/altosui/AltosGraph.java create mode 100644 ao-tools/altosui/AltosGraphDataChooser.java create mode 100644 ao-tools/altosui/AltosGraphTime.java create mode 100644 ao-tools/altosui/AltosGraphUI.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCsvReader.java b/ao-tools/altosui/AltosCsvReader.java new file mode 100644 index 00000000..600788f4 --- /dev/null +++ b/ao-tools/altosui/AltosCsvReader.java @@ -0,0 +1,113 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.lang.UnsupportedOperationException; +import java.util.HashMap; +import java.util.NoSuchElementException; +import java.util.Iterator; +import java.io.*; +import com.csvreader.CsvReader; + +import altosui.AltosDataPoint; + +class AltosCsvReader implements Iterable +{ + public CsvReader csv; + public AltosDataPoint next = null; + + static protected String [] headers = "version serial flight call time rssi state state_name acceleration pressure altitude height accel_speed baro_speed temperature battery_voltage drogue_voltage main_voltage connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_range pad_az pad_el".split(" "); + + AltosCsvReader(Reader stream) { + csv = new CsvReader(stream); + csv.setComment('#'); + csv.setUseComments(true); + csv.setHeaders(headers); + } + AltosCsvReader(String filename) throws FileNotFoundException { + csv = new CsvReader(filename); + csv.setComment('#'); + csv.setUseComments(true); + csv.setHeaders(headers); + } + + public Iterator iterator() { + return new Iterator() { + public void remove() { + throw new UnsupportedOperationException(); + } + public boolean hasNext() { + if (next == null) { + try { + if (csv.readRecord()) { + next = new CsvRow(); + } else { + close(); + return false; + } + } catch (IOException e) { + close(); + return false; + } + } + return true; + } + public AltosDataPoint next() { + if (!hasNext()) + throw new NoSuchElementException(); + AltosDataPoint res = next; + next = null; + return res; + } + }; + } + + public void close() { + csv.close(); + } + + private class CsvRow extends HashMap + implements AltosDataPoint + { + CsvRow() throws IOException { + for (int i = 0; i < headers.length; i++) { + this.put(headers[i], csv.get(headers[i]).trim()); + } + } + + private int intField(String name) { + return Integer.parseInt(get(name).trim()); + } + private double doubleField(String name) { + return Double.valueOf(get(name)).doubleValue(); + } + private String stringField(String name) { + return get(name); + } + + public int version() { return intField("version"); } + public int serial() { return intField("serial"); } + public int flight() { return intField("flight"); } + public String callsign() { return stringField("call"); } + public double time() { return doubleField("time"); } + public double rssi() { return doubleField("rssi"); } + + public int state() { return intField("state"); } + public String state_name() { return stringField("state_name"); } + + public double acceleration() { return doubleField("acceleration"); } + public double pressure() { return doubleField("pressure"); } + public double altitude() { return doubleField("altitude"); } + public double height() { return doubleField("height"); } + public double accel_speed() { return doubleField("accel_speed"); } + public double baro_speed() { return doubleField("baro_speed"); } + public double temperature() { return doubleField("temperature"); } + public double battery_voltage() { + return doubleField("battery_voltage"); + } + public double drogue_voltage() { return doubleField("drogue_voltage"); } + public double main_voltage() { return doubleField("main_voltage"); } + } +} diff --git a/ao-tools/altosui/AltosDataPoint.java b/ao-tools/altosui/AltosDataPoint.java new file mode 100644 index 00000000..66313e03 --- /dev/null +++ b/ao-tools/altosui/AltosDataPoint.java @@ -0,0 +1,29 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +interface AltosDataPoint { + int version(); + int serial(); + int flight(); + String callsign(); + double time(); + double rssi(); + + int state(); + String state_name(); + + double acceleration(); + double pressure(); + double altitude(); + double height(); + double accel_speed(); + double baro_speed(); + double temperature(); + double battery_voltage(); + double drogue_voltage(); + double main_voltage(); +} + diff --git a/ao-tools/altosui/AltosGraph.java b/ao-tools/altosui/AltosGraph.java new file mode 100644 index 00000000..fa3b87c1 --- /dev/null +++ b/ao-tools/altosui/AltosGraph.java @@ -0,0 +1,27 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.io.*; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.ChartUtilities; + +import altosui.AltosDataPoint; + +abstract class AltosGraph { + public String filename; + public abstract void addData(AltosDataPoint d); + public abstract JFreeChart createChart(); + public void toPNG() throws java.io.IOException { toPNG(300, 500); } + public void toPNG(int width, int height) + throws java.io.IOException + { + File pngout = new File(filename); + JFreeChart chart = createChart(); + ChartUtilities.saveChartAsPNG(pngout, chart, width, height); + System.out.println("Created " + filename); + } +} diff --git a/ao-tools/altosui/AltosGraphDataChooser.java b/ao-tools/altosui/AltosGraphDataChooser.java new file mode 100644 index 00000000..1bf28454 --- /dev/null +++ b/ao-tools/altosui/AltosGraphDataChooser.java @@ -0,0 +1,77 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; + +import altosui.AltosPreferences; +import altosui.AltosReader; +import altosui.AltosCsvReader; +import altosui.AltosEepromReader; +import altosui.AltosTelemetryReader; + +public class AltosGraphDataChooser extends JFileChooser { + JFrame frame; + String filename; + File file; + + public String filename() { + return filename; + } + + public File file() { + return file; + } + + public Iterable runDialog() { + int ret; + + ret = showOpenDialog(frame); + if (ret == APPROVE_OPTION) { + file = getSelectedFile(); + if (file == null) + return null; + filename = file.getName(); + try { + return new AltosCsvReader(new FileReader(file)); + } catch (FileNotFoundException fe) { + JOptionPane.showMessageDialog(frame, + filename, + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + } + return null; + } + + public AltosGraphDataChooser(JFrame in_frame) { + frame = in_frame; + setDialogTitle("Select Flight Record File"); + setFileFilter(new FileNameExtensionFilter("Flight data file", + "csv")); + setCurrentDirectory(AltosPreferences.logdir()); + } +} diff --git a/ao-tools/altosui/AltosGraphTime.java b/ao-tools/altosui/AltosGraphTime.java new file mode 100644 index 00000000..c0f99c59 --- /dev/null +++ b/ao-tools/altosui/AltosGraphTime.java @@ -0,0 +1,222 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.HashMap; + +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.AxisLocation; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.labels.StandardXYToolTipGenerator; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.plot.ValueMarker; +import org.jfree.chart.renderer.xy.StandardXYItemRenderer; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import org.jfree.ui.RectangleAnchor; +import org.jfree.ui.TextAnchor; + +import altosui.AltosDataPoint; +import altosui.AltosGraph; + +class AltosGraphTime extends AltosGraph { + static interface Element { + void attachGraph(AltosGraphTime g); + void gotTimeData(double time, AltosDataPoint d); + void addToPlot(AltosGraphTime g, XYPlot plot); + } + + static class TimeAxis implements Element { + private int axis; + private Color color; + private String label; + private AxisLocation locn; + private double min_y = Double.NaN; + + public TimeAxis(int axis, String label, Color color, AxisLocation locn) + { + this.axis = axis; + this.color = color; + this.label = label; + this.locn = locn; + } + + public void setLowerBound(double min_y) { + this.min_y = min_y; + } + + public void attachGraph(AltosGraphTime g) { return; } + public void gotTimeData(double time, AltosDataPoint d) { return; } + + public void addToPlot(AltosGraphTime g, XYPlot plot) { + NumberAxis numAxis = new NumberAxis(label); + if (!Double.isNaN(min_y)) + numAxis.setLowerBound(min_y); + plot.setRangeAxis(axis, numAxis); + plot.setRangeAxisLocation(axis, locn); + numAxis.setLabelPaint(color); + numAxis.setTickLabelPaint(color); + numAxis.setAutoRangeIncludesZero(false); + } + } + + abstract static class TimeSeries implements Element { + protected XYSeries series; + private String axisName; + private Color color; + + public TimeSeries(String axisName, String label, Color color) { + this.series = new XYSeries(label); + this.axisName = axisName; + this.color = color; + } + + public void attachGraph(AltosGraphTime g) { + g.setAxis(this, axisName, color); + } + abstract public void gotTimeData(double time, AltosDataPoint d); + + public void addToPlot(AltosGraphTime g, XYPlot plot) { + XYSeriesCollection dataset = new XYSeriesCollection(); + dataset.addSeries(this.series); + + XYItemRenderer renderer = new StandardXYItemRenderer(); + renderer.setSeriesPaint(0, color); + + int dataNum = g.getDataNum(this); + int axisNum = g.getAxisNum(this); + + plot.setDataset(dataNum, dataset); + plot.mapDatasetToRangeAxis(dataNum, axisNum); + plot.setRenderer(dataNum, renderer); + } + } + + static class StateMarker implements Element { + private double val = Double.NaN; + private String name; + private int state; + + StateMarker(int state, String name) { + this.state = state; + this.name = name; + } + + public void attachGraph(AltosGraphTime g) { return; } + public void gotTimeData(double time, AltosDataPoint d) { + if (Double.isNaN(val) || time < val) { + if (d.state() == state) { + val = time; + } + } + } + + public void addToPlot(AltosGraphTime g, XYPlot plot) { + if (Double.isNaN(val)) + return; + + ValueMarker m = new ValueMarker(val); + m.setLabel(name); + m.setLabelAnchor(RectangleAnchor.TOP_RIGHT); + m.setLabelTextAnchor(TextAnchor.TOP_LEFT); + plot.addDomainMarker(m); + } + } + + private String title; + private ArrayList elements; + private HashMap axes; + private HashMap datasets; + private ArrayList datasetAxis; + + public AltosGraphTime(String title) { + this.filename = title.toLowerCase().replaceAll("[^a-z0-9]","_")+".png"; + this.title = title; + this.elements = new ArrayList(); + this.axes = new HashMap(); + this.datasets = new HashMap(); + this.datasetAxis = new ArrayList(); + } + + public AltosGraphTime addElement(Element e) { + e.attachGraph(this); + elements.add(e); + return this; + } + + public void setAxis(Element ds, String axisName, Color color) { + Integer axisNum = axes.get(axisName); + int dsNum = datasetAxis.size(); + if (axisNum == null) { + axisNum = newAxis(axisName, color); + } + datasets.put(ds, dsNum); + datasetAxis.add(axisNum); + } + + public int getAxisNum(Element ds) { + return datasetAxis.get( datasets.get(ds) ).intValue(); + } + public int getDataNum(Element ds) { + return datasets.get(ds).intValue(); + } + + private Integer newAxis(String name, Color color) { + int cnt = axes.size(); + AxisLocation locn = AxisLocation.BOTTOM_OR_LEFT; + if (cnt > 0) { + locn = AxisLocation.TOP_OR_RIGHT; + } + Integer res = new Integer(cnt); + axes.put(name, res); + this.addElement(new TimeAxis(cnt, name, color, locn)); + return res; + } + + public void addData(AltosDataPoint d) { + double time = d.time(); + for (Element e : elements) { + e.gotTimeData(time, d); + } + } + + public JFreeChart createChart() { + NumberAxis xAxis = new NumberAxis("Time (s)"); + xAxis.setAutoRangeIncludesZero(false); + XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); + XYPlot plot = new XYPlot(); + plot.setDomainAxis(xAxis); + plot.setRenderer(renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + + renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, + plot, true); + ChartUtilities.applyCurrentTheme(chart); + + plot.setDomainPannable(true); + plot.setRangePannable(true); + + for (Element e : elements) { + e.addToPlot(this, plot); + } + + return chart; + } + + public void toPNG() throws java.io.IOException { + if (axes.size() > 1) { + toPNG(800, 500); + } else { + toPNG(300, 500); + } + } +} diff --git a/ao-tools/altosui/AltosGraphUI.java b/ao-tools/altosui/AltosGraphUI.java new file mode 100644 index 00000000..73f95023 --- /dev/null +++ b/ao-tools/altosui/AltosGraphUI.java @@ -0,0 +1,301 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.io.*; +import java.util.ArrayList; + +import javax.swing.JFrame; +import java.awt.Color; + +import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.AxisLocation; +import org.jfree.ui.ApplicationFrame; +import org.jfree.ui.RefineryUtilities; + +import altosui.AltosCsvReader; +import altosui.AltosDataPoint; +import altosui.AltosGraphTime; + +public class AltosGraphUI extends JFrame +{ + static final private Color red = new Color(194,31,31); + static final private Color green = new Color(31,194,31); + static final private Color blue = new Color(31,31,194); + static final private Color black = new Color(31,31,31); + + static private class OverallGraphs { + AltosGraphTime.Element height = + new AltosGraphTime.TimeSeries("Height (m)", "Height (AGL)", red) { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.height()); + } + }; + + AltosGraphTime.Element speed = + new AltosGraphTime.TimeSeries("Speed (m/s)", "Vertical Speed", green) { + public void gotTimeData(double time, AltosDataPoint d) { + if (d.state() < 4) { + series.add(time, d.accel_speed()); + } else { + series.add(time, d.baro_speed()); + } + } + }; + + AltosGraphTime.Element acceleration = + new AltosGraphTime.TimeSeries("Acceleration (m/s\u00B2)", + "Axial Acceleration", blue) + { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.acceleration()); + } + }; + + AltosGraphTime.Element temperature = + new AltosGraphTime.TimeSeries("Temperature (\u00B0C)", + "Board temperature", red) + { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.temperature()); + } + }; + + AltosGraphTime.Element drogue_voltage = + new AltosGraphTime.TimeSeries("Voltage (V)", "Drogue Continuity", blue) + { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.drogue_voltage()); + } + }; + + AltosGraphTime.Element main_voltage = + new AltosGraphTime.TimeSeries("Voltage (V)", "Main Continuity", green) + { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.main_voltage()); + } + }; + + AltosGraphTime.Element e_pad = new AltosGraphTime.StateMarker(2, "Pad"); + AltosGraphTime.Element e_boost = new AltosGraphTime.StateMarker(3, "Boost"); + AltosGraphTime.Element e_fast = new AltosGraphTime.StateMarker(4, "Fast"); + AltosGraphTime.Element e_coast = new AltosGraphTime.StateMarker(5, "Coast"); + AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(6, "Drogue"); + AltosGraphTime.Element e_main = new AltosGraphTime.StateMarker(7, "Main"); + AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(8, "Landed"); + + protected AltosGraphTime myAltosGraphTime(String suffix) { + return (new AltosGraphTime("Overall " + suffix)) + .addElement(e_boost) + .addElement(e_drogue) + .addElement(e_main) + .addElement(e_landed); + } + + public ArrayList graphs() { + ArrayList graphs = new ArrayList(); + + graphs.add( myAltosGraphTime("Summary") + .addElement(height) + .addElement(speed) + .addElement(acceleration) ); + + graphs.add( myAltosGraphTime("Altitude") + .addElement(height) ); + + graphs.add( myAltosGraphTime("Speed") + .addElement(speed) ); + + graphs.add( myAltosGraphTime("Acceleration") + .addElement(acceleration) ); + + graphs.add( myAltosGraphTime("Temperature") + .addElement(temperature) ); + + graphs.add( myAltosGraphTime("Continuity") + .addElement(drogue_voltage) + .addElement(main_voltage) ); + + return graphs; + } + } + + static private class AscentGraphs extends OverallGraphs { + protected AltosGraphTime myAltosGraphTime(String suffix) { + return (new AltosGraphTime("Ascent " + suffix) { + public void addData(AltosDataPoint d) { + int state = d.state(); + if (3 <= state && state <= 5) { + super.addData(d); + } + } + }).addElement(e_boost) + .addElement(e_fast) + .addElement(e_coast); + } + } + + static private class DescentGraphs extends OverallGraphs { + protected AltosGraphTime myAltosGraphTime(String suffix) { + return (new AltosGraphTime("Descent " + suffix) { + public void addData(AltosDataPoint d) { + int state = d.state(); + if (6 <= state && state <= 7) { + super.addData(d); + } + } + }).addElement(e_drogue) + .addElement(e_main); + // ((XYGraph)graph[8]).ymin = new Double(-50); + } + } + + public AltosGraphUI(JFrame frame) + { + super("Altos Graph"); + + AltosGraphDataChooser chooser; + chooser = new AltosGraphDataChooser(frame); + Iterable reader = chooser.runDialog(); + if (reader == null) + return; + + init(reader, 0); + } + + public AltosGraphUI(Iterable data, int which) + { + super("Altos Graph"); + init(data, which); + } + + private void init(Iterable data, int which) { + AltosGraph graph = createGraph(data, which); + + JFreeChart chart = graph.createChart(); + ChartPanel chartPanel = new ChartPanel(chart); + chartPanel.setMouseWheelEnabled(true); + chartPanel.setPreferredSize(new java.awt.Dimension(800, 500)); + setContentPane(chartPanel); + + pack(); + + RefineryUtilities.centerFrameOnScreen(this); + + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + setVisible(true); + } + + private static AltosGraph createGraph(Iterable data, + int which) + { + return createGraphsWhich(data, which).get(0); + } + + private static ArrayList createGraphs( + Iterable data) + { + return createGraphsWhich(data, -1); + } + + private static ArrayList createGraphsWhich( + Iterable data, int which) + { + ArrayList graph = new ArrayList(); + graph.addAll((new OverallGraphs()).graphs()); + graph.addAll((new AscentGraphs()).graphs()); + graph.addAll((new DescentGraphs()).graphs()); + + if (which > 0) { + if (which >= graph.size()) { + which = 0; + } + AltosGraph g = graph.get(which); + graph = new ArrayList(); + graph.add(g); + } + + for (AltosDataPoint dp : data) { + for (AltosGraph g : graph) { + g.addData(dp); + } + } + + return graph; + } + + public static void main(String[] args) + throws java.io.FileNotFoundException, java.io.IOException + { + if (args.length < 1 || 2 < args.length) + { + System.out.println("Please specify telemetry csv"); + return; + } + + AltosCsvReader csv = new AltosCsvReader(args[0]); + if (args.length == 1) { + for (AltosGraph g : createGraphs(csv)) { + g.toPNG(); + } + } else { + int which = Integer.parseInt(args[1].trim()); + AltosGraphUI demo = new AltosGraphUI(csv, which); + } + } +} + +/* gnuplot bits... + * +300x400 + +-------------------------------------------------------- +TOO HARD! :) + +"ascent-gps-accuracy.png" "Vertical error margin to apogee - GPS v Baro (m)" + 5:($7 < 6 ? $24-$11 : 1/0) +"descent-gps-accuracy.png" "Vertical error margin during descent - GPS v Baro (m)" + 5:($7 < 6 ? 1/0 : $24-$11) + +set output "overall-gps-accuracy.png" +set ylabel "distance above sea level (m)" +plot "telemetry.csv" using 5:11 with lines ti "baro altitude" axis x1y1, \ + "telemetry.csv" using 5:24 with lines ti "gps altitude" axis x1y1 + +set term png tiny size 700,700 enhanced +set xlabel "m" +set ylabel "m" +set polar +set grid polar +set rrange[*:*] +set angles degrees + +set output "overall-gps-path.png" +#:30 with yerrorlines +plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0) with lines ti "pad", \ + "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0) with lines ti "boost", \ + "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0) with lines ti "fast", \ + "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0) with lines ti "coast", \ + "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \ + "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \ + "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed" + +set output "ascent-gps-path.png" +plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0):30 with lines ti "pad", \ + "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0):20 with lines ti "boost", \ + "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0):10 with lines ti "fast", \ + "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0):5 with lines ti "coast" + +set output "descent-gps-path.png" +plot "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \ + "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \ + "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed" + + */ + + diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index edee146d..ad02f2ef 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -667,6 +667,13 @@ public class AltosUI extends JFrame { new AltosCSVUI(AltosUI.this); } + /* Load a flight log CSV file and display a pretty graph. + */ + + private void GraphData() { + new AltosGraphUI(AltosUI.this); + } + /* Create the AltosUI menus */ private void createMenu() { @@ -713,6 +720,14 @@ public class AltosUI extends JFrame { }); menu.add(item); + item = new JMenuItem("Graph Data",KeyEvent.VK_F); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + GraphData(); + } + }); + menu.add(item); + item = new JMenuItem("Quit",KeyEvent.VK_Q); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); @@ -895,4 +910,4 @@ public class AltosUI extends JFrame { altosui.setVisible(true); } } -} \ No newline at end of file +} -- cgit v1.2.3 From af404b428bd742039afc25ff3850f76bc92c7c29 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 15 Sep 2010 07:24:04 +1000 Subject: Add JFreeChart to Makefile.am --- ao-tools/altosui/Makefile.am | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index fa391889..0a91f939 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -5,7 +5,7 @@ man_MANS=altosui.1 altoslibdir=$(libdir)/altos -CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" +CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(JFREECHART)/*:$(FREETTS)/*:/usr/share/java/*" bin_SCRIPTS=altosui @@ -48,8 +48,19 @@ altosui_JAVA = \ AltosTelemetry.java \ AltosTelemetryReader.java \ AltosUI.java \ + AltosCsvReader.java \ + AltosDataPoint.java \ + AltosGraph.java \ + AltosGraphTime.java \ + AltosGraphUI.java \ + AltosGraphDataChooser.java \ AltosVoice.java +JFREECHART_CLASS= \ + jfreechart.jar \ + jcommon.jar \ + csv.jar + FREETTS_CLASS= \ cmudict04.jar \ cmulex.jar \ @@ -82,7 +93,7 @@ LINUX_DIST=Altos-Linux-$(VERSION).tar.bz2 MACOSX_DIST=Altos-Mac-$(VERSION).zip WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe -FAT_FILES=$(FATJAR) $(FREETTS_CLASS) +FAT_FILES=$(FATJAR) $(FREETTS_CLASS) $(JFREECHART_CLASS) LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) LINUX_EXTRA=altosui-fat @@ -97,7 +108,7 @@ all-local: classes/altosui $(JAR) altosui altosui-test clean-local: -rm -rf classes $(JAR) $(FATJAR) \ $(LINUX_DIST) $(MACOSX_DIST) windows $(WINDOWS_DIST) $(FREETTS_CLASS) \ - $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ + $(JFREECHART_CLASS) $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ altosui altosui-test macosx linux fat: $(FATJAR) $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) @@ -143,7 +154,7 @@ $(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) -C classes altosui \ -C ../libaltos libaltosJNI -$(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(LIBALTOS) $(JAVA_ICON) +$(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLASS) $(LIBALTOS) $(JAVA_ICON) jar cfm $@ Manifest-fat.txt \ -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ -C classes altosui \ @@ -151,11 +162,11 @@ $(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(LIBALTOS) $(JA Manifest.txt: Makefile echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTS)/freetts.jar" >> $@ + echo "Class-Path: $(FREETTS)/freetts.jar $(JFREECHART)/jfreechart.jar $(JFREECHAR)/jcommon.jar $(JFREECHART)/csv.jar" >> $@ Manifest-fat.txt: echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: freetts.jar" >> $@ + echo "Class-Path: freetts.jar jfreechart.jar jcommon.jar csv.jar" >> $@ altosui: Makefile echo "#!/bin/sh" > $@ -- cgit v1.2.3 From 7a4d7110debb88f4e906fee7c46f2badd561809d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 19 Sep 2010 02:50:43 -0700 Subject: altosui: Use recorded ground acceleration when reading eeprom files The flight software records 1000 accelerometer samples and records that in the flight log. Use that value instead of using the very few samples recorded in the eeprom before boost is detected. This generates far more accurate accerometer data in the .csv files. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 4cc8536a..03e73812 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -95,7 +95,6 @@ public class AltosEepromReader extends AltosReader { boolean last_reported; double ground_pres; - double ground_accel; int n_pad_samples; @@ -140,9 +139,6 @@ public class AltosEepromReader extends AltosReader { ground_pres += state.pres; state.ground_pres = (int) (ground_pres / n_pad_samples); state.flight_pres = state.ground_pres; - ground_accel += state.accel; - state.ground_accel = (int) (ground_accel / n_pad_samples); - state.flight_accel = state.ground_accel; } else { state.flight_pres = (state.flight_pres * 15 + state.pres) / 16; state.flight_accel = (state.flight_accel * 15 + state.accel) / 16; @@ -345,6 +341,7 @@ public class AltosEepromReader extends AltosReader { tick = record.tick; if (record.cmd == Altos.AO_LOG_FLIGHT) { state.ground_accel = record.a; + state.flight_accel = record.a; state.flight = record.b; boost_tick = tick; seen |= seen_flight; -- cgit v1.2.3 From 1260589976c1a95848b298497fd251c4ee7d3f93 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 19 Sep 2010 02:52:29 -0700 Subject: altosui: Write raw sensor data to .csv files For data export, provide the raw sensor samples instead of the filtered values. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 6 +++--- ao-tools/altosui/AltosRecord.java | 22 +++++++++++++++++----- ao-tools/altosui/AltosState.java | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index 07fa371f..f7b3c03c 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -111,9 +111,9 @@ public class AltosCSV { void write_basic(AltosRecord record) { 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(), + record.raw_pressure(), + record.raw_altitude(), + record.raw_height(), record.accel_speed(), state.baro_speed, record.temperature(), diff --git a/ao-tools/altosui/AltosRecord.java b/ao-tools/altosui/AltosRecord.java index b670ee37..18c6079d 100644 --- a/ao-tools/altosui/AltosRecord.java +++ b/ao-tools/altosui/AltosRecord.java @@ -73,7 +73,11 @@ public class AltosRecord { return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; } - public double pressure() { + public double raw_pressure() { + return barometer_to_pressure(pres); + } + + public double filtered_pressure() { return barometer_to_pressure(flight_pres); } @@ -81,16 +85,24 @@ public class AltosRecord { return barometer_to_pressure(ground_pres); } - public double altitude() { - return AltosConvert.pressure_to_altitude(pressure()); + public double filtered_altitude() { + return AltosConvert.pressure_to_altitude(filtered_pressure()); + } + + public double raw_altitude() { + return AltosConvert.pressure_to_altitude(raw_pressure()); } public double ground_altitude() { return AltosConvert.pressure_to_altitude(ground_pressure()); } - public double height() { - return altitude() - ground_altitude(); + public double filtered_height() { + return filtered_altitude() - ground_altitude(); + } + + public double raw_height() { + return raw_altitude() - ground_altitude(); } public double battery_voltage() { diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index 3ef00f35..90e73f5e 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -80,7 +80,7 @@ public class AltosState { data = cur; ground_altitude = data.ground_altitude(); - height = data.altitude() - ground_altitude; + height = data.filtered_altitude() - ground_altitude; report_time = System.currentTimeMillis(); -- cgit v1.2.3 From fd010661ced6075f82a961625826665a3d8d1efe Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 14:00:04 -0700 Subject: altosui: Factor some UI elements into separate classes Clean up AltosUI by moving the two main tables to separate class files. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosInfoTable.java | 221 +++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosStatusTable.java | 73 +++++++++++ ao-tools/altosui/AltosUI.java | 192 +++------------------------- ao-tools/altosui/Makefile-standalone | 2 + ao-tools/altosui/Makefile.am | 7 +- 5 files changed, 315 insertions(+), 180 deletions(-) create mode 100644 ao-tools/altosui/AltosInfoTable.java create mode 100644 ao-tools/altosui/AltosStatusTable.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosInfoTable.java b/ao-tools/altosui/AltosInfoTable.java new file mode 100644 index 00000000..9964ab10 --- /dev/null +++ b/ao-tools/altosui/AltosInfoTable.java @@ -0,0 +1,221 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosFlightInfoTableModel; +import altosui.AltosState; + +public class AltosInfoTable { + private Box box; + private JTable table[]; + private AltosFlightInfoTableModel model[]; + private Box ibox[]; + + private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14); + private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14); + + static final int info_columns = 3; + static final int info_rows = 17; + + public AltosInfoTable() { + box = Box.createHorizontalBox(); + model = new AltosFlightInfoTableModel[info_columns]; + table = new JTable[info_columns]; + ibox = new Box[info_columns]; + for (int i = 0; i < info_columns; i++) { + model[i] = new AltosFlightInfoTableModel(); + table[i] = new JTable(model[i]); + ibox[i] = box.createVerticalBox(); + + table[i].setFont(infoValueFont); + table[i].setRowHeight(rowHeight()); + table[i].setShowGrid(true); + ibox[i].add(table[i].getTableHeader()); + ibox[i].add(table[i]); + box.add(ibox[i]); + } + } + + public int rowHeight() { + FontMetrics infoValueMetrics = table[0].getFontMetrics(infoValueFont); + return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 20 / 10; + } + + public int columnWidth() { + FontMetrics infoValueMetrics = table[0].getFontMetrics(infoValueFont); + return infoValueMetrics.charWidth('0') * 20 * 2; + } + + public int height() { + return rowHeight() * info_rows; + } + + public int width() { + return columnWidth() * info_columns; + } + + public Box box() { + return box; + } + + void info_reset() { + for (int i = 0; i < info_columns; i++) + model[i].resetRow(); + } + + void info_add_row(int col, String name, String value) { + model[col].addRow(name, value); + } + + void info_add_row(int col, String name, String format, Object... parameters) { + model[col].addRow(name, String.format(format, parameters)); + } + + void info_add_deg(int col, String name, double v, int pos, int neg) { + int c = pos; + if (v < 0) { + c = neg; + v = -v; + } + double deg = Math.floor(v); + double min = (v - deg) * 60; + + model[col].addRow(name, String.format("%3.0f°%08.5f'", deg, min)); + } + + void info_finish() { + for (int i = 0; i < info_columns; i++) + model[i].finish(); + } + + public void clear() { + info_reset(); + info_finish(); + } + + public void show(AltosState state, int crc_errors) { + if (state == null) + return; + info_reset(); + info_add_row(0, "Rocket state", "%s", state.data.state()); + info_add_row(0, "Callsign", "%s", state.data.callsign); + info_add_row(0, "Rocket serial", "%6d", state.data.serial); + info_add_row(0, "Rocket flight", "%6d", state.data.flight); + + info_add_row(0, "RSSI", "%6d dBm", state.data.rssi); + info_add_row(0, "CRC Errors", "%6d", crc_errors); + info_add_row(0, "Height", "%6.0f m", state.height); + info_add_row(0, "Max height", "%6.0f m", state.max_height); + info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration); + info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration); + info_add_row(0, "Speed", "%8.1f m/s", state.ascent ? state.speed : state.baro_speed); + info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed); + info_add_row(0, "Temperature", "%9.2f °C", state.temperature); + info_add_row(0, "Battery", "%9.2f V", state.battery); + info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense); + info_add_row(0, "Main", "%9.2f V", state.main_sense); + info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude); + if (state.gps == null) { + info_add_row(1, "GPS", "not available"); + } else { + if (state.gps_ready) + info_add_row(1, "GPS state", "%s", "ready"); + else + info_add_row(1, "GPS state", "wait (%d)", + state.gps_waiting); + if (state.data.gps.locked) + info_add_row(1, "GPS", " locked"); + else if (state.data.gps.connected) + 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); + + /* The SkyTraq GPS doesn't report these values */ + if (false) { + info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°", + state.gps.ground_speed, + state.gps.course); + info_add_row(1, "GPS climb rate", "%8.1f m/s", + state.gps.climb_rate); + info_add_row(1, "GPS error", "%6d m(h)%3d m(v)", + state.gps.h_error, state.gps.v_error); + } + info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop); + + if (state.npad > 0) { + if (state.from_pad != null) { + info_add_row(1, "Distance from pad", "%6d m", + (int) (state.from_pad.distance + 0.5)); + info_add_row(1, "Direction from pad", "%6d°", + (int) (state.from_pad.bearing + 0.5)); + info_add_row(1, "Elevation from pad", "%6d°", + (int) (state.elevation + 0.5)); + info_add_row(1, "Range from pad", "%6d m", + (int) (state.range + 0.5)); + } else { + info_add_row(1, "Distance from pad", "unknown"); + info_add_row(1, "Direction from pad", "unknown"); + info_add_row(1, "Elevation from pad", "unknown"); + info_add_row(1, "Range from pad", "unknown"); + } + info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); + 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); + int nsat_vis = 0; + int c; + + if (state.gps.cc_gps_sat == null) + info_add_row(2, "Satellites Visible", "%4d", 0); + else { + info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length); + for (c = 0; c < state.gps.cc_gps_sat.length; c++) { + info_add_row(2, "Satellite id,C/N0", + "%4d, %4d", + state.gps.cc_gps_sat[c].svid, + state.gps.cc_gps_sat[c].c_n0); + } + } + } + info_finish(); + } +} diff --git a/ao-tools/altosui/AltosStatusTable.java b/ao-tools/altosui/AltosStatusTable.java new file mode 100644 index 00000000..3965a57d --- /dev/null +++ b/ao-tools/altosui/AltosStatusTable.java @@ -0,0 +1,73 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosFlightStatusTableModel; +import altosui.AltosFlightInfoTableModel; + +public class AltosStatusTable extends JTable { + private AltosFlightStatusTableModel flightStatusModel; + + JFrame frame; + + private Font statusFont = new Font("SansSerif", Font.BOLD, 24); + + public AltosStatusTable(JFrame in_frame) { + super((TableModel) new AltosFlightStatusTableModel()); + flightStatusModel = (AltosFlightStatusTableModel) getModel(); + frame = in_frame; + + setFont(statusFont); + + TableColumnModel tcm = getColumnModel(); + + for (int i = 0; i < flightStatusModel.getColumnCount(); i++) { + DefaultTableCellRenderer r = new DefaultTableCellRenderer(); + r.setFont(statusFont); + r.setHorizontalAlignment(SwingConstants.CENTER); + tcm.getColumn(i).setCellRenderer(r); + } + + setRowHeight(rowHeight()); + setShowGrid(false); + } + + public int rowHeight() { + FontMetrics statusMetrics = getFontMetrics(statusFont); + return (statusMetrics.getHeight() + statusMetrics.getLeading()) * 15 / 10; + } + + public int height() { + return rowHeight * 4; + } + + public void set(AltosState state) { + flightStatusModel.set(state); + } +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index edee146d..456031ec 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -38,31 +38,25 @@ import altosui.AltosDeviceDialog; import altosui.AltosPreferences; import altosui.AltosLog; import altosui.AltosVoice; -import altosui.AltosFlightStatusTableModel; import altosui.AltosFlightInfoTableModel; import altosui.AltosChannelMenu; import altosui.AltosFlashUI; import altosui.AltosLogfileChooser; import altosui.AltosCSVUI; import altosui.AltosLine; +import altosui.AltosStatusTable; +import altosui.AltosInfoTable; import libaltosJNI.*; public class AltosUI extends JFrame { private int channel = -1; - private AltosFlightStatusTableModel flightStatusModel; - private JTable flightStatus; - - static final int info_columns = 3; - - private AltosFlightInfoTableModel[] flightInfoModel; - private JTable[] flightInfo; + private AltosStatusTable flightStatus; + private AltosInfoTable flightInfo; private AltosSerial serial_line; private AltosLog altos_log; - private Box[] ibox; private Box vbox; - private Box hbox; private Font statusFont = new Font("SansSerif", Font.BOLD, 24); private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14); @@ -98,44 +92,12 @@ public class AltosUI extends JFrame { vbox = Box.createVerticalBox(); this.add(vbox); - flightStatusModel = new AltosFlightStatusTableModel(); - flightStatus = new JTable(flightStatusModel); - flightStatus.setFont(statusFont); - TableColumnModel tcm = flightStatus.getColumnModel(); - for (int i = 0; i < flightStatusModel.getColumnCount(); i++) { - DefaultTableCellRenderer r = new DefaultTableCellRenderer(); - r.setFont(statusFont); - r.setHorizontalAlignment(SwingConstants.CENTER); - tcm.getColumn(i).setCellRenderer(r); - } - - FontMetrics statusMetrics = flightStatus.getFontMetrics(statusFont); - int statusHeight = (statusMetrics.getHeight() + statusMetrics.getLeading()) * 15 / 10; - flightStatus.setRowHeight(statusHeight); - flightStatus.setShowGrid(false); + flightStatus = new AltosStatusTable(this); vbox.add(flightStatus); - hbox = Box.createHorizontalBox(); - vbox.add(hbox); - - flightInfo = new JTable[3]; - flightInfoModel = new AltosFlightInfoTableModel[3]; - ibox = new Box[3]; - FontMetrics infoValueMetrics = flightStatus.getFontMetrics(infoValueFont); - int infoHeight = (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 20 / 10; - - for (int i = 0; i < info_columns; i++) { - ibox[i] = Box.createVerticalBox(); - flightInfoModel[i] = new AltosFlightInfoTableModel(); - flightInfo[i] = new JTable(flightInfoModel[i]); - flightInfo[i].setFont(infoValueFont); - flightInfo[i].setRowHeight(infoHeight); - flightInfo[i].setShowGrid(true); - ibox[i].add(flightInfo[i].getTableHeader()); - ibox[i].add(flightInfo[i]); - hbox.add(ibox[i]); - } + flightInfo = new AltosInfoTable(); + vbox.add(flightInfo.box()); setTitle("AltOS"); @@ -144,8 +106,8 @@ public class AltosUI extends JFrame { serial_line = new AltosSerial(); altos_log = new AltosLog(serial_line); int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); - this.setSize(new Dimension (infoValueMetrics.charWidth('0') * 6 * 20, - statusHeight * 4 + infoHeight * 17)); + this.setSize(new Dimension (flightInfo.width(), + flightStatus.height() + flightInfo.height())); this.validate(); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @@ -157,136 +119,11 @@ public class AltosUI extends JFrame { voice.speak("Rocket flight monitor ready."); } - public void info_reset() { - for (int i = 0; i < info_columns; i++) - flightInfoModel[i].resetRow(); - } - - public void info_add_row(int col, String name, String value) { - flightInfoModel[col].addRow(name, value); - } - - public void info_add_row(int col, String name, String format, Object... parameters) { - flightInfoModel[col].addRow(name, String.format(format, parameters)); - } - - public void info_add_deg(int col, String name, double v, int pos, int neg) { - int c = pos; - if (v < 0) { - c = neg; - v = -v; - } - double deg = Math.floor(v); - double min = (v - deg) * 60; - - flightInfoModel[col].addRow(name, String.format("%3.0f°%08.5f'", deg, min)); - } - - public void info_finish() { - for (int i = 0; i < info_columns; i++) - flightInfoModel[i].finish(); - } - - public void show(AltosState state, int crc_errors) { - if (state == null) - return; - flightStatusModel.set(state); - - info_reset(); - info_add_row(0, "Rocket state", "%s", state.data.state()); - info_add_row(0, "Callsign", "%s", state.data.callsign); - info_add_row(0, "Rocket serial", "%6d", state.data.serial); - info_add_row(0, "Rocket flight", "%6d", state.data.flight); - - info_add_row(0, "RSSI", "%6d dBm", state.data.rssi); - info_add_row(0, "CRC Errors", "%6d", crc_errors); - info_add_row(0, "Height", "%6.0f m", state.height); - info_add_row(0, "Max height", "%6.0f m", state.max_height); - info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration); - info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration); - info_add_row(0, "Speed", "%8.1f m/s", state.ascent ? state.speed : state.baro_speed); - info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed); - info_add_row(0, "Temperature", "%9.2f °C", state.temperature); - info_add_row(0, "Battery", "%9.2f V", state.battery); - info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense); - info_add_row(0, "Main", "%9.2f V", state.main_sense); - info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude); - if (state.gps == null) { - info_add_row(1, "GPS", "not available"); - } else { - if (state.gps_ready) - info_add_row(1, "GPS state", "%s", "ready"); - else - info_add_row(1, "GPS state", "wait (%d)", - state.gps_waiting); - if (state.data.gps.locked) - info_add_row(1, "GPS", " locked"); - else if (state.data.gps.connected) - 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); - - /* The SkyTraq GPS doesn't report these values */ - if (false) { - info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°", - state.gps.ground_speed, - state.gps.course); - info_add_row(1, "GPS climb rate", "%8.1f m/s", - state.gps.climb_rate); - info_add_row(1, "GPS error", "%6d m(h)%3d m(v)", - state.gps.h_error, state.gps.v_error); - } - info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop); - - if (state.npad > 0) { - if (state.from_pad != null) { - info_add_row(1, "Distance from pad", "%6d m", - (int) (state.from_pad.distance + 0.5)); - info_add_row(1, "Direction from pad", "%6d°", - (int) (state.from_pad.bearing + 0.5)); - info_add_row(1, "Elevation from pad", "%6d°", - (int) (state.elevation + 0.5)); - info_add_row(1, "Range from pad", "%6d m", - (int) (state.range + 0.5)); - } else { - info_add_row(1, "Distance from pad", "unknown"); - info_add_row(1, "Direction from pad", "unknown"); - info_add_row(1, "Elevation from pad", "unknown"); - info_add_row(1, "Range from pad", "unknown"); - } - info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); - 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); - int nsat_vis = 0; - int c; - - if (state.gps.cc_gps_sat == null) - info_add_row(2, "Satellites Visible", "%4d", 0); - else { - info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length); - for (c = 0; c < state.gps.cc_gps_sat.length; c++) { - info_add_row(2, "Satellite id,C/N0", - "%4d, %4d", - state.gps.cc_gps_sat[c].svid, - state.gps.cc_gps_sat[c].c_n0); - } - } + void show(AltosState state, int crc_errors) { + if (state != null) { + flightStatus.set(state); + flightInfo.show(state, crc_errors); } - info_finish(); } class IdleThread extends Thread { @@ -455,8 +292,7 @@ public class AltosUI extends JFrame { idle_thread = new IdleThread(); - info_reset(); - info_finish(); + flightInfo.clear(); try { for (;;) { try { diff --git a/ao-tools/altosui/Makefile-standalone b/ao-tools/altosui/Makefile-standalone index 90621f36..a95a5aa8 100644 --- a/ao-tools/altosui/Makefile-standalone +++ b/ao-tools/altosui/Makefile-standalone @@ -24,6 +24,7 @@ CLASSFILES=\ AltosGreatCircle.class \ AltosHexfile.class \ AltosLine.class \ + AltosInfoTable.class \ AltosLog.class \ AltosLogfileChooser.class \ AltosParse.class \ @@ -33,6 +34,7 @@ CLASSFILES=\ AltosSerialMonitor.class \ AltosSerial.class \ AltosState.class \ + AltosStatusTable.class \ AltosTelemetry.class \ AltosTelemetryReader.class \ AltosUI.class \ diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index fa391889..56ac0520 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -33,6 +33,7 @@ altosui_JAVA = \ AltosGreatCircle.java \ AltosHexfile.java \ Altos.java \ + AltosInfoTable.java \ AltosLine.java \ AltosLogfileChooser.java \ AltosLog.java \ @@ -45,6 +46,7 @@ altosui_JAVA = \ AltosSerial.java \ AltosSerialMonitor.java \ AltosState.java \ + AltosStatusTable.java \ AltosTelemetry.java \ AltosTelemetryReader.java \ AltosUI.java \ @@ -100,8 +102,6 @@ clean-local: $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ altosui altosui-test macosx linux -fat: $(FATJAR) $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) - if FATINSTALL FATTARGET=$(FATDIR)/$(VERSION) @@ -124,8 +124,11 @@ $(WINDOWS_DIST_TARGET): $(WINDOWS_DIST) mkdir -p $(FATTARGET) cp -p $< $@ +else +fat: $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) endif + altosuidir=$(datadir)/java install-altosuiJAVA: altosui.jar -- cgit v1.2.3 From 34ca8c00f4be72c314baff4c96f1e2f010948454 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 20 Sep 2010 06:30:49 -0700 Subject: altosui: remove unused ReplayThread wrapper classes These aren't used now that the replay opener dialog knows how to build a reader from a filename. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 456031ec..1adeeccf 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -445,19 +445,6 @@ public class AltosUI extends JFrame { } } - class ReplayTelemetryThread extends ReplayThread { - ReplayTelemetryThread(FileInputStream in, String in_name) { - super(new AltosTelemetryReader(in), in_name); - } - - } - - class ReplayEepromThread extends ReplayThread { - ReplayEepromThread(FileInputStream in, String in_name) { - super(new AltosEepromReader(in), in_name); - } - } - Thread display_thread; private void stop_display() { -- cgit v1.2.3 From e66919aa46193bd8c7a1e86fb32a3367dae121f5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 23 Sep 2010 16:52:51 -0700 Subject: altosui: Require 4 sats for 'good' GPS data Wait for 10 consecutive GPS reports with at least 4 sats before reporting "GPS ready" state. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosState.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index 90e73f5e..1048bb51 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -60,6 +60,7 @@ public class AltosState { static final int MIN_PAD_SAMPLES = 10; int npad; + int ngps; int gps_waiting; boolean gps_ready; @@ -97,6 +98,7 @@ public class AltosState { /* Preserve any existing gps data */ npad = prev_state.npad; + ngps = prev_state.ngps; gps = prev_state.gps; pad_lat = prev_state.pad_lat; pad_lon = prev_state.pad_lon; @@ -120,15 +122,23 @@ public class AltosState { baro_speed = prev_state.baro_speed; } else { npad = 0; + ngps = 0; gps = null; baro_speed = 0; time_change = 0; } if (state == Altos.ao_flight_pad) { - if (data.gps != null && data.gps.locked) { + + /* Track consecutive 'good' gps reports, waiting for 10 of them */ + if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) npad++; - if (npad > 1) { + else + npad = 0; + + /* Average GPS data while on the pad */ + if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) { + if (ngps > 1) { /* 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; @@ -138,8 +148,7 @@ public class AltosState { pad_lon = data.gps.lon; pad_alt = data.gps.alt; } - } else { - npad = 0; + ngps++; } } @@ -163,13 +172,13 @@ public class AltosState { if (data.gps != null) { if (gps == null || !gps.locked || data.gps.locked) gps = data.gps; - if (npad > 0 && gps.locked) { + if (ngps > 0 && gps.locked) { from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); } } elevation = 0; range = -1; - if (npad > 0) { + if (ngps > 0) { gps_height = gps.alt - pad_alt; if (from_pad != null) { elevation = Math.atan2(height, from_pad.distance) * 180 / Math.PI; -- cgit v1.2.3 From c89a34d1eb25155405b0036baeadc7bbfeade1c2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 27 Sep 2010 17:11:48 -0700 Subject: altosui: Create iterables for log file scanning. Split out display threads Convert from log file reading paradigm to using iterators which is more idiomatic for java. Split more code out of AltosUI.java, including the display update threads for telemetry monitoring and logfile replay.x Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 20 +- ao-tools/altosui/AltosCSVUI.java | 15 +- ao-tools/altosui/AltosDisplayThread.java | 255 ++++++++++++++++ ao-tools/altosui/AltosEepromIterable.java | 419 +++++++++++++++++++++++++++ ao-tools/altosui/AltosEepromReader.java | 406 -------------------------- ao-tools/altosui/AltosLogfileChooser.java | 11 +- ao-tools/altosui/AltosRecord.java | 2 +- ao-tools/altosui/AltosRecordIterable.java | 42 +++ ao-tools/altosui/AltosReplayThread.java | 83 ++++++ ao-tools/altosui/AltosTelemetryIterable.java | 83 ++++++ ao-tools/altosui/AltosTelemetryReader.java | 88 ------ ao-tools/altosui/AltosUI.java | 282 ++---------------- ao-tools/altosui/Makefile.am | 7 +- 13 files changed, 920 insertions(+), 793 deletions(-) create mode 100644 ao-tools/altosui/AltosDisplayThread.java create mode 100644 ao-tools/altosui/AltosEepromIterable.java delete mode 100644 ao-tools/altosui/AltosEepromReader.java create mode 100644 ao-tools/altosui/AltosRecordIterable.java create mode 100644 ao-tools/altosui/AltosReplayThread.java create mode 100644 ao-tools/altosui/AltosTelemetryIterable.java delete mode 100644 ao-tools/altosui/AltosTelemetryReader.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index f7b3c03c..7f14adad 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -207,22 +207,10 @@ public class AltosCSV { out.close(); } - public void write(AltosReader reader) { - AltosRecord record; - - reader.write_comments(out()); - try { - for (;;) { - record = reader.read(); - if (record == null) - break; - write(record); - } - } catch (IOException ie) { - System.out.printf("IOException\n"); - } catch (ParseException pe) { - System.out.printf("ParseException %s\n", pe.getMessage()); - } + public void write(AltosRecordIterable iterable) { + iterable.write_comments(out()); + for (AltosRecord r : iterable) + write(r); } public AltosCSV(File in_name) throws FileNotFoundException { diff --git a/ao-tools/altosui/AltosCSVUI.java b/ao-tools/altosui/AltosCSVUI.java index 643d4112..4eb72de8 100644 --- a/ao-tools/altosui/AltosCSVUI.java +++ b/ao-tools/altosui/AltosCSVUI.java @@ -35,17 +35,17 @@ public class AltosCSVUI extends JDialog implements Runnable, ActionListener { - JFrame frame; - Thread thread; - AltosReader reader; - AltosCSV writer; + JFrame frame; + Thread thread; + AltosRecordIterable iterable; + AltosCSV writer; public void run() { AltosLogfileChooser chooser; chooser = new AltosLogfileChooser(frame); - reader = chooser.runDialog(); - if (reader == null) + iterable = chooser.runDialog(); + if (iterable == null) return; JFileChooser csv_chooser; @@ -67,8 +67,7 @@ public class AltosCSVUI "Cannot open file", JOptionPane.ERROR_MESSAGE); } - writer.write(reader); - reader.close(); + writer.write(iterable); writer.close(); } } diff --git a/ao-tools/altosui/AltosDisplayThread.java b/ao-tools/altosui/AltosDisplayThread.java new file mode 100644 index 00000000..9cc3d5ce --- /dev/null +++ b/ao-tools/altosui/AltosDisplayThread.java @@ -0,0 +1,255 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosDisplayThread extends Thread { + + Frame parent; + IdleThread idle_thread; + AltosVoice voice; + String name; + int crc_errors; + AltosStatusTable flightStatus; + AltosInfoTable flightInfo; + + 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 < Altos.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 (Altos.ao_flight_drogue <= state.state && + state.state < Altos.ao_flight_landed && + state.range >= 0) + { + voice.speak("Height %d, bearing %d, elevation %d, range %d.\n", + (int) (state.height + 0.5), + (int) (state.from_pad.bearing + 0.5), + (int) (state.elevation + 0.5), + (int) (state.range + 0.5)); + } else if (state.state > Altos.ao_flight_pad) { + voice.speak("%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 >= Altos.ao_flight_drogue && + (last || + System.currentTimeMillis() - state.report_time >= 15000 || + state.state == Altos.ao_flight_landed)) + { + if (Math.abs(state.baro_speed) < 20 && state.height < 100) + voice.speak("rocket landed safely"); + else + voice.speak("rocket may have crashed"); + if (state.from_pad != null) + voice.speak("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 () { + + reported_landing = 0; + state = null; + report_interval = 10000; + try { + for (;;) { + set_report_time(); + for (;;) { + voice.drain(); + synchronized (this) { + long sleep_time = report_time - now(); + if (sleep_time <= 0) + break; + wait(sleep_time); + } + } + report(false); + } + } catch (InterruptedException ie) { + try { + voice.drain(); + } catch (InterruptedException iie) { } + } + } + + public synchronized void notice(AltosState new_state, boolean spoken) { + AltosState old_state = state; + state = new_state; + if (!started && state.state > Altos.ao_flight_pad) { + started = true; + start(); + } + + if (state.state < Altos.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(); + } + } + + void init() { } + + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } + + void close(boolean interrupted) { } + + void update(AltosState state) throws InterruptedException { } + + boolean tell(AltosState state, AltosState old_state) { + boolean ret = false; + if (old_state == null || old_state.state != state.state) { + voice.speak(state.data.state()); + if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && + state.state > Altos.ao_flight_boost) { + voice.speak("max speed: %d meters per second.", + (int) (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: %d meters.", + (int) (state.max_height + 0.5)); + ret = true; + } + } + if (old_state == null || old_state.gps_ready != state.gps_ready) { + if (state.gps_ready) { + voice.speak("GPS ready"); + ret = true; + } + else if (old_state != null) { + voice.speak("GPS lost"); + ret = true; + } + } + old_state = state; + return ret; + } + + void show(AltosState state, int crc_errors) { + if (state != null) { + flightStatus.set(state); + flightInfo.show(state, crc_errors); + } + } + + public void run() { + boolean interrupted = false; + String line; + AltosState state = null; + AltosState old_state = null; + boolean told; + + idle_thread = new IdleThread(); + + flightInfo.clear(); + try { + for (;;) { + try { + AltosRecord record = read(); + if (record == null) + break; + old_state = state; + state = new AltosState(record, state); + update(state); + show(state, crc_errors); + told = tell(state, old_state); + idle_thread.notice(state, told); + } catch (ParseException pp) { + System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); + } catch (AltosCRCException ce) { + ++crc_errors; + show(state, crc_errors); + } + } + } catch (InterruptedException ee) { + interrupted = true; + } catch (IOException ie) { + JOptionPane.showMessageDialog(parent, + String.format("Error reading from \"%s\"", name), + "Telemetry Read Error", + JOptionPane.ERROR_MESSAGE); + } finally { + close(interrupted); + idle_thread.interrupt(); + try { + idle_thread.join(); + } catch (InterruptedException ie) {} + } + } + + public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosStatusTable in_status, AltosInfoTable in_info) { + parent = in_parent; + voice = in_voice; + flightStatus = in_status; + flightInfo = in_info; + } + + public void report() { + if (idle_thread != null) + idle_thread.report(true); + } + +} diff --git a/ao-tools/altosui/AltosEepromIterable.java b/ao-tools/altosui/AltosEepromIterable.java new file mode 100644 index 00000000..d4ac3f3e --- /dev/null +++ b/ao-tools/altosui/AltosEepromIterable.java @@ -0,0 +1,419 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosRecord; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosEepromMonitor; + +/* + * 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 { + + public int index; + + public AltosOrderedRecord(String line, int in_index, int prev_tick) + throws ParseException { + super(line); + int new_tick = tick | (prev_tick & ~0xffff); + if (new_tick < prev_tick) { + if (prev_tick - new_tick > 0x8000) + new_tick += 0x10000; + } + tick = new_tick; + 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 int compareTo(AltosOrderedRecord o) { + int tick_diff = tick - o.tick; + if (tick_diff != 0) + return tick_diff; + return index - o.index; + } +} + +public class AltosEepromIterable 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|seen_temp_volt|seen_deploy; + + AltosEepromRecord flight_record; + AltosEepromRecord gps_date_record; + + TreeSet records; + + LinkedList list; + + class EepromState { + int seen; + int n_pad_samples; + double ground_pres; + int gps_tick; + int boost_tick; + + EepromState() { + seen = 0; + n_pad_samples = 0; + ground_pres = 0.0; + gps_tick = 0; + } + } + + void update_state(AltosRecord state, AltosEepromRecord record, EepromState eeprom) { + state.tick = record.tick; + switch (record.cmd) { + case Altos.AO_LOG_FLIGHT: + eeprom.seen |= seen_flight; + state.ground_accel = record.a; + state.flight_accel = record.a; + state.flight = record.b; + eeprom.boost_tick = record.tick; + break; + case Altos.AO_LOG_SENSOR: + state.accel = record.a; + state.pres = record.b; + if (state.state < Altos.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; + state.flight_vel += (state.accel_plus_g - state.accel); + } + eeprom.seen |= seen_sensor; + break; + case Altos.AO_LOG_TEMP_VOLT: + state.temp = record.a; + state.batt = record.b; + eeprom.seen |= seen_temp_volt; + break; + case Altos.AO_LOG_DEPLOY: + state.drogue = record.a; + state.main = record.b; + eeprom.seen |= seen_deploy; + break; + case Altos.AO_LOG_STATE: + state.state = record.a; + break; + case Altos.AO_LOG_GPS_TIME: + eeprom.gps_tick = state.tick; + AltosGPS old = state.gps; + state.gps = new AltosGPS(); + + /* 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); + + int flags = (record.b >> 8); + state.gps.connected = (flags & Altos.AO_GPS_RUNNING) != 0; + state.gps.locked = (flags & Altos.AO_GPS_VALID) != 0; + state.gps.date_valid = (flags & Altos.AO_GPS_DATE_VALID) != 0; + state.gps.nsat = (flags & Altos.AO_GPS_NUM_SAT_MASK) >> + Altos.AO_GPS_NUM_SAT_SHIFT; + break; + case Altos.AO_LOG_GPS_LAT: + int lat32 = record.a | (record.b << 16); + state.gps.lat = (double) lat32 / 1e7; + break; + case Altos.AO_LOG_GPS_LON: + int lon32 = record.a | (record.b << 16); + state.gps.lon = (double) lon32 / 1e7; + break; + case Altos.AO_LOG_GPS_ALT: + state.gps.alt = record.a; + break; + case Altos.AO_LOG_GPS_SAT: + if (state.tick == eeprom.gps_tick) { + int svid = record.a; + int c_n0 = record.b >> 8; + state.gps.add_sat(svid, c_n0); + } + break; + case Altos.AO_LOG_GPS_DATE: + state.gps.year = (record.a & 0xff) + 2000; + state.gps.month = record.a >> 8; + state.gps.day = record.b & 0xff; + break; + + case Altos.AO_LOG_CONFIG_VERSION: + break; + case Altos.AO_LOG_MAIN_DEPLOY: + break; + case Altos.AO_LOG_APOGEE_DELAY: + break; + case Altos.AO_LOG_RADIO_CHANNEL: + break; + case Altos.AO_LOG_CALLSIGN: + state.callsign = record.data; + break; + case Altos.AO_LOG_ACCEL_CAL: + state.accel_plus_g = record.a; + state.accel_minus_g = record.b; + break; + case Altos.AO_LOG_RADIO_CAL: + break; + case Altos.AO_LOG_MANUFACTURER: + break; + case Altos.AO_LOG_PRODUCT: + break; + case Altos.AO_LOG_SERIAL_NUMBER: + state.serial = record.a; + break; + case Altos.AO_LOG_SOFTWARE_VERSION: + break; + } + } + + LinkedList make_list() { + LinkedList list = new LinkedList(); + Iterator iterator = records.iterator(); + AltosOrderedRecord record = null; + AltosRecord state = new AltosRecord(); + boolean last_reported = false; + EepromState eeprom = new EepromState(); + + state.state = Altos.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) { + AltosRecord r = new AltosRecord(state); + r.time = (r.tick - eeprom.boost_tick) / 100.0; + list.add(r); + } + update_state(state, record, eeprom); + } + AltosRecord r = new AltosRecord(state); + r.time = (r.tick - eeprom.boost_tick) / 100.0; + list.add(r); + return list; + } + + public Iterator iterator() { + if (list == null) + list = make_list(); + return list.iterator(); + } + + public void write_comments(PrintStream out) { + Iterator iterator = records.iterator(); + out.printf("# Comments\n"); + while (iterator.hasNext()) { + AltosOrderedRecord record = iterator.next(); + switch (record.cmd) { + case Altos.AO_LOG_CONFIG_VERSION: + out.printf("# Config version: %s\n", record.data); + break; + case Altos.AO_LOG_MAIN_DEPLOY: + out.printf("# Main deploy: %s\n", record.a); + break; + case Altos.AO_LOG_APOGEE_DELAY: + out.printf("# Apogee delay: %s\n", record.a); + break; + case Altos.AO_LOG_RADIO_CHANNEL: + out.printf("# Radio channel: %s\n", record.a); + break; + case Altos.AO_LOG_CALLSIGN: + out.printf("# Callsign: %s\n", record.data); + break; + case Altos.AO_LOG_ACCEL_CAL: + out.printf ("# Accel cal: %d %d\n", record.a, record.b); + break; + case Altos.AO_LOG_RADIO_CAL: + out.printf ("# Radio cal: %d\n", record.a); + break; + case Altos.AO_LOG_MANUFACTURER: + out.printf ("# Manufacturer: %s\n", record.data); + break; + case Altos.AO_LOG_PRODUCT: + out.printf ("# Product: %s\n", record.data); + break; + case Altos.AO_LOG_SERIAL_NUMBER: + out.printf ("# Serial number: %d\n", record.a); + break; + case Altos.AO_LOG_SOFTWARE_VERSION: + out.printf ("# Software version: %s\n", record.data); + break; + } + } + } + + /* + * 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; + + 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); + } + + /* + * 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 last_gps_time = null; + + int index = 0; + int prev_tick = 0; + + boolean missing_time = false; + + try { + for (;;) { + String line = AltosRecord.gets(input); + if (line == null) + break; + AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick); + if (record == null) + break; + if (record.cmd == Altos.AO_LOG_INVALID) + continue; + prev_tick = record.tick; + if (record.cmd == Altos.AO_LOG_FLIGHT) { + flight_record = record; + continue; + } + + /* 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 == Altos.AO_LOG_GPS_DATE) { + gps_date_record = record; + continue; + } + + /* go back and fix up any missing time values */ + if (record.cmd == Altos.AO_LOG_GPS_TIME) { + last_gps_time = record; + if (missing_time) { + Iterator iterator = records.iterator(); + while (iterator.hasNext()) { + AltosOrderedRecord old = iterator.next(); + if (old.cmd == Altos.AO_LOG_GPS_TIME && + old.a == -1 && old.b == -1) + { + update_time(record, old); + } + } + missing_time = false; + } + } + + if (record.cmd == Altos.AO_LOG_GPS_LAT) { + if (last_gps_time == null || last_gps_time.tick != record.tick) { + AltosOrderedRecord add_gps_time = new AltosOrderedRecord(Altos.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; + + records.add(add_gps_time); + record.index = index++; + } + } + records.add(record); + + /* Bail after reading the 'landed' record; we're all done */ + if (record.cmd == Altos.AO_LOG_STATE && + record.a == Altos.ao_flight_landed) + break; + } + } catch (IOException io) { + } catch (ParseException pe) { + } + try { + input.close(); + } catch (IOException ie) { + } + } +} diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java deleted file mode 100644 index 03e73812..00000000 --- a/ao-tools/altosui/AltosEepromReader.java +++ /dev/null @@ -1,406 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -import altosui.AltosRecord; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosEepromMonitor; - -/* - * 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 { - - public int index; - - public AltosOrderedRecord(String line, int in_index, int prev_tick) - throws ParseException { - super(line); - int new_tick = tick | (prev_tick & ~0xffff); - if (new_tick < prev_tick) { - if (prev_tick - new_tick > 0x8000) - new_tick += 0x10000; - } - tick = new_tick; - 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 int compareTo(AltosOrderedRecord o) { - int tick_diff = tick - o.tick; - if (tick_diff != 0) - return tick_diff; - return index - o.index; - } -} - -public class AltosEepromReader extends AltosReader { - - 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|seen_temp_volt|seen_deploy; - - AltosRecord state; - AltosOrderedRecord record; - - TreeSet records; - - Iterator record_iterator; - - int seen; - - int index; - - boolean last_reported; - - double ground_pres; - - int n_pad_samples; - - int gps_tick; - - int boost_tick; - - boolean saw_gps_date; - - boolean missing_gps_time; - - public AltosRecord read() throws IOException, ParseException { - for (;;) { - if (record == null) { - if (!record_iterator.hasNext()) { - if (last_reported) - return null; - last_reported = true; - AltosRecord r = new AltosRecord(state); - r.time = (r.tick - boost_tick) / 100.0; - return r; - } - record = record_iterator.next(); - - if ((seen & seen_basic) == seen_basic && record.tick != state.tick) { - AltosRecord r = new AltosRecord(state); - r.time = (r.tick - boost_tick) / 100.0; - return r; - } - } - - state.tick = record.tick; - switch (record.cmd) { - case Altos.AO_LOG_FLIGHT: - /* recorded when first read from the file */ - break; - case Altos.AO_LOG_SENSOR: - state.accel = record.a; - state.pres = record.b; - if (state.state < Altos.ao_flight_boost) { - n_pad_samples++; - ground_pres += state.pres; - state.ground_pres = (int) (ground_pres / 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; - state.flight_vel += (state.accel_plus_g - state.accel); - } - seen |= seen_sensor; - break; - case Altos.AO_LOG_TEMP_VOLT: - state.temp = record.a; - state.batt = record.b; - seen |= seen_temp_volt; - break; - case Altos.AO_LOG_DEPLOY: - state.drogue = record.a; - state.main = record.b; - seen |= seen_deploy; - break; - case Altos.AO_LOG_STATE: - state.state = record.a; - break; - case Altos.AO_LOG_GPS_TIME: - gps_tick = state.tick; - AltosGPS old = state.gps; - state.gps = new AltosGPS(); - - /* 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); - int flags = (record.b >> 8); - state.gps.connected = (flags & Altos.AO_GPS_RUNNING) != 0; - state.gps.locked = (flags & Altos.AO_GPS_VALID) != 0; - state.gps.date_valid = (flags & Altos.AO_GPS_DATE_VALID) != 0; - state.gps.nsat = (flags & Altos.AO_GPS_NUM_SAT_MASK) >> - Altos.AO_GPS_NUM_SAT_SHIFT; - break; - case Altos.AO_LOG_GPS_LAT: - int lat32 = record.a | (record.b << 16); - state.gps.lat = (double) lat32 / 1e7; - break; - case Altos.AO_LOG_GPS_LON: - int lon32 = record.a | (record.b << 16); - state.gps.lon = (double) lon32 / 1e7; - break; - case Altos.AO_LOG_GPS_ALT: - state.gps.alt = record.a; - break; - case Altos.AO_LOG_GPS_SAT: - if (state.tick == gps_tick) { - int svid = record.a; - int c_n0 = record.b >> 8; - state.gps.add_sat(svid, c_n0); - } - break; - case Altos.AO_LOG_GPS_DATE: - state.gps.year = (record.a & 0xff) + 2000; - state.gps.month = record.a >> 8; - state.gps.day = record.b & 0xff; - break; - - case Altos.AO_LOG_CONFIG_VERSION: - break; - case Altos.AO_LOG_MAIN_DEPLOY: - break; - case Altos.AO_LOG_APOGEE_DELAY: - break; - case Altos.AO_LOG_RADIO_CHANNEL: - break; - case Altos.AO_LOG_CALLSIGN: - state.callsign = record.data; - break; - case Altos.AO_LOG_ACCEL_CAL: - state.accel_plus_g = record.a; - state.accel_minus_g = record.b; - break; - case Altos.AO_LOG_RADIO_CAL: - break; - case Altos.AO_LOG_MANUFACTURER: - break; - case Altos.AO_LOG_PRODUCT: - break; - case Altos.AO_LOG_SERIAL_NUMBER: - state.serial = record.a; - break; - case Altos.AO_LOG_SOFTWARE_VERSION: - break; - } - record = null; - } - } - - public void write_comments(PrintStream out) { - Iterator iterator = records.iterator(); - out.printf("# Comments\n"); - while (iterator.hasNext()) { - AltosOrderedRecord record = iterator.next(); - switch (record.cmd) { - case Altos.AO_LOG_CONFIG_VERSION: - out.printf("# Config version: %s\n", record.data); - break; - case Altos.AO_LOG_MAIN_DEPLOY: - out.printf("# Main deploy: %s\n", record.a); - break; - case Altos.AO_LOG_APOGEE_DELAY: - out.printf("# Apogee delay: %s\n", record.a); - break; - case Altos.AO_LOG_RADIO_CHANNEL: - out.printf("# Radio channel: %s\n", record.a); - break; - case Altos.AO_LOG_CALLSIGN: - out.printf("# Callsign: %s\n", record.data); - break; - case Altos.AO_LOG_ACCEL_CAL: - out.printf ("# Accel cal: %d %d\n", record.a, record.b); - break; - case Altos.AO_LOG_RADIO_CAL: - out.printf ("# Radio cal: %d\n", record.a); - break; - case Altos.AO_LOG_MANUFACTURER: - out.printf ("# Manufacturer: %s\n", record.data); - break; - case Altos.AO_LOG_PRODUCT: - out.printf ("# Product: %s\n", record.data); - break; - case Altos.AO_LOG_SERIAL_NUMBER: - out.printf ("# Serial number: %d\n", record.a); - break; - case Altos.AO_LOG_SOFTWARE_VERSION: - out.printf ("# Software version: %s\n", record.data); - break; - } - } - } - - /* - * 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; - - 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); - } - - /* - * 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 AltosEepromReader (FileInputStream input) { - state = new AltosRecord(); - state.state = Altos.ao_flight_pad; - state.accel_plus_g = 15758; - state.accel_minus_g = 16294; - seen = 0; - records = new TreeSet(); - - AltosOrderedRecord last_gps_time = null; - - int index = 0; - int tick = 0; - - boolean missing_time = false; - - try { - for (;;) { - String line = AltosRecord.gets(input); - if (line == null) - break; - AltosOrderedRecord record = new AltosOrderedRecord(line, index++, tick); - if (record == null) - break; - if (record.cmd == Altos.AO_LOG_INVALID) - continue; - tick = record.tick; - if (record.cmd == Altos.AO_LOG_FLIGHT) { - state.ground_accel = record.a; - state.flight_accel = record.a; - state.flight = record.b; - boost_tick = tick; - seen |= seen_flight; - } - - /* 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 == Altos.AO_LOG_GPS_DATE) - saw_gps_date = true; - - /* go back and fix up any missing time values */ - if (record.cmd == Altos.AO_LOG_GPS_TIME) { - last_gps_time = record; - if (missing_time) { - Iterator iterator = records.iterator(); - while (iterator.hasNext()) { - AltosOrderedRecord old = iterator.next(); - if (old.cmd == Altos.AO_LOG_GPS_TIME && - old.a == -1 && old.b == -1) - { - update_time(record, old); - } - } - missing_time = false; - } - } - - if (record.cmd == Altos.AO_LOG_GPS_LAT) { - if (last_gps_time == null || last_gps_time.tick != record.tick) { - AltosOrderedRecord add_gps_time = new AltosOrderedRecord(Altos.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; - - records.add(add_gps_time); - record.index = index++; - } - } - records.add(record); - - /* Bail after reading the 'landed' record; we're all done */ - if (record.cmd == Altos.AO_LOG_STATE && - record.a == Altos.ao_flight_landed) - break; - } - } catch (IOException io) { - } catch (ParseException pe) { - } - record_iterator = records.iterator(); - try { - input.close(); - } catch (IOException ie) { - } - } -} diff --git a/ao-tools/altosui/AltosLogfileChooser.java b/ao-tools/altosui/AltosLogfileChooser.java index 36b51de6..8b9d77d6 100644 --- a/ao-tools/altosui/AltosLogfileChooser.java +++ b/ao-tools/altosui/AltosLogfileChooser.java @@ -27,11 +27,6 @@ import java.util.*; import java.text.*; import java.util.prefs.*; -import altosui.AltosPreferences; -import altosui.AltosReader; -import altosui.AltosEepromReader; -import altosui.AltosTelemetryReader; - public class AltosLogfileChooser extends JFileChooser { JFrame frame; String filename; @@ -45,7 +40,7 @@ public class AltosLogfileChooser extends JFileChooser { return file; } - public AltosReader runDialog() { + public AltosRecordIterable runDialog() { int ret; ret = showOpenDialog(frame); @@ -59,9 +54,9 @@ public class AltosLogfileChooser extends JFileChooser { in = new FileInputStream(file); if (filename.endsWith("eeprom")) - return new AltosEepromReader(in); + return new AltosEepromIterable(in); else - return new AltosTelemetryReader(in); + return new AltosTelemetryIterable(in); } catch (FileNotFoundException fe) { JOptionPane.showMessageDialog(frame, filename, diff --git a/ao-tools/altosui/AltosRecord.java b/ao-tools/altosui/AltosRecord.java index 18c6079d..00484767 100644 --- a/ao-tools/altosui/AltosRecord.java +++ b/ao-tools/altosui/AltosRecord.java @@ -142,7 +142,7 @@ public class AltosRecord { return counts_per_g / 9.80665; } public double acceleration() { - return (accel_plus_g - accel) / accel_counts_per_mss(); + return (ground_accel - accel) / accel_counts_per_mss(); } public double accel_speed() { diff --git a/ao-tools/altosui/AltosRecordIterable.java b/ao-tools/altosui/AltosRecordIterable.java new file mode 100644 index 00000000..147ecc14 --- /dev/null +++ b/ao-tools/altosui/AltosRecordIterable.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosRecord; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosEepromMonitor; + +public abstract class AltosRecordIterable implements Iterable { + public abstract Iterator iterator(); + public void write_comments(PrintStream out) { } +} diff --git a/ao-tools/altosui/AltosReplayThread.java b/ao-tools/altosui/AltosReplayThread.java new file mode 100644 index 00000000..b418160a --- /dev/null +++ b/ao-tools/altosui/AltosReplayThread.java @@ -0,0 +1,83 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.Altos; +import altosui.AltosSerial; +import altosui.AltosSerialMonitor; +import altosui.AltosRecord; +import altosui.AltosTelemetry; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosFlightInfoTableModel; +import altosui.AltosChannelMenu; +import altosui.AltosFlashUI; +import altosui.AltosLogfileChooser; +import altosui.AltosCSVUI; +import altosui.AltosLine; +import altosui.AltosStatusTable; +import altosui.AltosInfoTable; +import altosui.AltosDisplayThread; + +/* + * Open an existing telemetry file and replay it in realtime + */ + +public class AltosReplayThread extends AltosDisplayThread { + Iterator iterator; + String name; + + public AltosRecord read() { + if (iterator.hasNext()) + return iterator.next(); + return null; + } + + public void close (boolean interrupted) { + if (!interrupted) + report(); + } + + void update(AltosState state) throws InterruptedException { + /* Make it run in realtime after the rocket leaves the pad */ + if (state.state > Altos.ao_flight_pad) + Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); + } + + public AltosReplayThread(Frame parent, Iterator in_iterator, + String in_name, AltosVoice voice, + AltosStatusTable status, AltosInfoTable info) { + super(parent, voice, status, info); + iterator = in_iterator; + name = in_name; + } +} diff --git a/ao-tools/altosui/AltosTelemetryIterable.java b/ao-tools/altosui/AltosTelemetryIterable.java new file mode 100644 index 00000000..0a125c98 --- /dev/null +++ b/ao-tools/altosui/AltosTelemetryIterable.java @@ -0,0 +1,83 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.io.*; +import java.util.*; +import java.text.*; +import altosui.AltosTelemetry; + +public class AltosTelemetryIterable extends AltosRecordIterable { + LinkedList records; + + public Iterator iterator () { + return records.iterator(); + } + + public AltosTelemetryIterable (FileInputStream input) { + boolean saw_boost = false; + int current_tick = 0; + int boost_tick = 0; + + records = new LinkedList (); + + try { + for (;;) { + String line = AltosRecord.gets(input); + if (line == null) { + break; + } + try { + AltosTelemetry record = new AltosTelemetry(line); + if (record == null) + break; + if (records.isEmpty()) { + current_tick = record.tick; + } else { + int tick = record.tick | (current_tick & ~ 0xffff); + if (tick < current_tick - 0x1000) + tick += 0x10000; + current_tick = tick; + record.tick = current_tick; + } + if (!saw_boost && record.state >= Altos.ao_flight_boost) + { + saw_boost = true; + boost_tick = record.tick; + } + records.add(record); + } catch (ParseException pe) { + System.out.printf("parse exception %s\n", pe.getMessage()); + } catch (AltosCRCException ce) { + System.out.printf("crc error\n"); + } + } + } catch (IOException io) { + System.out.printf("io exception\n"); + } + + /* 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/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java deleted file mode 100644 index 3564a0a5..00000000 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.io.*; -import java.util.*; -import java.text.*; -import altosui.AltosTelemetry; - -public class AltosTelemetryReader extends AltosReader { - LinkedList records; - - Iterator record_iterator; - - int boost_tick; - - public AltosRecord read() throws IOException, ParseException { - AltosRecord r; - if (!record_iterator.hasNext()) - return null; - - r = record_iterator.next(); - r.time = (r.tick - boost_tick) / 100.0; - return r; - } - - public AltosTelemetryReader (FileInputStream input) { - boolean saw_boost = false; - int current_tick = 0; - - records = new LinkedList (); - - try { - for (;;) { - String line = AltosRecord.gets(input); - if (line == null) { - break; - } - try { - AltosTelemetry record = new AltosTelemetry(line); - if (record == null) - break; - if (records.isEmpty()) { - current_tick = record.tick; - } else { - int tick = record.tick | (current_tick & ~ 0xffff); - if (tick < current_tick - 0x1000) - tick += 0x10000; - current_tick = tick; - record.tick = current_tick; - } - if (!saw_boost && record.state >= Altos.ao_flight_boost) - { - saw_boost = true; - boost_tick = record.tick; - } - records.add(record); - } catch (ParseException pe) { - System.out.printf("parse exception %s\n", pe.getMessage()); - } catch (AltosCRCException ce) { - System.out.printf("crc error\n"); - } - } - } catch (IOException io) { - System.out.printf("io exception\n"); - } - record_iterator = records.iterator(); - try { - input.close(); - } catch (IOException ie) { - } - } -} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 1adeeccf..29eda2ec 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -46,6 +46,7 @@ import altosui.AltosCSVUI; import altosui.AltosLine; import altosui.AltosStatusTable; import altosui.AltosInfoTable; +import altosui.AltosDisplayThread; import libaltosJNI.*; @@ -119,222 +120,7 @@ public class AltosUI extends JFrame { voice.speak("Rocket flight monitor ready."); } - void show(AltosState state, int crc_errors) { - if (state != null) { - flightStatus.set(state); - flightInfo.show(state, crc_errors); - } - } - - 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 < Altos.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 (Altos.ao_flight_drogue <= state.state && - state.state < Altos.ao_flight_landed && - state.range >= 0) - { - voice.speak("Height %d, bearing %d, elevation %d, range %d.\n", - (int) (state.height + 0.5), - (int) (state.from_pad.bearing + 0.5), - (int) (state.elevation + 0.5), - (int) (state.range + 0.5)); - } else if (state.state > Altos.ao_flight_pad) { - voice.speak("%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 >= Altos.ao_flight_drogue && - (last || - System.currentTimeMillis() - state.report_time >= 15000 || - state.state == Altos.ao_flight_landed)) - { - if (Math.abs(state.baro_speed) < 20 && state.height < 100) - voice.speak("rocket landed safely"); - else - voice.speak("rocket may have crashed"); - if (state.from_pad != null) - voice.speak("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 () { - - reported_landing = 0; - state = null; - report_interval = 10000; - try { - for (;;) { - set_report_time(); - for (;;) { - voice.drain(); - synchronized (this) { - long sleep_time = report_time - now(); - if (sleep_time <= 0) - break; - wait(sleep_time); - } - } - report(false); - } - } catch (InterruptedException ie) { - try { - voice.drain(); - } catch (InterruptedException iie) { } - } - } - - public synchronized void notice(AltosState new_state, boolean spoken) { - AltosState old_state = state; - state = new_state; - if (!started && state.state > Altos.ao_flight_pad) { - started = true; - start(); - } - - if (state.state < Altos.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(); - } - } - - private boolean tell(AltosState state, AltosState old_state) { - boolean ret = false; - if (old_state == null || old_state.state != state.state) { - voice.speak(state.data.state()); - if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && - state.state > Altos.ao_flight_boost) { - voice.speak("max speed: %d meters per second.", - (int) (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: %d meters.", - (int) (state.max_height + 0.5)); - ret = true; - } - } - if (old_state == null || old_state.gps_ready != state.gps_ready) { - if (state.gps_ready) { - voice.speak("GPS ready"); - ret = true; - } - else if (old_state != null) { - voice.speak("GPS lost"); - ret = true; - } - } - old_state = state; - return ret; - } - - class DisplayThread extends Thread { - IdleThread idle_thread; - - String name; - - int crc_errors; - - void init() { } - - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } - - void close(boolean interrupted) { } - - void update(AltosState state) throws InterruptedException { } - - public void run() { - boolean interrupted = false; - String line; - AltosState state = null; - AltosState old_state = null; - boolean told; - - idle_thread = new IdleThread(); - - flightInfo.clear(); - try { - for (;;) { - try { - AltosRecord record = read(); - if (record == null) - break; - old_state = state; - state = new AltosState(record, state); - update(state); - show(state, crc_errors); - told = tell(state, old_state); - idle_thread.notice(state, told); - } catch (ParseException pp) { - System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); - } catch (AltosCRCException ce) { - ++crc_errors; - show(state, crc_errors); - } - } - } catch (InterruptedException ee) { - interrupted = true; - } catch (IOException ie) { - JOptionPane.showMessageDialog(AltosUI.this, - String.format("Error reading from \"%s\"", name), - "Telemetry Read Error", - JOptionPane.ERROR_MESSAGE); - } finally { - close(interrupted); - idle_thread.interrupt(); - try { - idle_thread.join(); - } catch (InterruptedException ie) {} - } - } - - public void report() { - if (idle_thread != null) - idle_thread.report(true); - } - } - - class DeviceThread extends DisplayThread { + class DeviceThread extends AltosDisplayThread { AltosSerial serial; LinkedBlockingQueue telem; @@ -350,7 +136,8 @@ public class AltosUI extends JFrame { serial.remove_monitor(telem); } - public DeviceThread(AltosSerial s, String in_name) { + public DeviceThread(AltosSerial s, String in_name, AltosVoice voice, AltosStatusTable status, AltosInfoTable info) { + super(AltosUI.this, voice, status, info); serial = s; telem = new LinkedBlockingQueue(); serial.add_monitor(telem); @@ -366,7 +153,7 @@ public class AltosUI extends JFrame { try { stop_display(); serial_line.open(device); - DeviceThread thread = new DeviceThread(serial_line, device.getPath()); + DeviceThread thread = new DeviceThread(serial_line, device.getPath(), voice, flightStatus, flightInfo); serial_line.set_channel(AltosPreferences.channel()); serial_line.set_callsign(AltosPreferences.callsign()); run_display(thread); @@ -409,41 +196,6 @@ public class AltosUI extends JFrame { new AltosFlashUI(AltosUI.this); } - /* - * Open an existing telemetry file and replay it in realtime - */ - - class ReplayThread extends DisplayThread { - AltosReader reader; - String name; - - public AltosRecord read() { - try { - return reader.read(); - } catch (IOException ie) { - JOptionPane.showMessageDialog(AltosUI.this, - name, - "error reading", - JOptionPane.ERROR_MESSAGE); - } catch (ParseException pe) { - } - return null; - } - - public void close (boolean interrupted) { - if (!interrupted) - report(); - } - - public ReplayThread(AltosReader in_reader, String in_name) { - reader = in_reader; - } - void update(AltosState state) throws InterruptedException { - /* Make it run in realtime after the rocket leaves the pad */ - if (state.state > Altos.ao_flight_pad) - Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); - } - } Thread display_thread; @@ -469,10 +221,13 @@ public class AltosUI extends JFrame { private void Replay() { AltosLogfileChooser chooser = new AltosLogfileChooser( AltosUI.this); - AltosReader reader = chooser.runDialog(); - if (reader != null) - run_display(new ReplayThread(reader, - chooser.filename())); + AltosRecordIterable iterable = chooser.runDialog(); + if (iterable != null) + run_display(new AltosReplayThread(this, iterable.iterator(), + chooser.filename(), + voice, + flightStatus, + flightInfo)); } /* Connect to TeleMetrum, either directly or through @@ -663,16 +418,16 @@ public class AltosUI extends JFrame { return input.concat(extension); } - static AltosReader open_logfile(String filename) { + static AltosRecordIterable open_logfile(String filename) { File file = new File (filename); try { FileInputStream in; in = new FileInputStream(file); if (filename.endsWith("eeprom")) - return new AltosEepromReader(in); + return new AltosEepromIterable(in); else - return new AltosTelemetryReader(in); + return new AltosTelemetryIterable(in); } catch (FileNotFoundException fe) { System.out.printf("Cannot open '%s'\n", filename); return null; @@ -696,14 +451,13 @@ public class AltosUI extends JFrame { return; } System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); - AltosReader reader = open_logfile(input); - if (reader == null) + AltosRecordIterable iterable = open_logfile(input); + if (iterable == null) return; AltosCSV writer = open_csv(output); if (writer == null) return; - writer.write(reader); - reader.close(); + writer.write(iterable); writer.close(); } diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 56ac0520..7070af22 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -20,9 +20,10 @@ altosui_JAVA = \ AltosDebug.java \ AltosDeviceDialog.java \ AltosDevice.java \ + AltosDisplayThread.java \ AltosEepromDownload.java \ AltosEepromMonitor.java \ - AltosEepromReader.java \ + AltosEepromIterable.java \ AltosEepromRecord.java \ AltosFile.java \ AltosFlash.java \ @@ -41,6 +42,8 @@ altosui_JAVA = \ AltosPreferences.java \ AltosReader.java \ AltosRecord.java \ + AltosRecordIterable.java \ + AltosReplayThread.java \ AltosRomconfig.java \ AltosRomconfigUI.java \ AltosSerial.java \ @@ -48,7 +51,7 @@ altosui_JAVA = \ AltosState.java \ AltosStatusTable.java \ AltosTelemetry.java \ - AltosTelemetryReader.java \ + AltosTelemetryIterable.java \ AltosUI.java \ AltosVoice.java -- cgit v1.2.3 From fe7eba2e4af36cf29d8dc2378ac6985be04f68c6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 27 Sep 2010 18:51:05 -0700 Subject: altosui: .CSV output: add link quality, gps hdop and sat C/N0 numbers This makes the CSV files contain all of the available information. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 46 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index 7f14adad..c01d55a8 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -45,6 +45,7 @@ public class AltosCSV { * callsign * time (seconds since boost) * rssi + * link quality * * Flight status * state @@ -79,21 +80,22 @@ public class AltosCSV { * from_pad_azimuth (deg true) * from_pad_range (m) * from_pad_elevation (deg from horizon) + * hdop * * GPS Sat data - * hdop * C/N0 data for all 32 valid SDIDs */ void write_general_header() { - out.printf("version,serial,flight,call,time,rssi"); + out.printf("version,serial,flight,call,time,rssi,lqi"); } void write_general(AltosRecord record) { - out.printf("%s,%d,%d,%s,%8.2f,%4d", + out.printf("%s, %d, %d, %s, %8.2f, %4d, %3d", record.version, record.serial, record.flight, record.callsign, (double) record.time, - record.rssi); + record.rssi, + record.status & 0x7f); } void write_flight_header() { @@ -123,7 +125,7 @@ public class AltosCSV { } void write_gps_header() { - out.printf("connected,locked,nsat,latitude,longitude,altitude,year,month,day,hour,minute,second,pad_dist,pad_range,pad_az,pad_el"); + 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) { @@ -135,7 +137,7 @@ public class AltosCSV { 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", + 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", gps.connected?1:0, gps.locked?1:0, gps.nsat, @@ -151,7 +153,33 @@ public class AltosCSV { from_pad.distance, state.range, from_pad.bearing, - state.elevation); + state.elevation, + gps.hdop); + } + + void write_gps_sat_header() { + for(int i = 1; i <= 32; i++) { + out.printf("sat%02d", i); + if (i != 32) + out.printf(","); + } + } + + void write_gps_sat(AltosRecord record) { + AltosGPS gps = record.gps; + for(int i = 1; i <= 32; i++) { + int c_n0 = 0; + if (gps != null && gps.cc_gps_sat != null) { + for(int j = 0; j < gps.cc_gps_sat.length; j++) + if (gps.cc_gps_sat[j].svid == i) { + c_n0 = gps.cc_gps_sat[j].c_n0; + break; + } + } + out.printf ("%3d", c_n0); + if (i != 32) + out.printf(","); + } } void write_header() { @@ -159,6 +187,7 @@ public class AltosCSV { out.printf(","); write_flight_header(); out.printf(","); write_basic_header(); out.printf(","); write_gps_header(); + out.printf(","); write_gps_sat_header(); out.printf ("\n"); } @@ -167,7 +196,8 @@ public class AltosCSV { write_general(record); out.printf(","); write_flight(record); out.printf(","); write_basic(record); out.printf(","); - write_gps(record); + write_gps(record); out.printf(","); + write_gps_sat(record); out.printf ("\n"); } -- cgit v1.2.3 From 803203197e51e71e9c77b3610047fd5bf9a56c56 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 27 Sep 2010 18:52:30 -0700 Subject: altosui: Deal with eeprom dates going backwards across wrap eeprom timestamps can go backwards as the GPS time stamps are recorded when the first GPS character is received, but not placed into the eeprom log until the last GPS packet is complete. If this happens at the same time the tick count is wrapping, then the tick count will wrap backwards across the 0 boundary causing time to jump forwards. Fix this by letting time go backwards across the tick boundary, which requires that we know when the first 'real' tick is read from the eeprom file. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromIterable.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromIterable.java b/ao-tools/altosui/AltosEepromIterable.java index d4ac3f3e..2f1e7e90 100644 --- a/ao-tools/altosui/AltosEepromIterable.java +++ b/ao-tools/altosui/AltosEepromIterable.java @@ -44,15 +44,19 @@ class AltosOrderedRecord extends AltosEepromRecord implements Comparable 0x8000) - new_tick += 0x10000; + 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; + } } - tick = new_tick; index = in_index; } @@ -340,7 +344,7 @@ public class AltosEepromIterable extends AltosRecordIterable { int index = 0; int prev_tick = 0; - + boolean prev_tick_valid = false; boolean missing_time = false; try { @@ -348,12 +352,14 @@ public class AltosEepromIterable extends AltosRecordIterable { String line = AltosRecord.gets(input); if (line == null) break; - AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick); + AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick, prev_tick_valid); if (record == null) break; if (record.cmd == Altos.AO_LOG_INVALID) continue; prev_tick = record.tick; + if (record.cmd < Altos.AO_LOG_CONFIG_VERSION) + prev_tick_valid = true; if (record.cmd == Altos.AO_LOG_FLIGHT) { flight_record = record; continue; -- cgit v1.2.3 From ce7f59fbfb5a94a67a4ceced3cc371b4c6b6e5d1 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Tue, 28 Sep 2010 14:45:01 +1000 Subject: Hax0r graphing to support telem/eeprom files --- ao-tools/altosui/AltosCSV.java | 1 - ao-tools/altosui/AltosDataPointReader.java | 77 +++++++++++++++++++++++++++++ ao-tools/altosui/AltosGraphDataChooser.java | 20 ++++++-- ao-tools/altosui/Makefile.am | 5 +- 4 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 ao-tools/altosui/AltosDataPointReader.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index c01d55a8..3a9e48f8 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -23,7 +23,6 @@ import java.text.*; import java.util.*; import altosui.AltosRecord; -import altosui.AltosReader; public class AltosCSV { File name; diff --git a/ao-tools/altosui/AltosDataPointReader.java b/ao-tools/altosui/AltosDataPointReader.java new file mode 100644 index 00000000..4d7831e4 --- /dev/null +++ b/ao-tools/altosui/AltosDataPointReader.java @@ -0,0 +1,77 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.io.IOException; +import java.text.ParseException; +import java.lang.UnsupportedOperationException; +import java.util.NoSuchElementException; +import java.util.Iterator; + +import altosui.AltosDataPoint; +import altosui.AltosRecordIterable; +import altosui.AltosRecord; +import altosui.AltosState; + +class AltosDataPointReader implements Iterable { + Iterator iter; + AltosState state; + AltosRecord record; + + public AltosDataPointReader(Iterable reader) { + this.iter = reader.iterator(); + this.state = null; + } + + private void read_next_record() + throws NoSuchElementException + { + record = iter.next(); + state = new AltosState(record, state); + } + + private AltosDataPoint current_dp() { + assert this.record != null; + + return new AltosDataPoint() { + public int version() { return record.version; } + public int serial() { return record.serial; } + public int flight() { return record.flight; } + public String callsign() { return record.callsign; } + public double time() { return record.time; } + public double rssi() { return record.rssi; } + + public int state() { return record.state; } + public String state_name() { return record.state(); } + + public double acceleration() { return record.acceleration(); } + public double pressure() { return record.raw_pressure(); } + public double altitude() { return record.raw_altitude(); } + public double height() { return record.raw_height(); } + public double accel_speed() { return record.accel_speed(); } + public double baro_speed() { return state.baro_speed; } + public double temperature() { return record.temperature(); } + public double battery_voltage() { return record.battery_voltage(); } + public double drogue_voltage() { return record.drogue_voltage(); } + public double main_voltage() { return record.main_voltage(); } + }; + } + + public Iterator iterator() { + return new Iterator() { + public void remove() { + throw new UnsupportedOperationException(); + } + public boolean hasNext() { + return iter.hasNext(); + } + public AltosDataPoint next() { + read_next_record(); + return current_dp(); + } + }; + } +} + diff --git a/ao-tools/altosui/AltosGraphDataChooser.java b/ao-tools/altosui/AltosGraphDataChooser.java index 1bf28454..667d99f7 100644 --- a/ao-tools/altosui/AltosGraphDataChooser.java +++ b/ao-tools/altosui/AltosGraphDataChooser.java @@ -28,10 +28,10 @@ import java.text.*; import java.util.prefs.*; import altosui.AltosPreferences; -import altosui.AltosReader; import altosui.AltosCsvReader; -import altosui.AltosEepromReader; -import altosui.AltosTelemetryReader; +import altosui.AltosDataPointReader; +import altosui.AltosEepromIterable; +import altosui.AltosTelemetryIterable; public class AltosGraphDataChooser extends JFileChooser { JFrame frame; @@ -56,7 +56,17 @@ public class AltosGraphDataChooser extends JFileChooser { return null; filename = file.getName(); try { - return new AltosCsvReader(new FileReader(file)); + if (filename.endsWith("eeprom")) { + FileInputStream in = new FileInputStream(file); + return new AltosDataPointReader(new AltosEepromIterable(in)); + } else if (filename.endsWith("telem")) { + FileInputStream in = new FileInputStream(file); + return new AltosDataPointReader(new AltosTelemetryIterable(in)); + } else if (filename.endsWith("csv")) { + return new AltosCsvReader(new FileReader(file)); + } else { + throw new FileNotFoundException(); + } } catch (FileNotFoundException fe) { JOptionPane.showMessageDialog(frame, filename, @@ -71,7 +81,7 @@ public class AltosGraphDataChooser extends JFileChooser { frame = in_frame; setDialogTitle("Select Flight Record File"); setFileFilter(new FileNameExtensionFilter("Flight data file", - "csv")); + "csv", "telem", "eeprom")); setCurrentDirectory(AltosPreferences.logdir()); } } diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index ab8ca7d4..7510c88a 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -5,7 +5,7 @@ man_MANS=altosui.1 altoslibdir=$(libdir)/altos -CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(JFREECHART)/*:$(FREETTS)/*:/usr/share/java/*" +CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" bin_SCRIPTS=altosui @@ -53,6 +53,7 @@ altosui_JAVA = \ AltosTelemetry.java \ AltosTelemetryIterable.java \ AltosUI.java \ + AltosDataPointReader.java \ AltosCsvReader.java \ AltosDataPoint.java \ AltosGraph.java \ @@ -168,7 +169,7 @@ $(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLA Manifest.txt: Makefile echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTS)/freetts.jar $(JFREECHART)/jfreechart.jar $(JFREECHAR)/jcommon.jar $(JFREECHART)/csv.jar" >> $@ + echo "Class-Path: $(FREETTS)/freetts.jar $(FREETTS)/jfreechart.jar $(FREETTS)/jcommon.jar $(FREETTS)/csv.jar" >> $@ Manifest-fat.txt: echo 'Main-Class: altosui.AltosUI' > $@ -- cgit v1.2.3 From 28da3406426437604125d332e4cda90d459df487 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 27 Sep 2010 22:26:56 -0700 Subject: altosui: use Altos constants in graphing code The Altos class nicely defines constants for all of the flight states. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosGraphUI.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosGraphUI.java b/ao-tools/altosui/AltosGraphUI.java index 73f95023..d945c333 100644 --- a/ao-tools/altosui/AltosGraphUI.java +++ b/ao-tools/altosui/AltosGraphUI.java @@ -39,7 +39,7 @@ public class AltosGraphUI extends JFrame AltosGraphTime.Element speed = new AltosGraphTime.TimeSeries("Speed (m/s)", "Vertical Speed", green) { public void gotTimeData(double time, AltosDataPoint d) { - if (d.state() < 4) { + if (d.state() < Altos.ao_flight_drogue) { series.add(time, d.accel_speed()); } else { series.add(time, d.baro_speed()); @@ -81,13 +81,13 @@ public class AltosGraphUI extends JFrame } }; - AltosGraphTime.Element e_pad = new AltosGraphTime.StateMarker(2, "Pad"); - AltosGraphTime.Element e_boost = new AltosGraphTime.StateMarker(3, "Boost"); - AltosGraphTime.Element e_fast = new AltosGraphTime.StateMarker(4, "Fast"); - AltosGraphTime.Element e_coast = new AltosGraphTime.StateMarker(5, "Coast"); - AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(6, "Drogue"); - AltosGraphTime.Element e_main = new AltosGraphTime.StateMarker(7, "Main"); - AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(8, "Landed"); + AltosGraphTime.Element e_pad = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad"); + AltosGraphTime.Element e_boost = new AltosGraphTime.StateMarker(Altos.ao_flight_boost, "Boost"); + AltosGraphTime.Element e_fast = new AltosGraphTime.StateMarker(Altos.ao_flight_fast, "Fast"); + AltosGraphTime.Element e_coast = new AltosGraphTime.StateMarker(Altos.ao_flight_coast, "Coast"); + AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(Altos.ao_flight_drogue, "Drogue"); + AltosGraphTime.Element e_main = new AltosGraphTime.StateMarker(Altos.ao_flight_main, "Main"); + AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(Altos.ao_flight_landed, "Landed"); protected AltosGraphTime myAltosGraphTime(String suffix) { return (new AltosGraphTime("Overall " + suffix)) @@ -130,7 +130,7 @@ public class AltosGraphUI extends JFrame return (new AltosGraphTime("Ascent " + suffix) { public void addData(AltosDataPoint d) { int state = d.state(); - if (3 <= state && state <= 5) { + if (Altos.ao_flight_boost <= state && state <= Altos.ao_flight_coast) { super.addData(d); } } @@ -145,7 +145,7 @@ public class AltosGraphUI extends JFrame return (new AltosGraphTime("Descent " + suffix) { public void addData(AltosDataPoint d) { int state = d.state(); - if (6 <= state && state <= 7) { + if (Altos.ao_flight_drogue <= state && state <= Altos.ao_flight_main) { super.addData(d); } } -- cgit v1.2.3 From 82744c3497d37650b88dee80be7956c4bd1cffb2 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Tue, 28 Sep 2010 15:27:07 +1000 Subject: Add callsign/serial/flight to graph title --- ao-tools/altosui/AltosGraphTime.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosGraphTime.java b/ao-tools/altosui/AltosGraphTime.java index c0f99c59..ab01b888 100644 --- a/ao-tools/altosui/AltosGraphTime.java +++ b/ao-tools/altosui/AltosGraphTime.java @@ -131,6 +131,10 @@ class AltosGraphTime extends AltosGraph { } } + private String callsign = null; + private Integer serial = null; + private Integer flight = null; + private String title; private ArrayList elements; private HashMap axes; @@ -186,6 +190,9 @@ class AltosGraphTime extends AltosGraph { for (Element e : elements) { e.gotTimeData(time, d); } + if (callsign == null) callsign = d.callsign(); + if (serial == null) serial = new Integer(d.serial()); + if (flight == null) flight = new Integer(d.flight()); } public JFreeChart createChart() { @@ -197,6 +204,13 @@ class AltosGraphTime extends AltosGraph { plot.setRenderer(renderer); plot.setOrientation(PlotOrientation.VERTICAL); + if (serial != null && flight != null) { + title = serial + "/" + flight + ": " + title; + } + if (callsign != null) { + title = callsign + " - " + title; + } + renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); -- cgit v1.2.3 From f0d1468ceae065f0cdae6f6ae3323dec5636f073 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 28 Sep 2010 17:56:49 -0700 Subject: altosui: Add KML file export. Command line has switches now, --kml and --csv Export save dialog has combo box to select kml or csv result. Signed-off-by: Keith Packard --- ao-tools/altosui/Altos.java | 7 ++ ao-tools/altosui/AltosCSV.java | 10 +-- ao-tools/altosui/AltosCSVUI.java | 45 +++++++--- ao-tools/altosui/AltosKML.java | 169 ++++++++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 73 +++++++++++----- ao-tools/altosui/AltosWriter.java | 32 ++++++++ ao-tools/altosui/Makefile.am | 25 ++++-- 7 files changed, 313 insertions(+), 48 deletions(-) create mode 100644 ao-tools/altosui/AltosKML.java create mode 100644 ao-tools/altosui/AltosWriter.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java index 07bd01ae..997550e0 100644 --- a/ao-tools/altosui/Altos.java +++ b/ao-tools/altosui/Altos.java @@ -200,4 +200,11 @@ public class Altos { } return v * sign; } + + static String replace_extension(String input, String extension) { + int dot = input.lastIndexOf("."); + if (dot > 0) + input = input.substring(0,dot); + return input.concat(extension); + } } diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index 3a9e48f8..df98b2b4 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -22,9 +22,7 @@ import java.io.*; import java.text.*; import java.util.*; -import altosui.AltosRecord; - -public class AltosCSV { +public class AltosCSV implements AltosWriter { File name; PrintStream out; boolean header_written; @@ -33,9 +31,9 @@ public class AltosCSV { LinkedList pad_records; AltosState state; - static final int ALTOS_CSV_VERSION = 1; + static final int ALTOS_CSV_VERSION = 2; - /* Version 1 format: + /* Version 2 format: * * General info * version number @@ -91,7 +89,7 @@ public class AltosCSV { void write_general(AltosRecord record) { out.printf("%s, %d, %d, %s, %8.2f, %4d, %3d", - record.version, record.serial, record.flight, record.callsign, + ALTOS_CSV_VERSION, record.serial, record.flight, record.callsign, (double) record.time, record.rssi, record.status & 0x7f); diff --git a/ao-tools/altosui/AltosCSVUI.java b/ao-tools/altosui/AltosCSVUI.java index 4eb72de8..eb620ba8 100644 --- a/ao-tools/altosui/AltosCSVUI.java +++ b/ao-tools/altosui/AltosCSVUI.java @@ -38,7 +38,25 @@ public class AltosCSVUI JFrame frame; Thread thread; AltosRecordIterable iterable; - AltosCSV writer; + AltosWriter writer; + JFileChooser csv_chooser; + JComboBox combo_box; + + static String[] combo_box_items = { "CSV", "KML" }; + + void set_default_file() { + File current = csv_chooser.getSelectedFile(); + String current_name = current.getName(); + String new_name = null; + String selected = (String) combo_box.getSelectedItem(); + + if (selected.equals("CSV")) + new_name = Altos.replace_extension(current_name, ".csv"); + else if (selected.equals("KML")) + new_name = Altos.replace_extension(current_name, ".kml"); + if (new_name != null) + csv_chooser.setSelectedFile(new File(new_name)); + } public void run() { AltosLogfileChooser chooser; @@ -47,20 +65,22 @@ public class AltosCSVUI iterable = chooser.runDialog(); if (iterable == null) return; - JFileChooser csv_chooser; - File file = chooser.file(); - String path = file.getPath(); - int dot = path.lastIndexOf("."); - if (dot >= 0) - path = path.substring(0,dot); - path = path.concat(".csv"); - csv_chooser = new JFileChooser(path); - csv_chooser.setSelectedFile(new File(path)); + csv_chooser = new JFileChooser(chooser.file()); + combo_box = new JComboBox(combo_box_items); + combo_box.addActionListener(this); + csv_chooser.setAccessory(combo_box); + csv_chooser.setSelectedFile(chooser.file()); + set_default_file(); int ret = csv_chooser.showSaveDialog(frame); if (ret == JFileChooser.APPROVE_OPTION) { + File file = csv_chooser.getSelectedFile(); + String type = (String) combo_box.getSelectedItem(); try { - writer = new AltosCSV(csv_chooser.getSelectedFile()); + if (type.equals("CSV")) + writer = new AltosCSV(file); + else + writer = new AltosKML(file); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, file.getName(), @@ -73,6 +93,9 @@ public class AltosCSVUI } public void actionPerformed(ActionEvent e) { + System.out.printf("command %s param %s\n", e.getActionCommand(), e.paramString()); + if (e.getActionCommand().equals("comboBoxChanged")) + set_default_file(); } public AltosCSVUI(JFrame in_frame) { diff --git a/ao-tools/altosui/AltosKML.java b/ao-tools/altosui/AltosKML.java new file mode 100644 index 00000000..d586033f --- /dev/null +++ b/ao-tools/altosui/AltosKML.java @@ -0,0 +1,169 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.text.*; +import java.util.*; + +public class AltosKML implements AltosWriter { + + File name; + PrintStream out; + int state = -1; + AltosRecord prev = null; + + static final String[] kml_state_colors = { + "FF000000", + "FF000000", + "FF000000", + "FF0000FF", + "FF4080FF", + "FF00FFFF", + "FFFF0000", + "FF00FF00", + "FF000000", + "FFFFFFFF" + }; + + static final String kml_header_start = + "\n" + + "\n" + + "\n" + + " AO Flight#%d S/N: %03d\n" + + " \n"; + static final String kml_header_end = + " \n" + + " 0\n"; + + static final String kml_style_start = + " \n"; + + static final String kml_placemark_start = + " \n" + + " %s\n" + + " #ao-flightstate-%s\n" + + " \n" + + " 1\n" + + " absolute\n" + + " \n"; + + static final String kml_coord_fmt = + " %12.7f, %12.7f, %12.7f \n"; + + static final String kml_placemark_end = + " \n" + + " \n" + + " \n"; + + static final String kml_footer = + "\n" + + "\n"; + + void start (AltosRecord 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); + out.printf("Time: %2d:%02d:%02d\n", + record.gps.hour, record.gps.minute, record.gps.second); + out.printf("%s", kml_header_end); + } + + 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]); + 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) { + out.printf("%s", kml_placemark_end); + } + + void coord(AltosRecord record) { + AltosGPS gps = record.gps; + out.printf(kml_coord_fmt, + gps.lon, gps.lat, + record.filtered_altitude(), (double) gps.alt, + record.time, gps.nsat); + } + + void end() { + out.printf("%s", kml_footer); + } + + public void close() { + if (prev != null) { + state_end(prev); + end(); + prev = null; + } + } + + public void write(AltosRecord record) { + AltosGPS gps = record.gps; + + if (gps == null) + return; + if (!started) { + start(record); + started = true; + } + if (prev != null && + prev.gps.second == record.gps.second && + prev.gps.minute == record.gps.minute && + prev.gps.hour == record.gps.hour) + return; + if (record.state != state) { + state = record.state; + if (prev != null) { + coord(record); + state_end(prev); + } + state_start(record); + } + coord(record); + prev = record; + } + + public void write(AltosRecordIterable iterable) { + for (AltosRecord record : iterable) + write(record); + } + + public AltosKML(File in_name) throws FileNotFoundException { + name = in_name; + out = new PrintStream(name); + } + + public AltosKML(String in_string) throws FileNotFoundException { + this(new File(in_string)); + } +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index de0673a2..71481519 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -426,13 +426,6 @@ public class AltosUI extends JFrame { } - static String replace_extension(String input, String extension) { - int dot = input.lastIndexOf("."); - if (dot > 0) - input = input.substring(0,dot); - return input.concat(extension); - } - static AltosRecordIterable open_logfile(String filename) { File file = new File (filename); try { @@ -449,7 +442,7 @@ public class AltosUI extends JFrame { } } - static AltosCSV open_csv(String filename) { + static AltosWriter open_csv(String filename) { File file = new File (filename); try { return new AltosCSV(file); @@ -459,29 +452,65 @@ public class AltosUI extends JFrame { } } - static void process_file(String input) { - String output = replace_extension(input,".csv"); - if (input.equals(output)) { - System.out.printf("Not processing '%s'\n", input); - return; + static AltosWriter open_kml(String filename) { + File file = new File (filename); + try { + return new AltosKML(file); + } catch (FileNotFoundException fe) { + System.out.printf("Cannot open '%s'\n", filename); + return null; } - System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); + } + + static final int process_csv = 1; + static final int process_kml = 2; + + static void process_file(String input, int process) { AltosRecordIterable iterable = open_logfile(input); if (iterable == null) return; - AltosCSV writer = open_csv(output); - if (writer == null) - return; - writer.write(iterable); - writer.close(); + if (process == 0) + process = process_csv; + if ((process & process_csv) != 0) { + String output = Altos.replace_extension(input,".csv"); + System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); + if (input.equals(output)) { + System.out.printf("Not processing '%s'\n", input); + } else { + AltosWriter writer = open_csv(output); + if (writer != null) { + writer.write(iterable); + writer.close(); + } + } + } + if ((process & process_kml) != 0) { + String output = Altos.replace_extension(input,".kml"); + System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); + if (input.equals(output)) { + System.out.printf("Not processing '%s'\n", input); + } else { + AltosWriter writer = open_kml(output); + if (writer == null) + return; + writer.write(iterable); + writer.close(); + } + } } public static void main(final String[] args) { - + int process = 0; /* Handle batch-mode */ if (args.length > 0) { - for (int i = 0; i < args.length; i++) - process_file(args[i]); + for (int i = 0; i < args.length; i++) { + if (args[i].equals("--kml")) + process |= process_kml; + else if (args[i].equals("--csv")) + process |= process_csv; + else + process_file(args[i], process); + } } else { AltosUI altosui = new AltosUI(); altosui.setVisible(true); diff --git a/ao-tools/altosui/AltosWriter.java b/ao-tools/altosui/AltosWriter.java new file mode 100644 index 00000000..a172dff0 --- /dev/null +++ b/ao-tools/altosui/AltosWriter.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.text.*; +import java.util.*; + +public interface AltosWriter { + + public void write(AltosRecord record); + + public void write(AltosRecordIterable iterable); + + public void close(); +} diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 7510c88a..4e2a5027 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -35,6 +35,7 @@ altosui_JAVA = \ AltosHexfile.java \ Altos.java \ AltosInfoTable.java \ + AltosKML.java \ AltosLine.java \ AltosLogfileChooser.java \ AltosLog.java \ @@ -53,13 +54,14 @@ altosui_JAVA = \ AltosTelemetry.java \ AltosTelemetryIterable.java \ AltosUI.java \ - AltosDataPointReader.java \ - AltosCsvReader.java \ - AltosDataPoint.java \ - AltosGraph.java \ - AltosGraphTime.java \ - AltosGraphUI.java \ - AltosGraphDataChooser.java \ + AltosWriter.java \ + AltosDataPointReader.java \ + AltosCsvReader.java \ + AltosDataPoint.java \ + AltosGraph.java \ + AltosGraphTime.java \ + AltosGraphUI.java \ + AltosGraphDataChooser.java \ AltosVoice.java JFREECHART_CLASS= \ @@ -109,13 +111,13 @@ MACOSX_EXTRA=$(FIRMWARE) WINDOWS_FILES=$(FAT_FILES) altos.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) -all-local: classes/altosui $(JAR) altosui altosui-test +all-local: classes/altosui $(JAR) altosui altosui-test altosui-jdb clean-local: -rm -rf classes $(JAR) $(FATJAR) \ $(LINUX_DIST) $(MACOSX_DIST) windows $(WINDOWS_DIST) $(FREETTS_CLASS) \ $(JFREECHART_CLASS) $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ - altosui altosui-test macosx linux + altosui altosui-test altosui-jdb macosx linux if FATINSTALL @@ -185,6 +187,11 @@ altosui-test: Makefile echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos/.libs" -jar altosui.jar "$$@"' >> $@ chmod +x $@ +altosui-jdb: Makefile + echo "#!/bin/sh" > $@ + echo 'exec jdb -classpath "classes:../libaltos:$(FREETTS)/*" -Djava.library.path="../libaltos/.libs" altosui/AltosUI "$$@"' >> $@ + chmod +x $@ + libaltos.so: -rm -f "$@" $(LN_S) ../libaltos/.libs/"$@" . -- cgit v1.2.3 From c2c4d515ef9cc2cae8a8f2803e9498bb0794c4ed Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 6 Oct 2010 16:25:49 -0700 Subject: altosui: Remove ability to graph data in .csv files There's no reason to support these files when the raw .eeprom or .telem files which generate them should be used instead. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCsvReader.java | 113 ---------------------------- ao-tools/altosui/AltosGraphDataChooser.java | 5 +- ao-tools/altosui/AltosGraphUI.java | 21 ------ ao-tools/altosui/AltosUI.java | 4 - ao-tools/altosui/Makefile.am | 1 - 5 files changed, 1 insertion(+), 143 deletions(-) delete mode 100644 ao-tools/altosui/AltosCsvReader.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCsvReader.java b/ao-tools/altosui/AltosCsvReader.java deleted file mode 100644 index 600788f4..00000000 --- a/ao-tools/altosui/AltosCsvReader.java +++ /dev/null @@ -1,113 +0,0 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later - -package altosui; - -import java.lang.UnsupportedOperationException; -import java.util.HashMap; -import java.util.NoSuchElementException; -import java.util.Iterator; -import java.io.*; -import com.csvreader.CsvReader; - -import altosui.AltosDataPoint; - -class AltosCsvReader implements Iterable -{ - public CsvReader csv; - public AltosDataPoint next = null; - - static protected String [] headers = "version serial flight call time rssi state state_name acceleration pressure altitude height accel_speed baro_speed temperature battery_voltage drogue_voltage main_voltage connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_range pad_az pad_el".split(" "); - - AltosCsvReader(Reader stream) { - csv = new CsvReader(stream); - csv.setComment('#'); - csv.setUseComments(true); - csv.setHeaders(headers); - } - AltosCsvReader(String filename) throws FileNotFoundException { - csv = new CsvReader(filename); - csv.setComment('#'); - csv.setUseComments(true); - csv.setHeaders(headers); - } - - public Iterator iterator() { - return new Iterator() { - public void remove() { - throw new UnsupportedOperationException(); - } - public boolean hasNext() { - if (next == null) { - try { - if (csv.readRecord()) { - next = new CsvRow(); - } else { - close(); - return false; - } - } catch (IOException e) { - close(); - return false; - } - } - return true; - } - public AltosDataPoint next() { - if (!hasNext()) - throw new NoSuchElementException(); - AltosDataPoint res = next; - next = null; - return res; - } - }; - } - - public void close() { - csv.close(); - } - - private class CsvRow extends HashMap - implements AltosDataPoint - { - CsvRow() throws IOException { - for (int i = 0; i < headers.length; i++) { - this.put(headers[i], csv.get(headers[i]).trim()); - } - } - - private int intField(String name) { - return Integer.parseInt(get(name).trim()); - } - private double doubleField(String name) { - return Double.valueOf(get(name)).doubleValue(); - } - private String stringField(String name) { - return get(name); - } - - public int version() { return intField("version"); } - public int serial() { return intField("serial"); } - public int flight() { return intField("flight"); } - public String callsign() { return stringField("call"); } - public double time() { return doubleField("time"); } - public double rssi() { return doubleField("rssi"); } - - public int state() { return intField("state"); } - public String state_name() { return stringField("state_name"); } - - public double acceleration() { return doubleField("acceleration"); } - public double pressure() { return doubleField("pressure"); } - public double altitude() { return doubleField("altitude"); } - public double height() { return doubleField("height"); } - public double accel_speed() { return doubleField("accel_speed"); } - public double baro_speed() { return doubleField("baro_speed"); } - public double temperature() { return doubleField("temperature"); } - public double battery_voltage() { - return doubleField("battery_voltage"); - } - public double drogue_voltage() { return doubleField("drogue_voltage"); } - public double main_voltage() { return doubleField("main_voltage"); } - } -} diff --git a/ao-tools/altosui/AltosGraphDataChooser.java b/ao-tools/altosui/AltosGraphDataChooser.java index 667d99f7..caa14118 100644 --- a/ao-tools/altosui/AltosGraphDataChooser.java +++ b/ao-tools/altosui/AltosGraphDataChooser.java @@ -28,7 +28,6 @@ import java.text.*; import java.util.prefs.*; import altosui.AltosPreferences; -import altosui.AltosCsvReader; import altosui.AltosDataPointReader; import altosui.AltosEepromIterable; import altosui.AltosTelemetryIterable; @@ -62,8 +61,6 @@ public class AltosGraphDataChooser extends JFileChooser { } else if (filename.endsWith("telem")) { FileInputStream in = new FileInputStream(file); return new AltosDataPointReader(new AltosTelemetryIterable(in)); - } else if (filename.endsWith("csv")) { - return new AltosCsvReader(new FileReader(file)); } else { throw new FileNotFoundException(); } @@ -81,7 +78,7 @@ public class AltosGraphDataChooser extends JFileChooser { frame = in_frame; setDialogTitle("Select Flight Record File"); setFileFilter(new FileNameExtensionFilter("Flight data file", - "csv", "telem", "eeprom")); + "telem", "eeprom")); setCurrentDirectory(AltosPreferences.logdir()); } } diff --git a/ao-tools/altosui/AltosGraphUI.java b/ao-tools/altosui/AltosGraphUI.java index d945c333..25643c76 100644 --- a/ao-tools/altosui/AltosGraphUI.java +++ b/ao-tools/altosui/AltosGraphUI.java @@ -17,7 +17,6 @@ import org.jfree.chart.axis.AxisLocation; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; -import altosui.AltosCsvReader; import altosui.AltosDataPoint; import altosui.AltosGraphTime; @@ -228,26 +227,6 @@ public class AltosGraphUI extends JFrame return graph; } - - public static void main(String[] args) - throws java.io.FileNotFoundException, java.io.IOException - { - if (args.length < 1 || 2 < args.length) - { - System.out.println("Please specify telemetry csv"); - return; - } - - AltosCsvReader csv = new AltosCsvReader(args[0]); - if (args.length == 1) { - for (AltosGraph g : createGraphs(csv)) { - g.toPNG(); - } - } else { - int which = Integer.parseInt(args[1].trim()); - AltosGraphUI demo = new AltosGraphUI(csv, which); - } - } } /* gnuplot bits... diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 71481519..28ed42fb 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -59,10 +59,6 @@ public class AltosUI extends JFrame { private AltosLog altos_log; private Box vbox; - private Font statusFont = new Font("SansSerif", Font.BOLD, 24); - private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14); - private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14); - public AltosVoice voice = new AltosVoice(); public static boolean load_library(Frame frame) { diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 4e2a5027..58c1517f 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -56,7 +56,6 @@ altosui_JAVA = \ AltosUI.java \ AltosWriter.java \ AltosDataPointReader.java \ - AltosCsvReader.java \ AltosDataPoint.java \ AltosGraph.java \ AltosGraphTime.java \ -- cgit v1.2.3 From 811ced628d586134224c1b501b40ce9eb435fc7c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 6 Oct 2010 16:42:27 -0700 Subject: altosui: Separate out jfreechart and jcommon directories This allows these packages to be referenced separately Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 32 +++++++++++++++++++++----------- configure.ac | 12 ++++++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 58c1517f..2f4ed6d8 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -64,9 +64,10 @@ altosui_JAVA = \ AltosVoice.java JFREECHART_CLASS= \ - jfreechart.jar \ - jcommon.jar \ - csv.jar + jfreechart.jar + +JCOMMON_CLASS=\ + jcommon.jar FREETTS_CLASS= \ cmudict04.jar \ @@ -100,7 +101,7 @@ LINUX_DIST=Altos-Linux-$(VERSION).tar.bz2 MACOSX_DIST=Altos-Mac-$(VERSION).zip WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe -FAT_FILES=$(FATJAR) $(FREETTS_CLASS) $(JFREECHART_CLASS) +FAT_FILES=$(FATJAR) $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) LINUX_EXTRA=altosui-fat @@ -115,7 +116,7 @@ all-local: classes/altosui $(JAR) altosui altosui-test altosui-jdb clean-local: -rm -rf classes $(JAR) $(FATJAR) \ $(LINUX_DIST) $(MACOSX_DIST) windows $(WINDOWS_DIST) $(FREETTS_CLASS) \ - $(JFREECHART_CLASS) $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ + $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ altosui altosui-test altosui-jdb macosx linux if FATINSTALL @@ -162,7 +163,7 @@ $(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) -C classes altosui \ -C ../libaltos libaltosJNI -$(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLASS) $(LIBALTOS) $(JAVA_ICON) +$(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) $(JAVA_ICON) jar cfm $@ Manifest-fat.txt \ -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ -C classes altosui \ @@ -170,25 +171,25 @@ $(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLA Manifest.txt: Makefile echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTS)/freetts.jar $(FREETTS)/jfreechart.jar $(FREETTS)/jcommon.jar $(FREETTS)/csv.jar" >> $@ + echo "Class-Path: $(FREETTS)/freetts.jar $(JFREECHART)/jfreechart.jar $(JCOMMON)/jcommon.jar" >> $@ Manifest-fat.txt: echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: freetts.jar jfreechart.jar jcommon.jar csv.jar" >> $@ + echo "Class-Path: freetts.jar jfreechart.jar jcommon.jar" >> $@ altosui: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="$(altoslibdir)" -jar "$(altosuidir)/altosui.jar" "$$@"' >> $@ + echo 'exec java -cp "$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="$(altoslibdir)" -jar "$(altosuidir)/altosui.jar" "$$@"' >> $@ chmod +x $@ altosui-test: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos/.libs" -jar altosui.jar "$$@"' >> $@ + echo 'exec java -cp "$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="../libaltos/.libs" -jar altosui.jar "$$@"' >> $@ chmod +x $@ altosui-jdb: Makefile echo "#!/bin/sh" > $@ - echo 'exec jdb -classpath "classes:../libaltos:$(FREETTS)/*" -Djava.library.path="../libaltos/.libs" altosui/AltosUI "$$@"' >> $@ + echo 'exec jdb -classpath "classes:../libaltos:$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="../libaltos/.libs" altosui/AltosUI "$$@"' >> $@ chmod +x $@ libaltos.so: @@ -207,6 +208,14 @@ $(FREETTS_CLASS): -rm -f "$@" $(LN_S) "$(FREETTS)"/"$@" . +$(JFREECHART_CLASS): + -rm -f "$@" + $(LN_S) "$(JFREECHART)"/"$@" . + +$(JCOMMON_CLASS): + -rm -f "$@" + $(LN_S) "$(JCOMMON)"/"$@" . + $(LINUX_DIST): $(LINUX_FILES) $(LINUX_EXTRA) -rm -f $@ -rm -rf linux @@ -224,6 +233,7 @@ $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) mkdir -p macosx/AltOS macosx/AltosUI.app/Contents/Resources/Java cp -p $(FATJAR) macosx/AltosUI.app/Contents/Resources/Java/altosui.jar cp -p $(FREETTS_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java + cp -p $(JFREECHART_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java cp -p $(MACOSX_EXTRA) macosx/AltOS cd macosx && zip -r ../$@ AltosUI.app AltOS diff --git a/configure.ac b/configure.ac index 4bf8f7fe..903c5765 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,18 @@ AC_ARG_WITH(freetts, AS_HELP_STRING([--with-freetts=PATH], AC_SUBST(FREETTS) +AC_ARG_WITH(jfreechart, AS_HELP_STRING([--with-jfreechart=PATH], + [Set jfreechart class path (default /usr/share/java)]), + [JFREECHART=$withval], [JFREECHART=/usr/share/java]) + +AC_SUBST(JFREECHART) + +AC_ARG_WITH(jcommon, AS_HELP_STRING([--with-jcommon=PATH], + [Set jcommon class path (default /usr/share/java)]), + [JCOMMON=$withval], [JCOMMON=/usr/share/java]) + +AC_SUBST(JCOMMON) + AC_ARG_WITH(jvm, AS_HELP_STRING([--with-jvm-include=PATH], [Set jvm include path for jni builds (default searches in /usr/lib/jvm)]), [JVM_INCLUDE=$withval], [JVM_INCLUDE=auto]) -- cgit v1.2.3 From 16916be51d746b1e1057b3219e5bec8f8814259e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 5 Nov 2010 23:44:47 -0700 Subject: altosui: Split out flight monitoring to separate window This creates a per-TD (or replay) window to contain the flight monitoring information, allowing multiple monitors. This also adds per-TD preferences for monitoring channel. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDisplayThread.java | 40 +++---- ao-tools/altosui/AltosFlightReader.java | 38 +++++++ ao-tools/altosui/AltosFlightUI.java | 128 +++++++++++++++++++++ ao-tools/altosui/AltosLog.java | 17 +-- ao-tools/altosui/AltosPreferences.java | 20 ++-- ao-tools/altosui/AltosReplayReader.java | 57 ++++++++++ ao-tools/altosui/AltosReplayThread.java | 83 -------------- ao-tools/altosui/AltosSerial.java | 2 + ao-tools/altosui/AltosStatusTable.java | 5 +- ao-tools/altosui/AltosTelemetryReader.java | 62 +++++++++++ ao-tools/altosui/AltosUI.java | 171 +++++++---------------------- ao-tools/altosui/Makefile.am | 5 +- 12 files changed, 366 insertions(+), 262 deletions(-) create mode 100644 ao-tools/altosui/AltosFlightReader.java create mode 100644 ao-tools/altosui/AltosFlightUI.java create mode 100644 ao-tools/altosui/AltosReplayReader.java delete mode 100644 ao-tools/altosui/AltosReplayThread.java create mode 100644 ao-tools/altosui/AltosTelemetryReader.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDisplayThread.java b/ao-tools/altosui/AltosDisplayThread.java index 9cc3d5ce..b15472ed 100644 --- a/ao-tools/altosui/AltosDisplayThread.java +++ b/ao-tools/altosui/AltosDisplayThread.java @@ -30,13 +30,14 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosDisplayThread extends Thread { - Frame parent; - IdleThread idle_thread; - AltosVoice voice; - String name; - int crc_errors; - AltosStatusTable flightStatus; - AltosInfoTable flightInfo; + Frame parent; + IdleThread idle_thread; + AltosVoice voice; + String name; + AltosFlightReader reader; + int crc_errors; + AltosStatusTable flightStatus; + AltosInfoTable flightInfo; class IdleThread extends Thread { @@ -150,14 +151,6 @@ public class AltosDisplayThread extends Thread { } } - void init() { } - - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } - - void close(boolean interrupted) { } - - void update(AltosState state) throws InterruptedException { } - boolean tell(AltosState state, AltosState old_state) { boolean ret = false; if (old_state == null || old_state.state != state.state) { @@ -208,12 +201,12 @@ public class AltosDisplayThread extends Thread { try { for (;;) { try { - AltosRecord record = read(); + AltosRecord record = reader.read(); if (record == null) break; old_state = state; state = new AltosState(record, state); - update(state); + reader.update(state); show(state, crc_errors); told = tell(state, old_state); idle_thread.notice(state, told); @@ -232,7 +225,9 @@ public class AltosDisplayThread extends Thread { "Telemetry Read Error", JOptionPane.ERROR_MESSAGE); } finally { - close(interrupted); + if (!interrupted) + idle_thread.report(true); + reader.close(interrupted); idle_thread.interrupt(); try { idle_thread.join(); @@ -240,16 +235,11 @@ public class AltosDisplayThread extends Thread { } } - public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosStatusTable in_status, AltosInfoTable in_info) { + public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosStatusTable in_status, AltosInfoTable in_info, AltosFlightReader in_reader) { parent = in_parent; voice = in_voice; flightStatus = in_status; flightInfo = in_info; + reader = in_reader; } - - public void report() { - if (idle_thread != null) - idle_thread.report(true); - } - } diff --git a/ao-tools/altosui/AltosFlightReader.java b/ao-tools/altosui/AltosFlightReader.java new file mode 100644 index 00000000..3d59de9a --- /dev/null +++ b/ao-tools/altosui/AltosFlightReader.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; +import java.io.*; + +public class AltosFlightReader { + String name; + + int serial; + + void init() { } + + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } + + void close(boolean interrupted) { } + + void set_channel(int channel) { } + + void update(AltosState state) throws InterruptedException { } +} diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java new file mode 100644 index 00000000..84ba9dca --- /dev/null +++ b/ao-tools/altosui/AltosFlightUI.java @@ -0,0 +1,128 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlightUI extends JFrame { + String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; + Object[][] statusData = { { "0", "pad", "-50", "0" } }; + + AltosVoice voice; + AltosFlightReader reader; + AltosDisplayThread thread; + + private Box vbox; + private AltosStatusTable flightStatus; + private AltosInfoTable flightInfo; + + public int width() { + return flightInfo.width(); + } + + public int height() { + return flightStatus.height() + flightInfo.height(); + } + + void stop_display() { + if (thread != null && thread.isAlive()) { + thread.interrupt(); + try { + thread.join(); + } catch (InterruptedException ie) {} + } + thread = null; + } + + void disconnect() { + stop_display(); + } + + public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { + voice = in_voice; + reader = in_reader; + + java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg"); + if (imgURL != null) + setIconImage(new ImageIcon(imgURL).getImage()); + + setTitle(String.format("AltOS %s", reader.name)); + + flightStatus = new AltosStatusTable(); + + vbox = new Box (BoxLayout.Y_AXIS); + vbox.add(flightStatus); + + flightInfo = new AltosInfoTable(); + vbox.add(flightInfo.box()); + + this.add(vbox); + + if (serial >= 0) { + JMenuBar menubar = new JMenuBar(); + + // Channel menu + { + JMenu menu = new AltosChannelMenu(AltosPreferences.channel(serial)); + menu.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int channel = Integer.parseInt(e.getActionCommand()); + reader.set_channel(channel); + AltosPreferences.set_channel(serial, channel); + } + }); + menu.setMnemonic(KeyEvent.VK_C); + menubar.add(menu); + } + + this.setJMenuBar(menubar); + } + + this.setSize(new Dimension (width(), height())); + this.validate(); + + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + disconnect(); + setVisible(false); + dispose(); + } + }); + + this.setVisible(true); + + thread = new AltosDisplayThread(this, voice, flightStatus, flightInfo, reader); + + thread.start(); + } + + public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) { + this(in_voice, in_reader, -1); + } +} diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java index f876beba..fed96c28 100644 --- a/ao-tools/altosui/AltosLog.java +++ b/ao-tools/altosui/AltosLog.java @@ -39,9 +39,15 @@ class AltosLog implements Runnable { FileWriter log_file; Thread log_thread; - void close() throws IOException { - if (log_file != null) - log_file.close(); + void close() { + if (log_file != null) { + try { + log_file.close(); + } catch (IOException io) { + } + } + if (log_thread != null) + log_thread.interrupt(); } boolean open (AltosTelemetry telem) throws IOException { @@ -89,10 +95,7 @@ class AltosLog implements Runnable { } catch (InterruptedException ie) { } catch (IOException ie) { } - try { - close(); - } catch (IOException ie) { - } + close(); } public AltosLog (AltosSerial s) { diff --git a/ao-tools/altosui/AltosPreferences.java b/ao-tools/altosui/AltosPreferences.java index 52627563..e2a3df3b 100644 --- a/ao-tools/altosui/AltosPreferences.java +++ b/ao-tools/altosui/AltosPreferences.java @@ -32,7 +32,7 @@ class AltosPreferences { final static String logdirPreference = "LOGDIR"; /* channel preference name */ - final static String channelPreference = "CHANNEL"; + final static String channelPreferenceFormat = "CHANNEL-%d"; /* voice preference name */ final static String voicePreference = "VOICE"; @@ -52,8 +52,8 @@ class AltosPreferences { /* Log directory */ static File logdir; - /* Telemetry channel */ - static int channel; + /* Channel (map serial to channel) */ + static Hashtable channels; /* Voice preference */ static boolean voice; @@ -80,7 +80,7 @@ class AltosPreferences { logdir.mkdirs(); } - channel = preferences.getInt(channelPreference, 0); + channels = new Hashtable(); voice = preferences.getBoolean(voicePreference, true); @@ -151,15 +151,19 @@ class AltosPreferences { return logdir; } - public static void set_channel(int new_channel) { - channel = new_channel; + public static void set_channel(int serial, int new_channel) { + channels.put(serial, new_channel); synchronized (preferences) { - preferences.putInt(channelPreference, channel); + preferences.putInt(String.format(channelPreferenceFormat, serial), new_channel); flush_preferences(); } } - public static int channel() { + public static int channel(int serial) { + if (channels.containsKey(serial)) + return channels.get(serial); + int channel = preferences.getInt(String.format(channelPreferenceFormat, serial), 0); + channels.put(serial, channel); return channel; } diff --git a/ao-tools/altosui/AltosReplayReader.java b/ao-tools/altosui/AltosReplayReader.java new file mode 100644 index 00000000..4e5e1d93 --- /dev/null +++ b/ao-tools/altosui/AltosReplayReader.java @@ -0,0 +1,57 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +/* + * Open an existing telemetry file and replay it in realtime + */ + +public class AltosReplayReader extends AltosFlightReader { + Iterator iterator; + + public AltosRecord read() { + if (iterator.hasNext()) + return iterator.next(); + return null; + } + + public void close (boolean interrupted) { + } + + void update(AltosState state) throws InterruptedException { + /* Make it run in realtime after the rocket leaves the pad */ + if (state.state > Altos.ao_flight_pad) + Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); + } + + public AltosReplayReader(Iterator in_iterator, String in_name) { + iterator = in_iterator; + name = in_name; + } +} diff --git a/ao-tools/altosui/AltosReplayThread.java b/ao-tools/altosui/AltosReplayThread.java deleted file mode 100644 index b418160a..00000000 --- a/ao-tools/altosui/AltosReplayThread.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -import altosui.Altos; -import altosui.AltosSerial; -import altosui.AltosSerialMonitor; -import altosui.AltosRecord; -import altosui.AltosTelemetry; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosFlightInfoTableModel; -import altosui.AltosChannelMenu; -import altosui.AltosFlashUI; -import altosui.AltosLogfileChooser; -import altosui.AltosCSVUI; -import altosui.AltosLine; -import altosui.AltosStatusTable; -import altosui.AltosInfoTable; -import altosui.AltosDisplayThread; - -/* - * Open an existing telemetry file and replay it in realtime - */ - -public class AltosReplayThread extends AltosDisplayThread { - Iterator iterator; - String name; - - public AltosRecord read() { - if (iterator.hasNext()) - return iterator.next(); - return null; - } - - public void close (boolean interrupted) { - if (!interrupted) - report(); - } - - void update(AltosState state) throws InterruptedException { - /* Make it run in realtime after the rocket leaves the pad */ - if (state.state > Altos.ao_flight_pad) - Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); - } - - public AltosReplayThread(Frame parent, Iterator in_iterator, - String in_name, AltosVoice voice, - AltosStatusTable status, AltosInfoTable info) { - super(parent, voice, status, info); - iterator = in_iterator; - name = in_name; - } -} diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index a1fc4371..f65e44d6 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -193,6 +193,8 @@ public class AltosSerial implements Runnable { print("~\nE 0\n"); flush_output(); set_monitor(monitor_mode); + set_channel(AltosPreferences.channel()); + set_callsign(AltosPreferences.callsign()); } public void set_channel(int channel) { diff --git a/ao-tools/altosui/AltosStatusTable.java b/ao-tools/altosui/AltosStatusTable.java index 3965a57d..0d3a5d14 100644 --- a/ao-tools/altosui/AltosStatusTable.java +++ b/ao-tools/altosui/AltosStatusTable.java @@ -34,14 +34,11 @@ import altosui.AltosFlightInfoTableModel; public class AltosStatusTable extends JTable { private AltosFlightStatusTableModel flightStatusModel; - JFrame frame; - private Font statusFont = new Font("SansSerif", Font.BOLD, 24); - public AltosStatusTable(JFrame in_frame) { + public AltosStatusTable() { super((TableModel) new AltosFlightStatusTableModel()); flightStatusModel = (AltosFlightStatusTableModel) getModel(); - frame = in_frame; setFont(statusFont); diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java new file mode 100644 index 00000000..0b5509eb --- /dev/null +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -0,0 +1,62 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; +import java.io.*; +import java.util.concurrent.*; + +class AltosTelemetryReader extends AltosFlightReader { + AltosDevice device; + AltosSerial serial; + AltosLog log; + + LinkedBlockingQueue telem; + + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { + AltosLine l = telem.take(); + if (l.line == null) + throw new IOException("IO error"); + return new AltosTelemetry(l.line); + } + + void close(boolean interrupted) { + serial.remove_monitor(telem); + log.close(); + serial.close(); + } + + void set_channel(int channel) { + serial.set_channel(channel); + } + + void set_callsign(String callsign) { + serial.set_callsign(callsign); + } + + public AltosTelemetryReader (AltosDevice in_device) throws FileNotFoundException, IOException { + device = in_device; + serial = new AltosSerial(); + log = new AltosLog(serial); + name = device.getPath(); + + telem = new LinkedBlockingQueue(); + serial.add_monitor(telem); + } +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 28ed42fb..e1bbee30 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -39,7 +39,6 @@ import altosui.AltosPreferences; import altosui.AltosLog; import altosui.AltosVoice; import altosui.AltosFlightInfoTableModel; -import altosui.AltosChannelMenu; import altosui.AltosFlashUI; import altosui.AltosLogfileChooser; import altosui.AltosCSVUI; @@ -51,14 +50,6 @@ import altosui.AltosDisplayThread; import libaltosJNI.*; public class AltosUI extends JFrame { - private int channel = -1; - - private AltosStatusTable flightStatus; - private AltosInfoTable flightInfo; - private AltosSerial serial_line; - private AltosLog altos_log; - private Box vbox; - public AltosVoice voice = new AltosVoice(); public static boolean load_library(Frame frame) { @@ -73,38 +64,41 @@ public class AltosUI extends JFrame { return true; } + void telemetry_window(AltosDevice device) { + try { + AltosFlightReader reader = new AltosTelemetryReader(device); + if (reader != null) + new AltosFlightUI(voice, reader, device.getSerial()); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + String.format("Cannot open device \"%s\"", + device.getPath()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + device.getPath(), + "Unkonwn I/O error", + JOptionPane.ERROR_MESSAGE); + } + } + public AltosUI() { load_library(null); - String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; - Object[][] statusData = { { "0", "pad", "-50", "0" } }; - java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg"); if (imgURL != null) setIconImage(new ImageIcon(imgURL).getImage()); AltosPreferences.init(this); - vbox = Box.createVerticalBox(); - this.add(vbox); - - flightStatus = new AltosStatusTable(this); - - vbox.add(flightStatus); - - flightInfo = new AltosInfoTable(); - vbox.add(flightInfo.box()); - setTitle("AltOS"); createMenu(); - serial_line = new AltosSerial(); - altos_log = new AltosLog(serial_line); int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); - this.setSize(new Dimension (flightInfo.width(), - flightStatus.height() + flightInfo.height())); + this.setSize(new Dimension (300, 100)); this.validate(); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @@ -113,63 +107,14 @@ public class AltosUI extends JFrame { System.exit(0); } }); - voice.speak("Rocket flight monitor ready."); - } - - class DeviceThread extends AltosDisplayThread { - AltosSerial serial; - LinkedBlockingQueue telem; - - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { - AltosLine l = telem.take(); - if (l.line == null) - throw new IOException("IO error"); - return new AltosTelemetry(l.line); - } - - void close(boolean interrupted) { - serial.close(); - serial.remove_monitor(telem); - } - - public DeviceThread(AltosSerial s, String in_name, AltosVoice voice, AltosStatusTable status, AltosInfoTable info) { - super(AltosUI.this, voice, status, info); - serial = s; - telem = new LinkedBlockingQueue(); - serial.add_monitor(telem); - name = in_name; - } } private void ConnectToDevice() { AltosDevice device = AltosDeviceDialog.show(AltosUI.this, AltosDevice.product_basestation); - if (device != null) { - try { - stop_display(); - serial_line.open(device); - DeviceThread thread = new DeviceThread(serial_line, device.getPath(), voice, flightStatus, flightInfo); - serial_line.set_channel(AltosPreferences.channel()); - serial_line.set_callsign(AltosPreferences.callsign()); - run_display(thread); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - String.format("Cannot open device \"%s\"", - device.getPath()), - "Cannot open target device", - JOptionPane.ERROR_MESSAGE); - } catch (IOException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - device.getPath(), - "Unkonwn I/O error", - JOptionPane.ERROR_MESSAGE); - } - } - } - - void DisconnectFromDevice () { - stop_display(); + if (device != null) + telemetry_window(device); } void ConfigureCallsign() { @@ -177,11 +122,8 @@ public class AltosUI extends JFrame { result = JOptionPane.showInputDialog(AltosUI.this, "Configure Callsign", AltosPreferences.callsign()); - if (result != null) { + if (result != null) AltosPreferences.set_callsign(result); - if (serial_line != null) - serial_line.set_callsign(result); - } } void ConfigureTeleMetrum() { @@ -192,25 +134,6 @@ public class AltosUI extends JFrame { new AltosFlashUI(AltosUI.this); } - - Thread display_thread; - - private void stop_display() { - if (display_thread != null && display_thread.isAlive()) { - display_thread.interrupt(); - try { - display_thread.join(); - } catch (InterruptedException ie) {} - } - display_thread = null; - } - - private void run_display(Thread thread) { - stop_display(); - display_thread = thread; - display_thread.start(); - } - /* * Replay a flight from telemetry data */ @@ -218,12 +141,11 @@ public class AltosUI extends JFrame { AltosLogfileChooser chooser = new AltosLogfileChooser( AltosUI.this); AltosRecordIterable iterable = chooser.runDialog(); - if (iterable != null) - run_display(new AltosReplayThread(this, iterable.iterator(), - chooser.filename(), - voice, - flightStatus, - flightInfo)); + if (iterable != null) { + AltosFlightReader reader = new AltosReplayReader(iterable.iterator(), + chooser.filename()); + new AltosFlightUI(voice, reader); + } } /* Connect to TeleMetrum, either directly or through @@ -278,7 +200,7 @@ public class AltosUI extends JFrame { }); menu.add(item); - item = new JMenuItem("Flash Image",KeyEvent.VK_F); + item = new JMenuItem("Flash Image",KeyEvent.VK_I); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FlashImage(); @@ -286,7 +208,7 @@ public class AltosUI extends JFrame { }); menu.add(item); - item = new JMenuItem("Export Data",KeyEvent.VK_F); + item = new JMenuItem("Export Data",KeyEvent.VK_E); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ExportData(); @@ -294,7 +216,7 @@ public class AltosUI extends JFrame { }); menu.add(item); - item = new JMenuItem("Graph Data",KeyEvent.VK_F); + item = new JMenuItem("Graph Data",KeyEvent.VK_G); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GraphData(); @@ -307,6 +229,7 @@ public class AltosUI extends JFrame { ActionEvent.CTRL_MASK)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + System.out.printf("exiting\n"); System.exit(0); } }); @@ -314,7 +237,7 @@ public class AltosUI extends JFrame { } // Device menu - { + if (false) { menu = new JMenu("Device"); menu.setMnemonic(KeyEvent.VK_D); menubar.add(menu); @@ -327,14 +250,6 @@ public class AltosUI extends JFrame { }); menu.add(item); - item = new JMenuItem("Disconnect from Device",KeyEvent.VK_D); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - DisconnectFromDevice(); - } - }); - menu.add(item); - menu.addSeparator(); item = new JMenuItem("Set Callsign",KeyEvent.VK_S); @@ -403,23 +318,7 @@ public class AltosUI extends JFrame { }); menu.add(item); } - - // Channel menu - { - menu = new AltosChannelMenu(AltosPreferences.channel()); - menu.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - int new_channel = Integer.parseInt(e.getActionCommand()); - AltosPreferences.set_channel(new_channel); - serial_line.set_channel(new_channel); - } - }); - menu.setMnemonic(KeyEvent.VK_C); - menubar.add(menu); - } - this.setJMenuBar(menubar); - } static AltosRecordIterable open_logfile(String filename) { @@ -510,6 +409,10 @@ public class AltosUI extends JFrame { } else { AltosUI altosui = new AltosUI(); altosui.setVisible(true); + + AltosDevice[] devices = AltosDevice.list(AltosDevice.product_basestation); + for (int i = 0; i < devices.length; i++) + altosui.telemetry_window(devices[i]); } } } diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 2f4ed6d8..2322b93f 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -29,7 +29,9 @@ altosui_JAVA = \ AltosFlash.java \ AltosFlashUI.java \ AltosFlightInfoTableModel.java \ + AltosFlightReader.java \ AltosFlightStatusTableModel.java \ + AltosFlightUI.java \ AltosGPS.java \ AltosGreatCircle.java \ AltosHexfile.java \ @@ -44,7 +46,8 @@ altosui_JAVA = \ AltosReader.java \ AltosRecord.java \ AltosRecordIterable.java \ - AltosReplayThread.java \ + AltosTelemetryReader.java \ + AltosReplayReader.java \ AltosRomconfig.java \ AltosRomconfigUI.java \ AltosSerial.java \ -- cgit v1.2.3 From 6b17d276271faa8a420a1c8f6be17faaa0c7043c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 8 Nov 2010 22:07:04 -0800 Subject: altosui: Create buttons for main actions Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 97 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 19 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index e1bbee30..ded9e733 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -83,6 +83,27 @@ public class AltosUI extends JFrame { } } + Container pane; + GridBagLayout gridbag; + + JButton addButton(int x, int y, String label) { + GridBagConstraints c; + JButton b; + + c = new GridBagConstraints(); + c.gridx = x; c.gridy = y; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + c.weighty = 1; + b = new JButton(label); + + Dimension ps = b.getPreferredSize(); + + gridbag.setConstraints(b, c); + add(b, c); + return b; + } + public AltosUI() { load_library(null); @@ -93,13 +114,67 @@ public class AltosUI extends JFrame { AltosPreferences.init(this); + pane = getContentPane(); + gridbag = new GridBagLayout(); + pane.setLayout(gridbag); + + JButton b; + + b = addButton(0, 0, "Monitor Flight"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ConnectToDevice(); + } + }); + b = addButton(1, 0, "Save Flight Data"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + SaveFlightData(); + } + }); + b = addButton(2, 0, "Replay Flight"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Replay(); + } + }); + b = addButton(0, 1, "Graph Data"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + GraphData(); + } + }); + b = addButton(1, 1, "Export Data"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ExportData(); + } + }); + b = addButton(2, 1, "Configure TeleMetrum"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ConfigureTeleMetrum(); + } + }); + setTitle("AltOS"); createMenu(); - int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); - this.setSize(new Dimension (300, 100)); - this.validate(); + pane.doLayout(); + pane.validate(); + + doLayout(); + validate(); + + setVisible(true); + + Insets i = getInsets(); + Dimension ps = rootPane.getPreferredSize(); + ps.width += i.left + i.right; + ps.height += i.top + i.bottom; + setPreferredSize(ps); + setSize(ps); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override @@ -184,22 +259,6 @@ public class AltosUI extends JFrame { menu.setMnemonic(KeyEvent.VK_F); menubar.add(menu); - item = new JMenuItem("Replay File",KeyEvent.VK_R); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - Replay(); - } - }); - menu.add(item); - - item = new JMenuItem("Save Flight Data",KeyEvent.VK_S); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - SaveFlightData(); - } - }); - menu.add(item); - item = new JMenuItem("Flash Image",KeyEvent.VK_I); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { -- cgit v1.2.3 From 94f4a50d6430cc8280cbdaa9f39d3cb858d0e077 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 8 Nov 2010 22:10:46 -0800 Subject: altosui: Fix channel setting at serial open time Was using the previous non-device-specific preferences API. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index f65e44d6..d6848e57 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -193,7 +193,7 @@ public class AltosSerial implements Runnable { print("~\nE 0\n"); flush_output(); set_monitor(monitor_mode); - set_channel(AltosPreferences.channel()); + set_channel(AltosPreferences.channel(device.getSerial())); set_callsign(AltosPreferences.callsign()); } -- cgit v1.2.3 From a0a92c605e238277c9881545a7226e53b5dbc295 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 8 Nov 2010 22:17:26 -0800 Subject: altosui: Fix more calls to AltosPreferences.channel() Oops. Two more. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 2 +- ao-tools/altosui/AltosEepromDownload.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 7b6cd78c..7fecff0e 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -122,7 +122,7 @@ public class AltosConfig implements Runnable, ActionListener { void start_serial() throws InterruptedException { if (remote) { - serial_line.set_channel(AltosPreferences.channel()); + serial_line.set_channel(AltosPreferences.channel(device.getSerial())); serial_line.set_callsign(AltosPreferences.callsign()); serial_line.printf("p\n"); serial_line.flush_input(); diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index a7f64904..8efc94d2 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -224,7 +224,7 @@ public class AltosEepromDownload implements Runnable { public void run () { if (remote) { - serial_line.set_channel(AltosPreferences.channel()); + serial_line.set_channel(AltosPreferences.channel(device.getSerial())); serial_line.set_callsign(AltosPreferences.callsign()); serial_line.printf("p\nE 0\n"); serial_line.flush_input(); -- cgit v1.2.3 From eb77e806ded99532dc7eaa39c1893f075b028af6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 9 Nov 2010 10:21:34 -0800 Subject: altosui: Create abstract interface for flight data display This allows the implementation of the flight data display to occur in the flight UI instead of the display thread. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDisplayThread.java | 16 ++++++---------- ao-tools/altosui/AltosFlightDisplay.java | 24 ++++++++++++++++++++++++ ao-tools/altosui/AltosFlightUI.java | 13 +++++++++++-- ao-tools/altosui/Makefile.am | 1 + 4 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 ao-tools/altosui/AltosFlightDisplay.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDisplayThread.java b/ao-tools/altosui/AltosDisplayThread.java index b15472ed..957ac0d6 100644 --- a/ao-tools/altosui/AltosDisplayThread.java +++ b/ao-tools/altosui/AltosDisplayThread.java @@ -36,8 +36,7 @@ public class AltosDisplayThread extends Thread { String name; AltosFlightReader reader; int crc_errors; - AltosStatusTable flightStatus; - AltosInfoTable flightInfo; + AltosFlightDisplay display; class IdleThread extends Thread { @@ -182,10 +181,8 @@ public class AltosDisplayThread extends Thread { } void show(AltosState state, int crc_errors) { - if (state != null) { - flightStatus.set(state); - flightInfo.show(state, crc_errors); - } + if (state != null) + display.show(state, crc_errors); } public void run() { @@ -197,7 +194,7 @@ public class AltosDisplayThread extends Thread { idle_thread = new IdleThread(); - flightInfo.clear(); + display.reset(); try { for (;;) { try { @@ -235,11 +232,10 @@ public class AltosDisplayThread extends Thread { } } - public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosStatusTable in_status, AltosInfoTable in_info, AltosFlightReader in_reader) { + public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosFlightDisplay in_display, AltosFlightReader in_reader) { parent = in_parent; voice = in_voice; - flightStatus = in_status; - flightInfo = in_info; + display = in_display; reader = in_reader; } } diff --git a/ao-tools/altosui/AltosFlightDisplay.java b/ao-tools/altosui/AltosFlightDisplay.java new file mode 100644 index 00000000..d18d1d1f --- /dev/null +++ b/ao-tools/altosui/AltosFlightDisplay.java @@ -0,0 +1,24 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +public interface AltosFlightDisplay { + void reset(); + + void show(AltosState state, int crc_errors); +} diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 84ba9dca..11fc2442 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -28,7 +28,7 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -public class AltosFlightUI extends JFrame { +public class AltosFlightUI extends JFrame implements AltosFlightDisplay { String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; Object[][] statusData = { { "0", "pad", "-50", "0" } }; @@ -62,6 +62,15 @@ public class AltosFlightUI extends JFrame { stop_display(); } + public void reset() { + flightInfo.clear(); + } + + public void show(AltosState state, int crc_errors) { + flightStatus.set(state); + flightInfo.show(state, crc_errors); + } + public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { voice = in_voice; reader = in_reader; @@ -117,7 +126,7 @@ public class AltosFlightUI extends JFrame { this.setVisible(true); - thread = new AltosDisplayThread(this, voice, flightStatus, flightInfo, reader); + thread = new AltosDisplayThread(this, voice, this, reader); thread.start(); } diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 2322b93f..ccb88ed1 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -28,6 +28,7 @@ altosui_JAVA = \ AltosFile.java \ AltosFlash.java \ AltosFlashUI.java \ + AltosFlightDisplay.java \ AltosFlightInfoTableModel.java \ AltosFlightReader.java \ AltosFlightStatusTableModel.java \ -- cgit v1.2.3 From 22d00785188a880700cd372528189a7a15278da9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 9 Nov 2010 14:40:58 -0800 Subject: altosui: Add tab UI with 'pad' mode. This creates a multi-tab interface for flight monitoring and includes a special tab for 'pad' mode. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlightUI.java | 16 ++- ao-tools/altosui/AltosLed.java | 54 ++++++++ ao-tools/altosui/AltosLights.java | 72 +++++++++++ ao-tools/altosui/AltosPad.java | 249 ++++++++++++++++++++++++++++++++++++ ao-tools/altosui/Makefile.am | 24 +++- icon/grayled.png | Bin 0 -> 1528 bytes icon/grayon.png | Bin 0 -> 1873 bytes icon/greenled.png | Bin 0 -> 2281 bytes icon/greenoff.png | Bin 0 -> 1811 bytes icon/redled.png | Bin 0 -> 2103 bytes icon/redoff.png | Bin 0 -> 1694 bytes 11 files changed, 410 insertions(+), 5 deletions(-) create mode 100644 ao-tools/altosui/AltosLed.java create mode 100644 ao-tools/altosui/AltosLights.java create mode 100644 ao-tools/altosui/AltosPad.java create mode 100644 icon/grayled.png create mode 100644 icon/grayon.png create mode 100644 icon/greenled.png create mode 100644 icon/greenoff.png create mode 100644 icon/redled.png create mode 100644 icon/redoff.png (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 11fc2442..a7caf7e9 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -37,6 +37,11 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { AltosDisplayThread thread; private Box vbox; + + JTabbedPane pane; + + AltosPad pad; + private AltosStatusTable flightStatus; private AltosInfoTable flightInfo; @@ -63,10 +68,12 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { } public void reset() { + pad.reset(); flightInfo.clear(); } public void show(AltosState state, int crc_errors) { + pad.show(state, crc_errors); flightStatus.set(state); flightInfo.show(state, crc_errors); } @@ -86,8 +93,15 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { vbox = new Box (BoxLayout.Y_AXIS); vbox.add(flightStatus); + pane = new JTabbedPane(); + + pad = new AltosPad(); + pane.add("Launch Pad", pad); + flightInfo = new AltosInfoTable(); - vbox.add(flightInfo.box()); + pane.add("Table", flightInfo.box()); + + vbox.add(pane); this.add(vbox); diff --git a/ao-tools/altosui/AltosLed.java b/ao-tools/altosui/AltosLed.java new file mode 100644 index 00000000..e08e9960 --- /dev/null +++ b/ao-tools/altosui/AltosLed.java @@ -0,0 +1,54 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosLed extends JLabel { + ImageIcon on, off; + + ImageIcon create_icon(String path) { + java.net.URL imgURL = AltosUI.class.getResource(path); + if (imgURL != null) + return new ImageIcon(imgURL); + System.err.printf("Cannot find icon \"%s\"\n", path); + return null; + } + + public void set(boolean set) { + if (set) + setIcon(on); + else + setIcon(off); + } + + public AltosLed(String on_path, String off_path) { + on = create_icon(on_path); + off = create_icon(off_path); + setIcon(off); + } +} diff --git a/ao-tools/altosui/AltosLights.java b/ao-tools/altosui/AltosLights.java new file mode 100644 index 00000000..2d2a1938 --- /dev/null +++ b/ao-tools/altosui/AltosLights.java @@ -0,0 +1,72 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosLights extends JComponent { + + GridBagLayout gridbag; + + AltosLed red, green; + + ImageIcon create_icon(String path, String description) { + java.net.URL imgURL = AltosUI.class.getResource(path); + if (imgURL != null) + return new ImageIcon(imgURL, description); + System.err.printf("Cannot find icon \"%s\"\n", path); + return null; + } + + public void set (boolean on) { + if (on) { + red.set(false); + green.set(true); + } else { + red.set(true); + green.set(false); + } + } + + public AltosLights() { + GridBagConstraints c; + gridbag = new GridBagLayout(); + setLayout(gridbag); + + c = new GridBagConstraints(); + red = new AltosLed("/redled.png", "/redoff.png"); + c.gridx = 0; c.gridy = 0; + gridbag.setConstraints(red, c); + add(red); + red.set(true); + green = new AltosLed("/greenled.png", "/greenoff.png"); + c.gridx = 1; c.gridy = 0; + gridbag.setConstraints(green, c); + add(green); + green.set(false); + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosPad.java b/ao-tools/altosui/AltosPad.java new file mode 100644 index 00000000..133dbed3 --- /dev/null +++ b/ao-tools/altosui/AltosPad.java @@ -0,0 +1,249 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosPad extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + Font label_font; + Font value_font; + + public class LaunchStatus { + JLabel label; + JLabel value; + AltosLights lights; + + void show(AltosState state, int crc_errors) {} + void reset() { + value.setText("0"); + lights.set(false); + } + + public LaunchStatus (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + + lights = new AltosLights(); + c.gridx = 0; c.gridy = y; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.CENTER; + layout.setConstraints(lights, c); + add(lights); + + label = new JLabel(text); + label.setFont(label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.WEST; + layout.setConstraints(label, c); + add(label); + + value = new JLabel("4.00"); + value.setFont(label_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.EAST; + layout.setConstraints(value, c); + add(value); + + } + } + + public class LaunchValue { + JLabel label; + JLabel value; + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText("0"); + } + public LaunchValue (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + + label = new JLabel(text); + label.setFont(label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.WEST; + layout.setConstraints(label, c); + add(label); + + value = new JLabel("4.00"); + value.setFont(label_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.EAST; + layout.setConstraints(value, c); + add(value); + } + } + + class Battery extends LaunchStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.battery)); + lights.set(state.battery > 3.7); + } + public Battery (GridBagLayout layout, int y) { + super(layout, y, "Battery Voltage"); + } + } + + Battery battery; + + class Apogee extends LaunchStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.drogue_sense)); + lights.set(state.drogue_sense > 3.2); + } + public Apogee (GridBagLayout layout, int y) { + super(layout, y, "Apogee Igniter Voltage"); + } + } + + Apogee apogee; + + class Main extends LaunchStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.main_sense)); + lights.set(state.main_sense > 3.2); + } + public Main (GridBagLayout layout, int y) { + super(layout, y, "Main Igniter Voltage"); + } + } + + Main main; + + class GPS extends LaunchStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4d sats", state.gps.nsat)); + lights.set(state.gps_ready); + } + public GPS (GridBagLayout layout, int y) { + super (layout, y, "GPS Status"); + } + } + + GPS gps; + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } + + class PadLat extends LaunchValue { + void show (AltosState state, int crc_errors) { + value.setText(pos(state.pad_lat,"N", "S")); + } + public PadLat (GridBagLayout layout, int y) { + super (layout, y, "Pad Latitude"); + } + } + + PadLat pad_lat; + + class PadLon extends LaunchValue { + void show (AltosState state, int crc_errors) { + value.setText(pos(state.pad_lon,"E", "W")); + } + public PadLon (GridBagLayout layout, int y) { + super (layout, y, "Pad Longitude"); + } + } + + PadLon pad_lon; + + class PadAlt extends LaunchValue { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.0f m", state.pad_alt)); + } + public PadAlt (GridBagLayout layout, int y) { + super (layout, y, "Pad Altitude"); + } + } + + PadAlt pad_alt; + + public void reset() { + battery.reset(); + apogee.reset(); + main.reset(); + gps.reset(); + pad_lat.reset(); + pad_lon.reset(); + pad_alt.reset(); + } + + public void show(AltosState state, int crc_errors) { + battery.show(state, crc_errors); + apogee.show(state, crc_errors); + main.show(state, crc_errors); + gps.show(state, crc_errors); + pad_lat.show(state, crc_errors); + pad_lon.show(state, crc_errors); + pad_alt.show(state, crc_errors); + } + + public AltosPad() { + layout = new GridBagLayout(); + + GridBagConstraints c; + + label_font = new Font("Dialog", Font.PLAIN, 24); + value_font = new Font("Monospaced", Font.PLAIN, 24); + setLayout(layout); + + c = new GridBagConstraints(); + /* Elements in pad display: + * + * Battery voltage + * Igniter continuity + * GPS lock status and location + * Pad altitude + * RSSI + */ + battery = new Battery(layout, 0); + apogee = new Apogee(layout, 1); + main = new Main(layout, 2); + gps = new GPS(layout, 3); + pad_lat = new PadLat(layout, 4); + pad_lon = new PadLon(layout, 5); + pad_alt = new PadAlt(layout, 6); + } +} diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index ccb88ed1..ab9cf201 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -39,9 +39,12 @@ altosui_JAVA = \ Altos.java \ AltosInfoTable.java \ AltosKML.java \ + AltosLed.java \ + AltosLights.java \ AltosLine.java \ AltosLogfileChooser.java \ AltosLog.java \ + AltosPad.java \ AltosParse.java \ AltosPreferences.java \ AltosReader.java \ @@ -92,8 +95,21 @@ JAR=altosui.jar FATJAR=altosui-fat.jar # Icons -JAVA_ICON=$(top_srcdir)/icon/altus-metrum-16x16.jpg -WINDOWS_ICON=$(top_srcdir)/icon/altus-metrum.ico +ICONDIR=$(top_srcdir)/icon + +JAVA_ICON=$(ICONDIR)/altus-metrum-16x16.jpg + +ICONS= $(ICONDIR)/redled.png $(ICONDIR)/redoff.png \ + $(ICONDIR)/greenled.png $(ICONDIR)/greenoff.png \ + $(ICONDIR)/grayled.png $(ICONDIR)/grayoff.png + +# icon base names for jar +ICONJAR= -C $(ICONDIR) altus-metrum-16x16.jpg \ + -C $(ICONDIR) redled.png -C $(ICONDIR) redoff.png \ + -C $(ICONDIR) greenled.png -C $(ICONDIR) greenoff.png \ + -C $(ICONDIR) grayon.png -C $(ICONDIR) grayled.png + +WINDOWS_ICON=$(ICONDIR)/altus-metrum.ico # Firmware FIRMWARE_TD=$(top_srcdir)/src/teledongle-v0.2-$(VERSION).ihx @@ -163,13 +179,13 @@ classes/altosui: $(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) jar cfm $@ Manifest.txt \ - -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ + $(ICONJAR) \ -C classes altosui \ -C ../libaltos libaltosJNI $(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) $(JAVA_ICON) jar cfm $@ Manifest-fat.txt \ - -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ + $(ICONJAR) \ -C classes altosui \ -C ../libaltos libaltosJNI diff --git a/icon/grayled.png b/icon/grayled.png new file mode 100644 index 00000000..bb6005c6 Binary files /dev/null and b/icon/grayled.png differ diff --git a/icon/grayon.png b/icon/grayon.png new file mode 100644 index 00000000..c99b376e Binary files /dev/null and b/icon/grayon.png differ diff --git a/icon/greenled.png b/icon/greenled.png new file mode 100644 index 00000000..d7663961 Binary files /dev/null and b/icon/greenled.png differ diff --git a/icon/greenoff.png b/icon/greenoff.png new file mode 100644 index 00000000..c3cf8491 Binary files /dev/null and b/icon/greenoff.png differ diff --git a/icon/redled.png b/icon/redled.png new file mode 100644 index 00000000..230afae0 Binary files /dev/null and b/icon/redled.png differ diff --git a/icon/redoff.png b/icon/redoff.png new file mode 100644 index 00000000..a251402f Binary files /dev/null and b/icon/redoff.png differ -- cgit v1.2.3 From b0d31910da592e2f67c47c8fc3e15ce8135d5094 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 9 Nov 2010 23:34:32 -0800 Subject: altosui: Add ascent, descent and landed tabs This completes the set of tabs for in-flight status information. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosAscent.java | 250 +++++++++++++++++++++++++++++++ ao-tools/altosui/AltosDescent.java | 211 ++++++++++++++++++++++++++ ao-tools/altosui/AltosDisplayThread.java | 14 +- ao-tools/altosui/AltosFlightUI.java | 52 +++++++ ao-tools/altosui/AltosLanded.java | 208 +++++++++++++++++++++++++ ao-tools/altosui/AltosLights.java | 1 + ao-tools/altosui/AltosPad.java | 18 +-- ao-tools/altosui/AltosState.java | 1 + ao-tools/altosui/Makefile.am | 3 + 9 files changed, 743 insertions(+), 15 deletions(-) create mode 100644 ao-tools/altosui/AltosAscent.java create mode 100644 ao-tools/altosui/AltosDescent.java create mode 100644 ao-tools/altosui/AltosLanded.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java new file mode 100644 index 00000000..40df7af8 --- /dev/null +++ b/ao-tools/altosui/AltosAscent.java @@ -0,0 +1,250 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosAscent extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + Font label_font; + Font value_font; + + public class AscentValue { + JLabel label; + JTextField value; + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + } + public AscentValue (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + + label = new JLabel(text); + label.setFont(label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 0; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(20); + value.setFont(label_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 1; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridwidth = 2; + layout.setConstraints(value, c); + add(value); + } + } + + public class AscentValueHold { + JLabel label; + JTextField value; + JTextField max_value; + double max; + + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + max_value.setText(""); + max = 0; + } + + void show(String format, double v) { + value.setText(String.format(format, v)); + if (v > max) { + max_value.setText(String.format(format, v)); + max = v; + } + } + public AscentValueHold (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + + label = new JLabel(text); + label.setFont(label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 0; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(10); + value.setFont(label_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 1; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + layout.setConstraints(value, c); + add(value); + + max_value = new JTextField(10); + max_value.setFont(label_font); + max_value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + layout.setConstraints(max_value, c); + add(max_value); + } + } + + + class Height extends AscentValueHold { + void show (AltosState state, int crc_errors) { + show("%6.0f m", state.height); + } + public Height (GridBagLayout layout, int y) { + super (layout, y, "Height"); + } + } + + Height height; + + class Speed extends AscentValueHold { + void show (AltosState state, int crc_errors) { + double speed = state.speed; + if (!state.ascent) + speed = state.baro_speed; + show("%6.0f m/s", speed); + } + public Speed (GridBagLayout layout, int y) { + super (layout, y, "Speed"); + } + } + + Speed speed; + + class Accel extends AscentValueHold { + void show (AltosState state, int crc_errors) { + show("%6.0f m/s²", state.acceleration); + } + public Accel (GridBagLayout layout, int y) { + super (layout, y, "Acceleration"); + } + } + + Accel accel; + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } + + class Lat extends AscentValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lat,"N", "S")); + else + value.setText("???"); + } + public Lat (GridBagLayout layout, int y) { + super (layout, y, "Latitude"); + } + } + + Lat lat; + + class Lon extends AscentValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lon,"E", "W")); + else + value.setText("???"); + } + public Lon (GridBagLayout layout, int y) { + super (layout, y, "Longitude"); + } + } + + Lon lon; + + public void reset() { + lat.reset(); + lon.reset(); + height.reset(); + speed.reset(); + accel.reset(); + } + + public void show(AltosState state, int crc_errors) { + lat.show(state, crc_errors); + lon.show(state, crc_errors); + height.show(state, crc_errors); + speed.show(state, crc_errors); + accel.show(state, crc_errors); + } + + public void labels(GridBagLayout layout, int y) { + GridBagConstraints c; + JLabel cur, max; + + cur = new JLabel("Current"); + cur.setFont(label_font); + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + layout.setConstraints(cur, c); + add(cur); + + max = new JLabel("Maximum"); + max.setFont(label_font); + c.gridx = 2; c.gridy = y; + layout.setConstraints(max, c); + add(max); + } + + public AltosAscent() { + layout = new GridBagLayout(); + + label_font = new Font("Dialog", Font.PLAIN, 24); + value_font = new Font("Monospace", Font.PLAIN, 24); + setLayout(layout); + + /* Elements in ascent display: + * + * lat + * lon + * height + */ + labels(layout, 0); + height = new Height(layout, 1); + speed = new Speed(layout, 2); + accel = new Accel(layout, 3); + lat = new Lat(layout, 4); + lon = new Lon(layout, 5); + } +} diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java new file mode 100644 index 00000000..0d3d17f0 --- /dev/null +++ b/ao-tools/altosui/AltosDescent.java @@ -0,0 +1,211 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosDescent extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + Font label_font; + Font value_font; + + public class DescentValue { + JLabel label; + JTextField value; + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + } + + void show(String format, double v) { + value.setText(String.format(format, v)); + } + + public DescentValue (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + + label = new JLabel(text); + label.setFont(label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 0; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(20); + value.setFont(label_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 1; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.HORIZONTAL; + layout.setConstraints(value, c); + add(value); + } + } + + class Height extends DescentValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m", state.height); + } + public Height (GridBagLayout layout, int y) { + super (layout, y, "Height"); + } + } + + Height height; + + class Speed extends DescentValue { + void show (AltosState state, int crc_errors) { + double speed = state.speed; + if (!state.ascent) + speed = state.baro_speed; + show("%6.0f m/s", speed); + } + public Speed (GridBagLayout layout, int y) { + super (layout, y, "Speed"); + } + } + + Speed speed; + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } + + class Lat extends DescentValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lat,"N", "S")); + else + value.setText("???"); + } + public Lat (GridBagLayout layout, int y) { + super (layout, y, "Latitude"); + } + } + + Lat lat; + + class Lon extends DescentValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lon,"E", "W")); + else + value.setText("???"); + } + public Lon (GridBagLayout layout, int y) { + super (layout, y, "Longitude"); + } + } + + Lon lon; + + class Bearing extends DescentValue { + void show (AltosState state, int crc_errors) { + if (state.from_pad != null) + show("%3.0f°", state.from_pad.bearing); + else + value.setText("???"); + } + public Bearing (GridBagLayout layout, int y) { + super (layout, y, "Bearing"); + } + } + + Bearing bearing; + + class Elevation extends DescentValue { + void show (AltosState state, int crc_errors) { + if (state.from_pad != null) + show("%3.0f°", state.elevation); + else + value.setText("???"); + } + public Elevation (GridBagLayout layout, int y) { + super (layout, y, "Elevation"); + } + } + + Elevation elevation; + + class Range extends DescentValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m", state.range); + } + public Range (GridBagLayout layout, int y) { + super (layout, y, "Range"); + } + } + + Range range; + + public void reset() { + lat.reset(); + lon.reset(); + height.reset(); + speed.reset(); + bearing.reset(); + elevation.reset(); + range.reset(); + } + + public void show(AltosState state, int crc_errors) { + height.show(state, crc_errors); + speed.show(state, crc_errors); + bearing.show(state, crc_errors); + elevation.show(state, crc_errors); + range.show(state, crc_errors); + lat.show(state, crc_errors); + lon.show(state, crc_errors); + } + + public AltosDescent() { + layout = new GridBagLayout(); + + label_font = new Font("Dialog", Font.PLAIN, 24); + value_font = new Font("Monospace", Font.PLAIN, 24); + setLayout(layout); + + /* Elements in descent display */ + speed = new Speed(layout, 0); + height = new Height(layout, 1); + bearing = new Bearing(layout, 2); + elevation = new Elevation(layout, 3); + range = new Range(layout, 4); + lat = new Lat(layout, 5); + lon = new Lon(layout, 6); + } +} diff --git a/ao-tools/altosui/AltosDisplayThread.java b/ao-tools/altosui/AltosDisplayThread.java index 957ac0d6..b5b2777e 100644 --- a/ao-tools/altosui/AltosDisplayThread.java +++ b/ao-tools/altosui/AltosDisplayThread.java @@ -38,6 +38,11 @@ public class AltosDisplayThread extends Thread { int crc_errors; AltosFlightDisplay display; + synchronized void show(AltosState state, int crc_errors) { + if (state != null) + display.show(state, crc_errors); + } + class IdleThread extends Thread { boolean started; @@ -93,6 +98,10 @@ public class AltosDisplayThread extends Thread { (int) (state.from_pad.bearing + 0.5), (int) (state.from_pad.distance + 0.5)); ++reported_landing; + if (state.state != Altos.ao_flight_landed) { + state.state = Altos.ao_flight_landed; + show(state, 0); + } } } @@ -180,11 +189,6 @@ public class AltosDisplayThread extends Thread { return ret; } - void show(AltosState state, int crc_errors) { - if (state != null) - display.show(state, crc_errors); - } - public void run() { boolean interrupted = false; String line; diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index a7caf7e9..558b0395 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -41,10 +41,30 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { JTabbedPane pane; AltosPad pad; + AltosAscent ascent; + AltosDescent descent; + AltosLanded landed; private AltosStatusTable flightStatus; private AltosInfoTable flightInfo; + static final int tab_pad = 1; + static final int tab_ascent = 2; + static final int tab_descent = 3; + static final int tab_landed = 4; + + int cur_tab = 0; + + int which_tab(AltosState state) { + if (state.state < Altos.ao_flight_boost) + return tab_pad; + if (state.state <= Altos.ao_flight_coast) + return tab_ascent; + if (state.state <= Altos.ao_flight_main) + return tab_descent; + return tab_landed; + } + public int width() { return flightInfo.width(); } @@ -69,11 +89,34 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { public void reset() { pad.reset(); + ascent.reset(); + descent.reset(); + landed.reset(); flightInfo.clear(); } public void show(AltosState state, int crc_errors) { + int tab = which_tab(state); pad.show(state, crc_errors); + ascent.show(state, crc_errors); + descent.show(state, crc_errors); + landed.show(state, crc_errors); + if (tab != cur_tab) { + switch (tab) { + case tab_pad: + pane.setSelectedComponent(pad); + break; + case tab_ascent: + pane.setSelectedComponent(ascent); + break; + case tab_descent: + pane.setSelectedComponent(descent); + break; + case tab_landed: + pane.setSelectedComponent(landed); + } + cur_tab = tab; + } flightStatus.set(state); flightInfo.show(state, crc_errors); } @@ -98,6 +141,15 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { pad = new AltosPad(); pane.add("Launch Pad", pad); + ascent = new AltosAscent(); + pane.add("Ascent", ascent); + + descent = new AltosDescent(); + pane.add("Descent", descent); + + landed = new AltosLanded(); + pane.add("Landed", landed); + flightInfo = new AltosInfoTable(); pane.add("Table", flightInfo.box()); diff --git a/ao-tools/altosui/AltosLanded.java b/ao-tools/altosui/AltosLanded.java new file mode 100644 index 00000000..4b74aaa3 --- /dev/null +++ b/ao-tools/altosui/AltosLanded.java @@ -0,0 +1,208 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosLanded extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + Font label_font; + Font value_font; + + public class LandedValue { + JLabel label; + JTextField value; + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + } + + void show(String format, double v) { + value.setText(String.format(format, v)); + } + + public LandedValue (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + + label = new JLabel(text); + label.setFont(label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 0; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(20); + value.setFont(label_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 1; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.HORIZONTAL; + layout.setConstraints(value, c); + add(value); + } + } + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } + + class Lat extends LandedValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lat,"N", "S")); + else + value.setText("???"); + } + public Lat (GridBagLayout layout, int y) { + super (layout, y, "Latitude"); + } + } + + Lat lat; + + class Lon extends LandedValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lon,"E", "W")); + else + value.setText("???"); + } + public Lon (GridBagLayout layout, int y) { + super (layout, y, "Longitude"); + } + } + + Lon lon; + + class Bearing extends LandedValue { + void show (AltosState state, int crc_errors) { + if (state.from_pad != null) + show("%3.0f°", state.from_pad.bearing); + else + value.setText("???"); + } + public Bearing (GridBagLayout layout, int y) { + super (layout, y, "Bearing"); + } + } + + Bearing bearing; + + class Distance extends LandedValue { + void show (AltosState state, int crc_errors) { + if (state.from_pad != null) + show("%6.0f m", state.from_pad.distance); + else + value.setText("???"); + } + public Distance (GridBagLayout layout, int y) { + super (layout, y, "Distance"); + } + } + + Distance distance; + + class Height extends LandedValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m", state.max_height); + } + public Height (GridBagLayout layout, int y) { + super (layout, y, "Maximum Height"); + } + } + + Height height; + + class Speed extends LandedValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m/s", state.max_speed); + } + public Speed (GridBagLayout layout, int y) { + super (layout, y, "Maximum Speed"); + } + } + + Speed speed; + + class Accel extends LandedValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m/s²", state.max_acceleration); + } + public Accel (GridBagLayout layout, int y) { + super (layout, y, "Maximum Acceleration"); + } + } + + Accel accel; + + public void reset() { + lat.reset(); + lon.reset(); + bearing.reset(); + distance.reset(); + height.reset(); + speed.reset(); + accel.reset(); + } + + public void show(AltosState state, int crc_errors) { + bearing.show(state, crc_errors); + distance.show(state, crc_errors); + lat.show(state, crc_errors); + lon.show(state, crc_errors); + height.show(state, crc_errors); + speed.show(state, crc_errors); + accel.show(state, crc_errors); + } + + public AltosLanded() { + layout = new GridBagLayout(); + + label_font = new Font("Dialog", Font.PLAIN, 24); + value_font = new Font("Monospace", Font.PLAIN, 24); + setLayout(layout); + + /* Elements in descent display */ + bearing = new Bearing(layout, 0); + distance = new Distance(layout, 1); + lat = new Lat(layout, 2); + lon = new Lon(layout, 3); + height = new Height(layout, 4); + speed = new Speed(layout, 5); + accel = new Accel(layout, 6); + } +} diff --git a/ao-tools/altosui/AltosLights.java b/ao-tools/altosui/AltosLights.java index 2d2a1938..f1ed47c2 100644 --- a/ao-tools/altosui/AltosLights.java +++ b/ao-tools/altosui/AltosLights.java @@ -60,6 +60,7 @@ public class AltosLights extends JComponent { c = new GridBagConstraints(); red = new AltosLed("/redled.png", "/redoff.png"); c.gridx = 0; c.gridy = 0; + c.insets = new Insets (0, 5, 0, 5); gridbag.setConstraints(red, c); add(red); red.set(true); diff --git a/ao-tools/altosui/AltosPad.java b/ao-tools/altosui/AltosPad.java index 133dbed3..7b72be20 100644 --- a/ao-tools/altosui/AltosPad.java +++ b/ao-tools/altosui/AltosPad.java @@ -35,12 +35,12 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { public class LaunchStatus { JLabel label; - JLabel value; + JTextField value; AltosLights lights; void show(AltosState state, int crc_errors) {} void reset() { - value.setText("0"); + value.setText(""); lights.set(false); } @@ -64,12 +64,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JLabel("4.00"); + value = new JTextField(10); value.setFont(label_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.EAST; + c.anchor = GridBagConstraints.WEST; layout.setConstraints(value, c); add(value); @@ -78,11 +77,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { public class LaunchValue { JLabel label; - JLabel value; + JTextField value; void show(AltosState state, int crc_errors) {} void reset() { - value.setText("0"); + value.setText(""); } public LaunchValue (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); @@ -93,16 +92,15 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { c.gridx = 1; c.gridy = y; c.insets = new Insets(10, 10, 10, 10); c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.WEST; layout.setConstraints(label, c); add(label); - value = new JLabel("4.00"); + value = new JTextField(20); value.setFont(label_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.EAST; + c.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(value, c); add(value); } diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index 1048bb51..86eb636a 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -35,6 +35,7 @@ public class AltosState { int tick; int state; + boolean landed; boolean ascent; /* going up? */ double ground_altitude; diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index ab9cf201..267bae63 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -10,6 +10,7 @@ CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(FREETTS)/ bin_SCRIPTS=altosui altosui_JAVA = \ + AltosAscent.java \ AltosChannelMenu.java \ AltosConfig.java \ AltosConfigUI.java \ @@ -18,6 +19,7 @@ altosui_JAVA = \ AltosCSV.java \ AltosCSVUI.java \ AltosDebug.java \ + AltosDescent.java \ AltosDeviceDialog.java \ AltosDevice.java \ AltosDisplayThread.java \ @@ -39,6 +41,7 @@ altosui_JAVA = \ Altos.java \ AltosInfoTable.java \ AltosKML.java \ + AltosLanded.java \ AltosLed.java \ AltosLights.java \ AltosLine.java \ -- cgit v1.2.3 From b16b873723ee3e5097e6725c59ce191119439ad7 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 11 Nov 2010 15:38:27 +1000 Subject: use value_font for values --- ao-tools/altosui/AltosAscent.java | 14 +++++++------- ao-tools/altosui/AltosDescent.java | 6 +++--- ao-tools/altosui/AltosLanded.java | 6 +++--- ao-tools/altosui/AltosPad.java | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java index 40df7af8..51fa1a89 100644 --- a/ao-tools/altosui/AltosAscent.java +++ b/ao-tools/altosui/AltosAscent.java @@ -53,8 +53,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(20); - value.setFont(label_font); + value = new JTextField(30); + value.setFont(value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; @@ -98,16 +98,16 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(10); - value.setFont(label_font); + value = new JTextField(15); + value.setFont(value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.EAST; layout.setConstraints(value, c); add(value); - max_value = new JTextField(10); - max_value.setFont(label_font); + max_value = new JTextField(15); + max_value.setFont(value_font); max_value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.EAST; @@ -231,7 +231,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout = new GridBagLayout(); label_font = new Font("Dialog", Font.PLAIN, 24); - value_font = new Font("Monospace", Font.PLAIN, 24); + value_font = new Font("Monospaced", Font.PLAIN, 24); setLayout(layout); /* Elements in ascent display: diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index 0d3d17f0..0b7c8036 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -58,8 +58,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(20); - value.setFont(label_font); + value = new JTextField(30); + value.setFont(value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; @@ -196,7 +196,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { layout = new GridBagLayout(); label_font = new Font("Dialog", Font.PLAIN, 24); - value_font = new Font("Monospace", Font.PLAIN, 24); + value_font = new Font("Monospaced", Font.PLAIN, 24); setLayout(layout); /* Elements in descent display */ diff --git a/ao-tools/altosui/AltosLanded.java b/ao-tools/altosui/AltosLanded.java index 4b74aaa3..d170ccad 100644 --- a/ao-tools/altosui/AltosLanded.java +++ b/ao-tools/altosui/AltosLanded.java @@ -58,8 +58,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(20); - value.setFont(label_font); + value = new JTextField(30); + value.setFont(value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; @@ -193,7 +193,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { layout = new GridBagLayout(); label_font = new Font("Dialog", Font.PLAIN, 24); - value_font = new Font("Monospace", Font.PLAIN, 24); + value_font = new Font("Monospaced", Font.PLAIN, 24); setLayout(layout); /* Elements in descent display */ diff --git a/ao-tools/altosui/AltosPad.java b/ao-tools/altosui/AltosPad.java index 7b72be20..da047072 100644 --- a/ao-tools/altosui/AltosPad.java +++ b/ao-tools/altosui/AltosPad.java @@ -64,8 +64,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(10); - value.setFont(label_font); + value = new JTextField(15); + value.setFont(value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.WEST; @@ -95,8 +95,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(20); - value.setFont(label_font); + value = new JTextField(30); + value.setFont(value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.EAST; -- cgit v1.2.3 From 1f3e091efdfb2fe6f06a066cac60f5d267b94856 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 11 Nov 2010 15:40:37 +1000 Subject: add --replay command line argument --- ao-tools/altosui/AltosUI.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index ded9e733..2861444d 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -456,7 +456,26 @@ public class AltosUI extends JFrame { public static void main(final String[] args) { int process = 0; /* Handle batch-mode */ - if (args.length > 0) { + if (args.length == 2 && args[0].equals("--replay")) { + String filename = args[1]; + FileInputStream in; + try { + in = new FileInputStream(filename); + } catch (Exception e) { + System.out.printf("Failed to open file '%s'\n", filename); + return; + } + AltosRecordIterable recs; + AltosReplayReader reader; + if (filename.endsWith("eeprom")) { + recs = new AltosEepromIterable(in); + } else { + recs = new AltosTelemetryIterable(in); + } + reader = new AltosReplayReader(recs.iterator(), filename); + new AltosFlightUI(new AltosVoice(), reader); + return; + } else if (args.length > 0) { for (int i = 0; i < args.length; i++) { if (args[i].equals("--kml")) process |= process_kml; -- cgit v1.2.3 From 3ffaa5d1c00b28be20fd4a26deb7bd41d953e92a Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 11 Nov 2010 15:43:05 +1000 Subject: read preferences for --replay --- ao-tools/altosui/AltosFlightUI.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 558b0395..3581c54c 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -122,6 +122,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { } public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { + AltosPreferences.init(this); + voice = in_voice; reader = in_reader; -- cgit v1.2.3 From 8503943e3613f8670b128012b12ff14fb54321d7 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 11 Nov 2010 15:45:43 +1000 Subject: reduce font size for FlightInfoTable --- ao-tools/altosui/AltosInfoTable.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosInfoTable.java b/ao-tools/altosui/AltosInfoTable.java index 9964ab10..2f326e07 100644 --- a/ao-tools/altosui/AltosInfoTable.java +++ b/ao-tools/altosui/AltosInfoTable.java @@ -37,8 +37,8 @@ public class AltosInfoTable { private AltosFlightInfoTableModel model[]; private Box ibox[]; - private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14); - private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14); + private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 12); + private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 12); static final int info_columns = 3; static final int info_rows = 17; -- cgit v1.2.3 From 317ec72a34906faad88c6924e634617b074e71db Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 11 Nov 2010 15:52:01 +1000 Subject: use grayled.png for off --- ao-tools/altosui/AltosLights.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosLights.java b/ao-tools/altosui/AltosLights.java index f1ed47c2..2fa38412 100644 --- a/ao-tools/altosui/AltosLights.java +++ b/ao-tools/altosui/AltosLights.java @@ -58,16 +58,16 @@ public class AltosLights extends JComponent { setLayout(gridbag); c = new GridBagConstraints(); - red = new AltosLed("/redled.png", "/redoff.png"); + red = new AltosLed("/redled.png", "/grayled.png"); c.gridx = 0; c.gridy = 0; c.insets = new Insets (0, 5, 0, 5); gridbag.setConstraints(red, c); add(red); red.set(true); - green = new AltosLed("/greenled.png", "/greenoff.png"); + green = new AltosLed("/greenled.png", "/grayled.png"); c.gridx = 1; c.gridy = 0; gridbag.setConstraints(green, c); add(green); green.set(false); } -} \ No newline at end of file +} -- cgit v1.2.3 From cc0a730de093c49be2a921101d27622b6f592e92 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 11 Nov 2010 15:57:52 +1000 Subject: add compass bearing to voice output --- ao-tools/altosui/AltosDisplayThread.java | 4 +++- ao-tools/altosui/AltosGreatCircle.java | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDisplayThread.java b/ao-tools/altosui/AltosDisplayThread.java index b5b2777e..375965b9 100644 --- a/ao-tools/altosui/AltosDisplayThread.java +++ b/ao-tools/altosui/AltosDisplayThread.java @@ -69,8 +69,10 @@ public class AltosDisplayThread extends Thread { state.state < Altos.ao_flight_landed && state.range >= 0) { - voice.speak("Height %d, bearing %d, elevation %d, range %d.\n", + voice.speak("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)); diff --git a/ao-tools/altosui/AltosGreatCircle.java b/ao-tools/altosui/AltosGreatCircle.java index 07c02c16..aa6ae3b9 100644 --- a/ao-tools/altosui/AltosGreatCircle.java +++ b/ao-tools/altosui/AltosGreatCircle.java @@ -30,6 +30,31 @@ public class AltosGreatCircle { static final double rad = Math.PI / 180; static final double earth_radius = 6371.2 * 1000; /* in meters */ + static int BEARING_LONG = 0; + static int BEARING_SHORT = 1; + static int BEARING_VOICE = 2; + String bearing_words(int length) { + String [][] bearing_string = { + { + "North", "North North East", "North East", "East North East", + "East", "East South East", "South East", "South South East", + "South", "South South West", "South West", "West South West", + "West", "West North West", "North West", "North North West" + }, { + "N", "NNE", "NE", "ENE", + "E", "ESE", "SE", "SSE", + "S", "SSW", "SW", "WSW", + "W", "WNW", "NW", "NNW" + }, { + "north", "nor nor east", "north east", "east nor east", + "east", "east sow east", "south east", "sow sow east", + "south", "sow sow west", "south west", "west sow west", + "west", "west nor west", "north west", "nor nor west " + } + }; + return bearing_string[length][(int)((bearing / 90 * 8 + 1) / 2)%16]; + } + public AltosGreatCircle (double start_lat, double start_lon, double end_lat, double end_lon) { -- cgit v1.2.3 From 75f7698b99a661ed17a91748a99699fa6761772a Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 11 Nov 2010 16:06:32 +1000 Subject: add compass bearing during descent --- ao-tools/altosui/AltosDescent.java | 50 ++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index 0b7c8036..56d3e4fe 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -62,6 +62,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value.setFont(value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; + c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(value, c); @@ -133,15 +134,54 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { Lon lon; - class Bearing extends DescentValue { + class Bearing { + JLabel label; + JTextField value; + JTextField value_deg; + void reset () { + value.setText(""); + value_deg.setText(""); + } void show (AltosState state, int crc_errors) { - if (state.from_pad != null) - show("%3.0f°", state.from_pad.bearing); - else + if (state.from_pad != null) { + value.setText(state.from_pad.bearing_words( + AltosGreatCircle.BEARING_LONG)); + value_deg.setText(String.format("%3.0f°", state.from_pad.bearing)); + } else { value.setText("???"); + value_deg.setText("???"); + } } public Bearing (GridBagLayout layout, int y) { - super (layout, y, "Bearing"); + GridBagConstraints c = new GridBagConstraints(); + + label = new JLabel("Bearing"); + label.setFont(label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 0; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(30); + value.setFont(value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 1; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.HORIZONTAL; + layout.setConstraints(value, c); + add(value); + + value_deg = new JTextField(5); + value_deg.setFont(value_font); + value_deg.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.HORIZONTAL; + + layout.setConstraints(value_deg, c); + add(value_deg); } } -- cgit v1.2.3 From 81e7b43ecad666e2e2310c7c94184f888bc86585 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 12 Nov 2010 02:07:41 +1000 Subject: add site map tab, at least for QRS launches --- ao-tools/altosui/AltosFlightUI.java | 6 ++ ao-tools/altosui/AltosSiteMap.java | 137 ++++++++++++++++++++++++++++++++++++ ao-tools/altosui/Makefile.am | 1 + 3 files changed, 144 insertions(+) create mode 100644 ao-tools/altosui/AltosSiteMap.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 3581c54c..816ffa23 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -44,6 +44,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { AltosAscent ascent; AltosDescent descent; AltosLanded landed; + AltosSiteMap sitemap; private AltosStatusTable flightStatus; private AltosInfoTable flightInfo; @@ -93,6 +94,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { descent.reset(); landed.reset(); flightInfo.clear(); + sitemap.reset(); } public void show(AltosState state, int crc_errors) { @@ -119,6 +121,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { } flightStatus.set(state); flightInfo.show(state, crc_errors); + sitemap.show(state, crc_errors); } public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { @@ -155,6 +158,9 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { flightInfo = new AltosInfoTable(); pane.add("Table", flightInfo.box()); + sitemap = new AltosSiteMap(); + pane.add("Site Map", sitemap); + vbox.add(pane); this.add(vbox); diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java new file mode 100644 index 00000000..22b9aebe --- /dev/null +++ b/ao-tools/altosui/AltosSiteMap.java @@ -0,0 +1,137 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import javax.swing.*; +import javax.imageio.ImageIO; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.lang.Math; +import java.awt.geom.Point2D; +import java.awt.geom.Line2D; + +public class AltosSiteMap extends JComponent implements AltosFlightDisplay { + double lat, lng; + int zoom; + double scale_x, scale_y; + Point2D.Double coord_pt; + Point2D.Double last_pt; + + Graphics2D g2d; + + private void setLocation(double new_lat, double new_lng, int new_zoom) { + lat = new_lat; + lng = new_lng; + zoom = new_zoom; + scale_x = 256/360.0 * Math.pow(2, zoom); + scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + coord_pt = pt(lat, lng, new Point2D.Double(0,0)); + coord_pt.x = 320-coord_pt.x; + coord_pt.y = 320-coord_pt.y; + last_pt = null; + } + + private static double limit(double v, double lo, double hi) { + if (v < lo) + return lo; + if (hi < v) + return hi; + return v; + } + + // based on google js + // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js + // search for fromLatLngToPoint and fromPointToLatLng + private Point2D.Double pt(double lat, double lng) { + return pt(lat, lng, coord_pt); + } + + private Point2D.Double pt(double lat, double lng, Point2D.Double centre) { + Point2D.Double res = new Point2D.Double(); + double e; + + res.x = centre.x + lng*scale_x; + e = limit(Math.sin(Math.toRadians(lat)),-(1-1.0E-15),1-1.0E-15); + res.y = centre.y + 0.5*Math.log((1+e)/(1-e))*-scale_y; + return res; + } + + + public void reset() { + // ? + } + + static Color stateColors[] = { + Color.WHITE, // startup + Color.WHITE, // idle + Color.WHITE, // pad + Color.RED, // boost + Color.PINK, // fast + Color.YELLOW, // coast + Color.CYAN, // drogue + Color.BLUE, // main + Color.BLACK // landed + }; + + public void show(AltosState state, int crc_errors) { + if (!state.gps_ready) + return; + Point2D.Double pt = pt(state.gps.lat, state.gps.lon); + if (last_pt != null && pt != last_pt) { + if (0 <= state.state && state.state < stateColors.length) { + g2d.setColor(stateColors[state.state]); + } + g2d.draw(new Line2D.Double(last_pt, pt)); + } + last_pt = pt; + repaint(); + } + + public AltosSiteMap() { + GridBagLayout layout = new GridBagLayout(); + setLayout(layout); + + GridBagConstraints c = new GridBagConstraints(); + + setLocation(-27.850, 152.960, 15); + String pngfile = "/home/aj/qrs-S27.850,W152.960-15.png"; + + c.gridx = 0; c.gridy = 0; + c.weightx = 1; c.weighty = 1; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.BOTH; + + try { + BufferedImage myPicture = ImageIO.read(new File(pngfile)); + g2d = myPicture.createGraphics(); + JLabel picLabel = new JLabel(new ImageIcon( myPicture )); + JScrollPane scrollPane = new JScrollPane(picLabel); + layout.setConstraints(scrollPane, c); + add(scrollPane); + } catch (Exception e) { + throw new RuntimeException(e); + }; + } +} + diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 267bae63..fc532863 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -59,6 +59,7 @@ altosui_JAVA = \ AltosRomconfigUI.java \ AltosSerial.java \ AltosSerialMonitor.java \ + AltosSiteMap.java \ AltosState.java \ AltosStatusTable.java \ AltosTelemetry.java \ -- cgit v1.2.3 From 0327c1da01a3f6ede01f05c1d775651a57fd0c68 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 12 Nov 2010 02:08:58 +1000 Subject: tabs -> spaces --- ao-tools/altosui/AltosSiteMap.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 22b9aebe..6f33aabd 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -78,9 +78,9 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { } - public void reset() { - // ? - } + public void reset() { + // ? + } static Color stateColors[] = { Color.WHITE, // startup @@ -94,7 +94,7 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { Color.BLACK // landed }; - public void show(AltosState state, int crc_errors) { + public void show(AltosState state, int crc_errors) { if (!state.gps_ready) return; Point2D.Double pt = pt(state.gps.lat, state.gps.lon); @@ -106,7 +106,7 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { } last_pt = pt; repaint(); - } + } public AltosSiteMap() { GridBagLayout layout = new GridBagLayout(); -- cgit v1.2.3 From beb6c881ec006241c7d2820c64e5381131d41180 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 12 Nov 2010 03:24:26 +1000 Subject: make infotable scrollable, revert its fontsize to 14 --- ao-tools/altosui/AltosFlightUI.java | 2 +- ao-tools/altosui/AltosInfoTable.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 816ffa23..f56b3d1b 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -156,7 +156,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { pane.add("Landed", landed); flightInfo = new AltosInfoTable(); - pane.add("Table", flightInfo.box()); + pane.add("Table", new JScrollPane(flightInfo.box())); sitemap = new AltosSiteMap(); pane.add("Site Map", sitemap); diff --git a/ao-tools/altosui/AltosInfoTable.java b/ao-tools/altosui/AltosInfoTable.java index 2f326e07..9964ab10 100644 --- a/ao-tools/altosui/AltosInfoTable.java +++ b/ao-tools/altosui/AltosInfoTable.java @@ -37,8 +37,8 @@ public class AltosInfoTable { private AltosFlightInfoTableModel model[]; private Box ibox[]; - private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 12); - private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 12); + private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14); + private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14); static final int info_columns = 3; static final int info_rows = 17; -- cgit v1.2.3 From 1bcfa22de7821984149db10cb79913efed36b41e Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 12 Nov 2010 23:29:40 +1000 Subject: pull up maps for arbitrary locations --- ao-tools/altosui/AltosSiteMap.java | 54 +++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 16 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 6f33aabd..420bfc81 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -40,7 +40,8 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { Graphics2D g2d; - private void setLocation(double new_lat, double new_lng, int new_zoom) { + private void setLocation(double new_lat, double new_lng) { + int new_zoom = 15; lat = new_lat; lng = new_lng; zoom = new_zoom; @@ -50,6 +51,17 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { coord_pt.x = 320-coord_pt.x; coord_pt.y = 320-coord_pt.y; last_pt = null; + + try { + File pngfile = new File(AltosPreferences.logdir(), + FileCoord(lat, lng, zoom)); + System.out.printf("Trying file %s\n", pngfile); + BufferedImage myPicture = ImageIO.read(pngfile); + picLabel.setIcon(new ImageIcon( myPicture )); + g2d = myPicture.createGraphics(); + } catch (Exception e) { + throw new RuntimeException(e); + }; } private static double limit(double v, double lo, double hi) { @@ -60,6 +72,16 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { return v; } + private static String FileCoord(double lat, double lng, int zoom) { + char chlat = lat < 0 ? 'S' : 'N'; + char chlng = lng < 0 ? 'E' : 'W'; + if (lat < 0) lat = -lat; + if (lng < 0) lng = -lng; + return String.format("map-%c%.3f,%c%.3f-%d.png", + chlat, lat, chlng, lng, zoom); + } + + // based on google js // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js // search for fromLatLngToPoint and fromPointToLatLng @@ -95,8 +117,15 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { }; public void show(AltosState state, int crc_errors) { - if (!state.gps_ready) + if (!state.gps_ready && state.pad_lat == 0 && state.pad_lon == 0) return; + double plat = (int)(state.pad_lat*200)/200.0; + double plon = (int)(state.pad_lon*200)/200.0; + + if (last_pt == null) { + setLocation(plat, plon); + } + Point2D.Double pt = pt(state.gps.lat, state.gps.lon); if (last_pt != null && pt != last_pt) { if (0 <= state.state && state.state < stateColors.length) { @@ -107,31 +136,24 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { last_pt = pt; repaint(); } - + + JLabel picLabel = new JLabel(); + public AltosSiteMap() { GridBagLayout layout = new GridBagLayout(); setLayout(layout); GridBagConstraints c = new GridBagConstraints(); - setLocation(-27.850, 152.960, 15); - String pngfile = "/home/aj/qrs-S27.850,W152.960-15.png"; - c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.BOTH; + picLabel = new JLabel(); + JScrollPane scrollPane = new JScrollPane(picLabel); + layout.setConstraints(scrollPane, c); + add(scrollPane); - try { - BufferedImage myPicture = ImageIO.read(new File(pngfile)); - g2d = myPicture.createGraphics(); - JLabel picLabel = new JLabel(new ImageIcon( myPicture )); - JScrollPane scrollPane = new JScrollPane(picLabel); - layout.setConstraints(scrollPane, c); - add(scrollPane); - } catch (Exception e) { - throw new RuntimeException(e); - }; } } -- cgit v1.2.3 From 991541f57f065f429c6ec425efd6ac731280b2c1 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 12 Nov 2010 23:42:42 +1000 Subject: better error behaviour if no map --- ao-tools/altosui/AltosSiteMap.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 420bfc81..1fb70b35 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -40,7 +40,7 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { Graphics2D g2d; - private void setLocation(double new_lat, double new_lng) { + private boolean setLocation(double new_lat, double new_lng) { int new_zoom = 15; lat = new_lat; lng = new_lng; @@ -60,8 +60,10 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { picLabel.setIcon(new ImageIcon( myPicture )); g2d = myPicture.createGraphics(); } catch (Exception e) { - throw new RuntimeException(e); - }; + // throw new RuntimeException(e); + return false; + } + return true; } private static double limit(double v, double lo, double hi) { @@ -116,14 +118,20 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { Color.BLACK // landed }; + boolean nomaps = false; public void show(AltosState state, int crc_errors) { + if (nomaps) + return; if (!state.gps_ready && state.pad_lat == 0 && state.pad_lon == 0) return; double plat = (int)(state.pad_lat*200)/200.0; double plon = (int)(state.pad_lon*200)/200.0; if (last_pt == null) { - setLocation(plat, plon); + if (!setLocation(plat, plon)) { + nomaps = true; + return; + } } Point2D.Double pt = pt(state.gps.lat, state.gps.lon); -- cgit v1.2.3 From a6f30fae906bd87dff192c5fd4d10df283f99930 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 12 Nov 2010 17:02:22 -0800 Subject: altosui: Add RF calibration to TeleMetrum config dialog I think that's the last user-settable value. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 6 ++++++ ao-tools/altosui/AltosConfigUI.java | 43 ++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 7fecff0e..b7474f3b 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -83,6 +83,7 @@ public class AltosConfig implements Runnable, ActionListener { int_ref main_deploy; int_ref apogee_delay; int_ref radio_channel; + int_ref radio_calibration; string_ref version; string_ref product; string_ref callsign; @@ -146,6 +147,7 @@ public class AltosConfig implements Runnable, ActionListener { get_int(line, "Main deploy:", main_deploy); get_int(line, "Apogee delay:", apogee_delay); get_int(line, "Radio channel:", radio_channel); + get_int(line, "Radio cal:", radio_calibration); get_string(line, "Callsign:", callsign); get_string(line,"software-version", version); get_string(line,"product", product); @@ -175,6 +177,7 @@ public class AltosConfig implements Runnable, ActionListener { config_ui.set_main_deploy(main_deploy.get()); config_ui.set_apogee_delay(apogee_delay.get()); config_ui.set_radio_channel(radio_channel.get()); + config_ui.set_radio_calibration(radio_calibration.get()); config_ui.set_callsign(callsign.get()); config_ui.set_clean(); } catch (InterruptedException ie) { @@ -188,12 +191,14 @@ public class AltosConfig implements Runnable, ActionListener { main_deploy.set(config_ui.main_deploy()); apogee_delay.set(config_ui.apogee_delay()); radio_channel.set(config_ui.radio_channel()); + radio_calibration.set(config_ui.radio_calibration()); callsign.set(config_ui.callsign()); try { start_serial(); serial_line.printf("c m %d\n", main_deploy.get()); serial_line.printf("c d %d\n", apogee_delay.get()); serial_line.printf("c r %d\n", radio_channel.get()); + serial_line.printf("c f %d\n", radio_calibration.get()); serial_line.printf("c c %s\n", callsign.get()); serial_line.printf("c w\n"); } catch (InterruptedException ie) { @@ -234,6 +239,7 @@ public class AltosConfig implements Runnable, ActionListener { main_deploy = new int_ref(250); apogee_delay = new int_ref(0); radio_channel = new int_ref(0); + radio_calibration = new int_ref(1186611); callsign = new string_ref("N0CALL"); version = new string_ref("unknown"); product = new string_ref("unknown"); diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index 605ccc8b..37128573 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -57,6 +57,7 @@ public class AltosConfigUI JLabel main_deploy_label; JLabel apogee_delay_label; JLabel radio_channel_label; + JLabel radio_calibration_label; JLabel callsign_label; public boolean dirty; @@ -68,6 +69,7 @@ public class AltosConfigUI JComboBox main_deploy_value; JComboBox apogee_delay_value; JComboBox radio_channel_value; + JTextField radio_calibration_value; JTextField callsign_value; JButton save; @@ -256,7 +258,7 @@ public class AltosConfigUI radio_channel_value.addItemListener(this); pane.add(radio_channel_value, c); - /* Callsign */ + /* Radio Calibration */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 6; c.gridwidth = 3; @@ -264,11 +266,34 @@ public class AltosConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = il; c.ipady = 5; + radio_calibration_label = new JLabel("RF Calibration:"); + pane.add(radio_calibration_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 6; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_calibration_value = new JTextField(String.format("%d", 1186611)); + radio_calibration_value.getDocument().addDocumentListener(this); + pane.add(radio_calibration_value, c); + + /* Callsign */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 7; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; callsign_label = new JLabel("Callsign:"); pane.add(callsign_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 6; + c.gridx = 3; c.gridy = 7; c.gridwidth = 3; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; @@ -281,7 +306,7 @@ public class AltosConfigUI /* Buttons */ c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 7; + c.gridx = 0; c.gridy = 8; c.gridwidth = 6; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; @@ -292,7 +317,7 @@ public class AltosConfigUI save.setActionCommand("save"); c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 7; + c.gridx = 0; c.gridy = 8; c.gridwidth = 6; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.CENTER; @@ -303,7 +328,7 @@ public class AltosConfigUI reset.setActionCommand("reset"); c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 7; + c.gridx = 0; c.gridy = 8; c.gridwidth = 6; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_END; @@ -415,6 +440,14 @@ public class AltosConfigUI return radio_channel_value.getSelectedIndex(); } + public void set_radio_calibration(int new_radio_calibration) { + radio_calibration_value.setText(String.format("%d", new_radio_calibration)); + } + + public int radio_calibration() { + return Integer.parseInt(radio_calibration_value.getText()); + } + public void set_callsign(String new_callsign) { callsign_value.setText(new_callsign); } -- cgit v1.2.3 From 1e7e02987276847274493312202d22222c953149 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 14 Nov 2010 00:57:45 +1000 Subject: AltosTelemetryReader: actually open serial port --- ao-tools/altosui/AltosTelemetryReader.java | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index 0b5509eb..03e694f8 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -58,5 +58,6 @@ class AltosTelemetryReader extends AltosFlightReader { telem = new LinkedBlockingQueue(); serial.add_monitor(telem); + serial.open(device); } } -- cgit v1.2.3 From e68fe9454352087889c560d95797922493117acb Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 14 Nov 2010 00:59:01 +1000 Subject: AltosSiteMap: add targeting circles around landing site --- ao-tools/altosui/AltosSiteMap.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 1fb70b35..25b77792 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -118,6 +118,7 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { Color.BLACK // landed }; + boolean drawn_landed_circle = false; boolean nomaps = false; public void show(AltosState state, int crc_errors) { if (nomaps) @@ -141,6 +142,15 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { } g2d.draw(new Line2D.Double(last_pt, pt)); } + + if (state.state == 8 && !drawn_landed_circle) { + drawn_landed_circle = true; + g2d.setColor(Color.RED); + g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); + g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); + g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); + } + last_pt = pt; repaint(); } -- cgit v1.2.3 From 8463ffcaca6bcd31e645aba71c171f548dce96d8 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Nov 2010 15:19:14 -0800 Subject: altosui: Eliminate unncessary import altosui lines Java appears to automatically import every module from the current package. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSVUI.java | 3 --- ao-tools/altosui/AltosConfig.java | 14 -------------- ao-tools/altosui/AltosConfigUI.java | 13 ------------- ao-tools/altosui/AltosDataPointReader.java | 5 ----- ao-tools/altosui/AltosDebug.java | 2 -- ao-tools/altosui/AltosDeviceDialog.java | 1 - ao-tools/altosui/AltosEepromDownload.java | 12 ------------ ao-tools/altosui/AltosEepromIterable.java | 8 -------- ao-tools/altosui/AltosEepromMonitor.java | 10 ---------- ao-tools/altosui/AltosEepromRecord.java | 11 ----------- ao-tools/altosui/AltosFile.java | 2 -- ao-tools/altosui/AltosFlash.java | 2 -- ao-tools/altosui/AltosFlashUI.java | 3 --- ao-tools/altosui/AltosGPS.java | 2 -- ao-tools/altosui/AltosGraph.java | 2 -- ao-tools/altosui/AltosGraphDataChooser.java | 5 ----- ao-tools/altosui/AltosGraphTime.java | 3 --- ao-tools/altosui/AltosGraphUI.java | 3 --- ao-tools/altosui/AltosGreatCircle.java | 2 -- ao-tools/altosui/AltosInfoTable.java | 3 --- ao-tools/altosui/AltosLog.java | 3 --- ao-tools/altosui/AltosParse.java | 2 -- ao-tools/altosui/AltosReader.java | 2 -- ao-tools/altosui/AltosRecord.java | 2 -- ao-tools/altosui/AltosRecordIterable.java | 8 -------- ao-tools/altosui/AltosRomconfig.java | 1 - ao-tools/altosui/AltosRomconfigUI.java | 2 -- ao-tools/altosui/AltosSerial.java | 9 ++------- ao-tools/altosui/AltosState.java | 3 --- ao-tools/altosui/AltosStatusTable.java | 3 --- ao-tools/altosui/AltosTelemetry.java | 4 ---- ao-tools/altosui/AltosTelemetryIterable.java | 1 - ao-tools/altosui/AltosUI.java | 19 ------------------- 33 files changed, 2 insertions(+), 163 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSVUI.java b/ao-tools/altosui/AltosCSVUI.java index eb620ba8..16f25338 100644 --- a/ao-tools/altosui/AltosCSVUI.java +++ b/ao-tools/altosui/AltosCSVUI.java @@ -28,9 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosLogfileChooser; -import altosui.AltosCSV; - public class AltosCSVUI extends JDialog implements Runnable, ActionListener diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index b7474f3b..30f7d541 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -28,20 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.Altos; -import altosui.AltosSerial; -import altosui.AltosSerialMonitor; -import altosui.AltosRecord; -import altosui.AltosTelemetry; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosFlightStatusTableModel; -import altosui.AltosFlightInfoTableModel; -import altosui.AltosConfigUI; - import libaltosJNI.*; public class AltosConfig implements Runnable, ActionListener { diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index 37128573..9e3856b0 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -29,19 +29,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.Altos; -import altosui.AltosSerial; -import altosui.AltosSerialMonitor; -import altosui.AltosRecord; -import altosui.AltosTelemetry; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosFlightStatusTableModel; -import altosui.AltosFlightInfoTableModel; - import libaltosJNI.*; public class AltosConfigUI diff --git a/ao-tools/altosui/AltosDataPointReader.java b/ao-tools/altosui/AltosDataPointReader.java index 4d7831e4..7704310b 100644 --- a/ao-tools/altosui/AltosDataPointReader.java +++ b/ao-tools/altosui/AltosDataPointReader.java @@ -10,11 +10,6 @@ import java.lang.UnsupportedOperationException; import java.util.NoSuchElementException; import java.util.Iterator; -import altosui.AltosDataPoint; -import altosui.AltosRecordIterable; -import altosui.AltosRecord; -import altosui.AltosState; - class AltosDataPointReader implements Iterable { Iterator iter; AltosState state; diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index 3f469d48..9c10129d 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -22,8 +22,6 @@ import java.io.*; import java.util.concurrent.LinkedBlockingQueue; import java.util.LinkedList; import java.util.Iterator; -import altosui.AltosSerial; -import altosui.AltosRomconfig; public class AltosDebug extends AltosSerial { diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java index ec78e288..2966ad1e 100644 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -26,7 +26,6 @@ import libaltosJNI.libaltos; import libaltosJNI.altos_device; import libaltosJNI.SWIGTYPE_p_altos_file; import libaltosJNI.SWIGTYPE_p_altos_list; -import altosui.AltosDevice; public class AltosDeviceDialog extends JDialog implements ActionListener { diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 8efc94d2..bd9e4b48 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -28,18 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.Altos; -import altosui.AltosSerial; -import altosui.AltosSerialMonitor; -import altosui.AltosRecord; -import altosui.AltosTelemetry; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosEepromMonitor; - import libaltosJNI.*; public class AltosEepromDownload implements Runnable { diff --git a/ao-tools/altosui/AltosEepromIterable.java b/ao-tools/altosui/AltosEepromIterable.java index 2f1e7e90..fc683321 100644 --- a/ao-tools/altosui/AltosEepromIterable.java +++ b/ao-tools/altosui/AltosEepromIterable.java @@ -28,14 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosRecord; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosEepromMonitor; - /* * AltosRecords with an index field so they can be sorted by tick while preserving * the original ordering for elements with matching ticks diff --git a/ao-tools/altosui/AltosEepromMonitor.java b/ao-tools/altosui/AltosEepromMonitor.java index b88fdd29..7ff00ead 100644 --- a/ao-tools/altosui/AltosEepromMonitor.java +++ b/ao-tools/altosui/AltosEepromMonitor.java @@ -28,16 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosSerial; -import altosui.AltosSerialMonitor; -import altosui.AltosRecord; -import altosui.AltosTelemetry; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; - public class AltosEepromMonitor extends JDialog { Container pane; diff --git a/ao-tools/altosui/AltosEepromRecord.java b/ao-tools/altosui/AltosEepromRecord.java index 95cbe015..5a673817 100644 --- a/ao-tools/altosui/AltosEepromRecord.java +++ b/ao-tools/altosui/AltosEepromRecord.java @@ -28,17 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosSerial; -import altosui.AltosSerialMonitor; -import altosui.AltosRecord; -import altosui.AltosTelemetry; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosEepromMonitor; - public class AltosEepromRecord { public int cmd; public int tick; diff --git a/ao-tools/altosui/AltosFile.java b/ao-tools/altosui/AltosFile.java index 7f65381f..06360572 100644 --- a/ao-tools/altosui/AltosFile.java +++ b/ao-tools/altosui/AltosFile.java @@ -20,8 +20,6 @@ package altosui; import java.lang.*; import java.io.File; import java.util.*; -import altosui.AltosTelemetry; -import altosui.AltosPreferences; class AltosFile extends File { diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index a3e431cd..25b4a06e 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -28,8 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosHexfile; - public class AltosFlash { File file; FileInputStream input; diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 86f57a5f..70c8c549 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -28,9 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosHexfile; -import altosui.AltosFlash; - public class AltosFlashUI extends JDialog implements Runnable, ActionListener diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index acb6fb2c..83821842 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -19,8 +19,6 @@ package altosui; import java.lang.*; import java.text.*; -import altosui.AltosParse; - public class AltosGPS { public class AltosGPSSat { diff --git a/ao-tools/altosui/AltosGraph.java b/ao-tools/altosui/AltosGraph.java index fa3b87c1..58c27979 100644 --- a/ao-tools/altosui/AltosGraph.java +++ b/ao-tools/altosui/AltosGraph.java @@ -9,8 +9,6 @@ import java.io.*; import org.jfree.chart.JFreeChart; import org.jfree.chart.ChartUtilities; -import altosui.AltosDataPoint; - abstract class AltosGraph { public String filename; public abstract void addData(AltosDataPoint d); diff --git a/ao-tools/altosui/AltosGraphDataChooser.java b/ao-tools/altosui/AltosGraphDataChooser.java index caa14118..d128f4d5 100644 --- a/ao-tools/altosui/AltosGraphDataChooser.java +++ b/ao-tools/altosui/AltosGraphDataChooser.java @@ -27,11 +27,6 @@ import java.util.*; import java.text.*; import java.util.prefs.*; -import altosui.AltosPreferences; -import altosui.AltosDataPointReader; -import altosui.AltosEepromIterable; -import altosui.AltosTelemetryIterable; - public class AltosGraphDataChooser extends JFileChooser { JFrame frame; String filename; diff --git a/ao-tools/altosui/AltosGraphTime.java b/ao-tools/altosui/AltosGraphTime.java index ab01b888..a5451280 100644 --- a/ao-tools/altosui/AltosGraphTime.java +++ b/ao-tools/altosui/AltosGraphTime.java @@ -24,9 +24,6 @@ import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.RectangleAnchor; import org.jfree.ui.TextAnchor; -import altosui.AltosDataPoint; -import altosui.AltosGraph; - class AltosGraphTime extends AltosGraph { static interface Element { void attachGraph(AltosGraphTime g); diff --git a/ao-tools/altosui/AltosGraphUI.java b/ao-tools/altosui/AltosGraphUI.java index 25643c76..908aa3b4 100644 --- a/ao-tools/altosui/AltosGraphUI.java +++ b/ao-tools/altosui/AltosGraphUI.java @@ -17,9 +17,6 @@ import org.jfree.chart.axis.AxisLocation; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; -import altosui.AltosDataPoint; -import altosui.AltosGraphTime; - public class AltosGraphUI extends JFrame { static final private Color red = new Color(194,31,31); diff --git a/ao-tools/altosui/AltosGreatCircle.java b/ao-tools/altosui/AltosGreatCircle.java index aa6ae3b9..fb1b6ab3 100644 --- a/ao-tools/altosui/AltosGreatCircle.java +++ b/ao-tools/altosui/AltosGreatCircle.java @@ -17,8 +17,6 @@ package altosui; -import altosui.AltosGPS; - import java.lang.Math; public class AltosGreatCircle { diff --git a/ao-tools/altosui/AltosInfoTable.java b/ao-tools/altosui/AltosInfoTable.java index 2f326e07..28924410 100644 --- a/ao-tools/altosui/AltosInfoTable.java +++ b/ao-tools/altosui/AltosInfoTable.java @@ -28,9 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosFlightInfoTableModel; -import altosui.AltosState; - public class AltosInfoTable { private Box box; private JTable table[]; diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java index fed96c28..137147d5 100644 --- a/ao-tools/altosui/AltosLog.java +++ b/ao-tools/altosui/AltosLog.java @@ -22,9 +22,6 @@ import java.lang.*; import java.util.*; import java.text.ParseException; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosSerial; -import altosui.AltosFile; -import altosui.AltosLine; /* * This creates a thread to capture telemetry data and write it to diff --git a/ao-tools/altosui/AltosParse.java b/ao-tools/altosui/AltosParse.java index 4d82de78..fbfcaaee 100644 --- a/ao-tools/altosui/AltosParse.java +++ b/ao-tools/altosui/AltosParse.java @@ -20,8 +20,6 @@ package altosui; import java.text.*; import java.lang.*; -import altosui.Altos; - public class AltosParse { static boolean isdigit(char c) { return '0' <= c && c <= '9'; diff --git a/ao-tools/altosui/AltosReader.java b/ao-tools/altosui/AltosReader.java index 5be8795d..b9280a0c 100644 --- a/ao-tools/altosui/AltosReader.java +++ b/ao-tools/altosui/AltosReader.java @@ -21,8 +21,6 @@ import java.io.*; import java.util.*; import java.text.*; -import altosui.AltosRecord; - public class AltosReader { public AltosRecord read() throws IOException, ParseException { return null; } public void close() { } diff --git a/ao-tools/altosui/AltosRecord.java b/ao-tools/altosui/AltosRecord.java index 00484767..1160a273 100644 --- a/ao-tools/altosui/AltosRecord.java +++ b/ao-tools/altosui/AltosRecord.java @@ -21,8 +21,6 @@ import java.lang.*; import java.text.*; import java.util.HashMap; import java.io.*; -import altosui.AltosConvert; -import altosui.AltosGPS; public class AltosRecord { int version; diff --git a/ao-tools/altosui/AltosRecordIterable.java b/ao-tools/altosui/AltosRecordIterable.java index 147ecc14..a7df92d1 100644 --- a/ao-tools/altosui/AltosRecordIterable.java +++ b/ao-tools/altosui/AltosRecordIterable.java @@ -28,14 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosRecord; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosEepromMonitor; - public abstract class AltosRecordIterable implements Iterable { public abstract Iterator iterator(); public void write_comments(PrintStream out) { } diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java index 22d2dbd3..55056b5e 100644 --- a/ao-tools/altosui/AltosRomconfig.java +++ b/ao-tools/altosui/AltosRomconfig.java @@ -17,7 +17,6 @@ package altosui; import java.io.*; -import altosui.AltosHexfile; public class AltosRomconfig { public boolean valid; diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java index 2134975d..e1dc974e 100644 --- a/ao-tools/altosui/AltosRomconfigUI.java +++ b/ao-tools/altosui/AltosRomconfigUI.java @@ -28,8 +28,6 @@ import java.util.*; import java.text.*; import java.util.prefs.*; -import altosui.AltosRomconfig; - public class AltosRomconfigUI extends JDialog implements ActionListener diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index d6848e57..6787e0c8 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -26,13 +26,8 @@ import java.io.*; import java.util.concurrent.LinkedBlockingQueue; import java.util.LinkedList; import java.util.Iterator; -import altosui.AltosSerialMonitor; -import altosui.AltosLine; -import libaltosJNI.libaltos; -import libaltosJNI.altos_device; -import libaltosJNI.SWIGTYPE_p_altos_file; -import libaltosJNI.SWIGTYPE_p_altos_list; -import libaltosJNI.libaltosConstants; + +import libaltosJNI.*; /* * This class reads from the serial port and places each received diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index 86eb636a..ec499d5a 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -21,9 +21,6 @@ package altosui; -import altosui.AltosRecord; -import altosui.AltosGPS; - public class AltosState { AltosRecord data; diff --git a/ao-tools/altosui/AltosStatusTable.java b/ao-tools/altosui/AltosStatusTable.java index 0d3a5d14..02c6232f 100644 --- a/ao-tools/altosui/AltosStatusTable.java +++ b/ao-tools/altosui/AltosStatusTable.java @@ -28,9 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosFlightStatusTableModel; -import altosui.AltosFlightInfoTableModel; - public class AltosStatusTable extends JTable { private AltosFlightStatusTableModel flightStatusModel; diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index be22dac6..bdb6466a 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -20,10 +20,6 @@ package altosui; import java.lang.*; import java.text.*; import java.util.HashMap; -import altosui.AltosConvert; -import altosui.AltosRecord; -import altosui.AltosGPS; -import altosui.AltosCRCException; /* * Telemetry data contents diff --git a/ao-tools/altosui/AltosTelemetryIterable.java b/ao-tools/altosui/AltosTelemetryIterable.java index 0a125c98..a71ab872 100644 --- a/ao-tools/altosui/AltosTelemetryIterable.java +++ b/ao-tools/altosui/AltosTelemetryIterable.java @@ -20,7 +20,6 @@ package altosui; import java.io.*; import java.util.*; import java.text.*; -import altosui.AltosTelemetry; public class AltosTelemetryIterable extends AltosRecordIterable { LinkedList records; diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 2861444d..9ab451de 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -28,25 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.Altos; -import altosui.AltosSerial; -import altosui.AltosSerialMonitor; -import altosui.AltosRecord; -import altosui.AltosTelemetry; -import altosui.AltosState; -import altosui.AltosDeviceDialog; -import altosui.AltosPreferences; -import altosui.AltosLog; -import altosui.AltosVoice; -import altosui.AltosFlightInfoTableModel; -import altosui.AltosFlashUI; -import altosui.AltosLogfileChooser; -import altosui.AltosCSVUI; -import altosui.AltosLine; -import altosui.AltosStatusTable; -import altosui.AltosInfoTable; -import altosui.AltosDisplayThread; - import libaltosJNI.*; public class AltosUI extends JFrame { -- cgit v1.2.3 From dcfa56498d1b65a213b8aba9cbd6c4806532383c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Nov 2010 16:07:04 -0800 Subject: altosui: Open serial device at 'new' time. Prohibit duplicate opens. With the per-serial UI, there's never a reason to create a serial device without opening it right away. This eliminates the bug caused by not opening the serial device for telemetry reception. Serial devices can now be opened only once; this eliminates errors when trying to reflash or configure devices while receiving telemetry. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 9 +++++++-- ao-tools/altosui/AltosDebug.java | 11 ++++++++--- ao-tools/altosui/AltosEepromDownload.java | 9 +++++++-- ao-tools/altosui/AltosFlash.java | 13 +++++-------- ao-tools/altosui/AltosFlashUI.java | 11 ++++++++--- ao-tools/altosui/AltosSerial.java | 28 +++++++++++++++++----------- ao-tools/altosui/AltosTelemetryReader.java | 5 +++-- ao-tools/altosui/AltosUI.java | 6 ++++++ ao-tools/altosui/Makefile.am | 1 + 9 files changed, 62 insertions(+), 31 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 30f7d541..09e204a9 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -231,10 +231,9 @@ public class AltosConfig implements Runnable, ActionListener { product = new string_ref("unknown"); device = AltosDeviceDialog.show(owner, AltosDevice.product_any); - serial_line = new AltosSerial(); if (device != null) { try { - serial_line.open(device); + serial_line = new AltosSerial(device); if (!device.matchProduct(AltosDevice.product_telemetrum)) remote = true; config_thread = new Thread(this); @@ -245,6 +244,12 @@ public class AltosConfig implements Runnable, ActionListener { device.getPath()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(owner, + String.format("Device \"%s\" already in use", + device.getPath()), + "Device in use", + JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(owner, device.getPath(), diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index 9c10129d..9aa35d3f 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -19,9 +19,10 @@ package altosui; import java.lang.*; import java.io.*; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.LinkedList; -import java.util.Iterator; +import java.util.concurrent.*; +import java.util.*; + +import libaltosJNI.*; public class AltosDebug extends AltosSerial { @@ -259,4 +260,8 @@ public class AltosDebug extends AltosSerial { public void reset() { printf ("R\n"); } + + public AltosDebug (altos_device in_device) throws FileNotFoundException, AltosSerialInUseException { + super(in_device); + } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index bd9e4b48..8996b924 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -244,12 +244,11 @@ public class AltosEepromDownload implements Runnable { frame = given_frame; device = AltosDeviceDialog.show(frame, AltosDevice.product_any); - serial_line = new AltosSerial(); remote = false; if (device != null) { try { - serial_line.open(device); + serial_line = new AltosSerial(device); if (!device.matchProduct(AltosDevice.product_telemetrum)) remote = true; eeprom_thread = new Thread(this); @@ -260,6 +259,12 @@ public class AltosEepromDownload implements Runnable { device.getPath()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(frame, + String.format("Device \"%s\" already in use", + device.getPath()), + "Device in use", + JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(frame, device.getPath(), diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index 25b4a06e..fa2465d3 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -329,17 +329,14 @@ public class AltosFlash { return rom_config; } - public void open() throws IOException, FileNotFoundException, InterruptedException { + public AltosFlash(File in_file, AltosDevice in_debug_dongle) + throws IOException, FileNotFoundException, AltosSerialInUseException, InterruptedException { + file = in_file; + debug_dongle = in_debug_dongle; + debug = new AltosDebug(in_debug_dongle); input = new FileInputStream(file); image = new AltosHexfile(input); - debug.open(debug_dongle); if (!debug.check_connection()) throw new IOException("Debug port not connected"); } - - public AltosFlash(File in_file, AltosDevice in_debug_dongle) { - file = in_file; - debug_dongle = in_debug_dongle; - debug = new AltosDebug(); - } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 70c8c549..b09cb594 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -65,10 +65,9 @@ public class AltosFlashUI } public void run() { - flash = new AltosFlash(file, debug_dongle); - flash.addActionListener(this); try { - flash.open(); + flash = new AltosFlash(file, debug_dongle); + flash.addActionListener(this); AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); romconfig_ui.set(flash.romconfig()); @@ -88,6 +87,12 @@ public class AltosFlashUI "Cannot open image", file.toString(), JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(frame, + String.format("Device \"%s\" already in use", + debug_dongle.getPath()), + "Device in use", + JOptionPane.ERROR_MESSAGE); } catch (IOException e) { JOptionPane.showMessageDialog(frame, e.getMessage(), diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 6787e0c8..99a92fdb 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -23,9 +23,8 @@ package altosui; import java.lang.*; import java.io.*; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.LinkedList; -import java.util.Iterator; +import java.util.concurrent.*; +import java.util.*; import libaltosJNI.*; @@ -37,6 +36,9 @@ import libaltosJNI.*; public class AltosSerial implements Runnable { + static List devices_opened = Collections.synchronizedList(new LinkedList()); + + altos_device device; SWIGTYPE_p_altos_file altos; LinkedList> monitors; LinkedBlockingQueue reply_queue; @@ -141,10 +143,6 @@ public class AltosSerial implements Runnable { set_monitor(false); } - public boolean opened() { - return altos != null; - } - public void close() { if (altos != null) { libaltos.altos_close(altos); @@ -161,6 +159,9 @@ public class AltosSerial implements Runnable { libaltos.altos_free(altos); altos = null; } + synchronized (devices_opened) { + devices_opened.remove(device.getPath()); + } } public void putc(char c) { @@ -178,7 +179,12 @@ public class AltosSerial implements Runnable { print(String.format(format, arguments)); } - public void open(altos_device device) throws FileNotFoundException { + private void open() throws FileNotFoundException, AltosSerialInUseException { + synchronized (devices_opened) { + if (devices_opened.contains(device.getPath())) + throw new AltosSerialInUseException(device); + devices_opened.add(device.getPath()); + } close(); altos = libaltos.altos_open(device); if (altos == null) @@ -220,12 +226,12 @@ public class AltosSerial implements Runnable { } } - public AltosSerial() { - altos = null; - input_thread = null; + public AltosSerial(altos_device in_device) throws FileNotFoundException, AltosSerialInUseException { + device = in_device; line = ""; monitor_mode = false; monitors = new LinkedList> (); reply_queue = new LinkedBlockingQueue (); + open(); } } diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index 0b5509eb..ff02c722 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -50,9 +50,10 @@ class AltosTelemetryReader extends AltosFlightReader { serial.set_callsign(callsign); } - public AltosTelemetryReader (AltosDevice in_device) throws FileNotFoundException, IOException { + public AltosTelemetryReader (AltosDevice in_device) + throws FileNotFoundException, AltosSerialInUseException, IOException { device = in_device; - serial = new AltosSerial(); + serial = new AltosSerial(device); log = new AltosLog(serial); name = device.getPath(); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 9ab451de..0d8f0e8d 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -56,6 +56,12 @@ public class AltosUI extends JFrame { device.getPath()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(AltosUI.this, + String.format("Device \"%s\" already in use", + device.getPath()), + "Device in use", + JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, device.getPath(), diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 267bae63..f4c743df 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -58,6 +58,7 @@ altosui_JAVA = \ AltosRomconfig.java \ AltosRomconfigUI.java \ AltosSerial.java \ + AltosSerialInUseException.java \ AltosSerialMonitor.java \ AltosState.java \ AltosStatusTable.java \ -- cgit v1.2.3 From 11c95f687b1f68d35fa1a0af2c4e7982b8bb226a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Nov 2010 17:09:51 -0800 Subject: altosui: Replace flight status table with labels, fix resize. There's no reason to use a table for the flight status data, replace that with a selection of widgets instead. Also, set all of the grid bag constraints for the various flight status displays so that resize does something sensible. Adds a scrollbar to the table display so that it can shrink. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosAscent.java | 13 ++- ao-tools/altosui/AltosDescent.java | 78 +++++++++------- ao-tools/altosui/AltosFlightStatus.java | 157 ++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosFlightUI.java | 10 +- ao-tools/altosui/AltosLanded.java | 6 +- ao-tools/altosui/AltosPad.java | 20 ++-- ao-tools/altosui/AltosStatusTable.java | 67 -------------- ao-tools/altosui/Makefile.am | 3 +- 8 files changed, 237 insertions(+), 117 deletions(-) create mode 100644 ao-tools/altosui/AltosFlightStatus.java delete mode 100644 ao-tools/altosui/AltosStatusTable.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java index 51fa1a89..7525b655 100644 --- a/ao-tools/altosui/AltosAscent.java +++ b/ao-tools/altosui/AltosAscent.java @@ -43,6 +43,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } public AscentValue (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; label = new JLabel(text); label.setFont(label_font); @@ -50,6 +51,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { c.gridx = 0; c.gridy = y; c.insets = new Insets(10, 10, 10, 10); c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; layout.setConstraints(label, c); add(label); @@ -58,8 +61,9 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.HORIZONTAL; + c.fill = GridBagConstraints.BOTH; c.gridwidth = 2; + c.weightx = 1; layout.setConstraints(value, c); add(value); } @@ -88,6 +92,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } public AscentValueHold (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; label = new JLabel(text); label.setFont(label_font); @@ -95,6 +100,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { c.gridx = 0; c.gridy = y; c.insets = new Insets(10, 10, 10, 10); c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; layout.setConstraints(label, c); add(label); @@ -103,6 +110,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; layout.setConstraints(value, c); add(value); @@ -111,6 +120,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { max_value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; layout.setConstraints(max_value, c); add(max_value); } diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index 56d3e4fe..b69e36b6 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -48,6 +48,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { public DescentValue (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; label = new JLabel(text); label.setFont(label_font); @@ -55,6 +56,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { c.gridx = 0; c.gridy = y; c.insets = new Insets(10, 10, 10, 10); c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; layout.setConstraints(label, c); add(label); @@ -64,7 +67,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { c.gridx = 1; c.gridy = y; c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.HORIZONTAL; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; layout.setConstraints(value, c); add(value); } @@ -138,50 +142,54 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { JLabel label; JTextField value; JTextField value_deg; - void reset () { + void reset () { value.setText(""); value_deg.setText(""); - } + } void show (AltosState state, int crc_errors) { if (state.from_pad != null) { - value.setText(state.from_pad.bearing_words( - AltosGreatCircle.BEARING_LONG)); + value.setText(state.from_pad.bearing_words( + AltosGreatCircle.BEARING_LONG)); value_deg.setText(String.format("%3.0f°", state.from_pad.bearing)); } else { value.setText("???"); value_deg.setText("???"); - } + } } public Bearing (GridBagLayout layout, int y) { - GridBagConstraints c = new GridBagConstraints(); - - label = new JLabel("Bearing"); - label.setFont(label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 0; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); - c.anchor = GridBagConstraints.WEST; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(30); - value.setFont(value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 1; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.HORIZONTAL; - layout.setConstraints(value, c); - add(value); - - value_deg = new JTextField(5); - value_deg.setFont(value_font); - value_deg.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.HORIZONTAL; - - layout.setConstraints(value_deg, c); - add(value_deg); + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel("Bearing"); + label.setFont(label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 0; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + c.weightx = 0; + c.fill = GridBagConstraints.VERTICAL; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(30); + value.setFont(value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 1; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.weightx = 1; + c.fill = GridBagConstraints.BOTH; + layout.setConstraints(value, c); + add(value); + + value_deg = new JTextField(5); + value_deg.setFont(value_font); + value_deg.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.weightx = 1; + c.fill = GridBagConstraints.BOTH; + layout.setConstraints(value_deg, c); + add(value_deg); } } diff --git a/ao-tools/altosui/AltosFlightStatus.java b/ao-tools/altosui/AltosFlightStatus.java new file mode 100644 index 00000000..b99a5325 --- /dev/null +++ b/ao-tools/altosui/AltosFlightStatus.java @@ -0,0 +1,157 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + + private Font status_font; + + public class FlightValue { + JLabel label; + JTextField value; + + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + } + public FlightValue (GridBagLayout layout, int x, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(5, 5, 5, 5); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + c.weighty = 1; + + label = new JLabel(text); + label.setFont(status_font); + label.setHorizontalAlignment(SwingConstants.CENTER); + c.gridx = x; c.gridy = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(""); + value.setFont(status_font); + value.setHorizontalAlignment(SwingConstants.CENTER); + c.gridx = x; c.gridy = 1; + layout.setConstraints(value, c); + add(value); + } + } + + class Call extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(state.data.callsign); + } + public Call (GridBagLayout layout, int x) { + super (layout, x, "Callsign"); + } + } + + Call call; + + class Serial extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(String.format("%d", state.data.serial)); + } + public Serial (GridBagLayout layout, int x) { + super (layout, x, "Serial"); + } + } + + Serial serial; + + class Flight extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(String.format("%d", state.data.flight)); + } + public Flight (GridBagLayout layout, int x) { + super (layout, x, "Flight"); + } + } + + Flight flight; + + class FlightState extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(state.data.state()); + } + public FlightState (GridBagLayout layout, int x) { + super (layout, x, "State"); + } + } + + FlightState flight_state; + + class RSSI extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(String.format("%d", state.data.rssi)); + } + public RSSI (GridBagLayout layout, int x) { + super (layout, x, "RSSI (dBm)"); + } + } + + RSSI rssi; + + public void reset () { + call.reset(); + serial.reset(); + flight.reset(); + flight_state.reset(); + rssi.reset(); + } + + public void show (AltosState state, int crc_errors) { + call.show(state, crc_errors); + serial.show(state, crc_errors); + flight.show(state, crc_errors); + flight_state.show(state, crc_errors); + rssi.show(state, crc_errors); + } + + public int height() { + Dimension d = layout.preferredLayoutSize(this); + return d.height; + } + + public AltosFlightStatus() { + layout = new GridBagLayout(); + + status_font = new Font("SansSerif", Font.BOLD, 24); + setLayout(layout); + + call = new Call(layout, 0); + serial = new Serial(layout, 1); + flight = new Flight(layout, 2); + flight_state = new FlightState(layout, 3); + rssi = new RSSI(layout, 4); + } +} diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 3581c54c..ae31048d 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -45,7 +45,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { AltosDescent descent; AltosLanded landed; - private AltosStatusTable flightStatus; + private AltosFlightStatus flightStatus; + private JScrollPane flightInfoPane; private AltosInfoTable flightInfo; static final int tab_pad = 1; @@ -117,7 +118,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { } cur_tab = tab; } - flightStatus.set(state); + flightStatus.show(state, crc_errors); flightInfo.show(state, crc_errors); } @@ -133,7 +134,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { setTitle(String.format("AltOS %s", reader.name)); - flightStatus = new AltosStatusTable(); + flightStatus = new AltosFlightStatus(); vbox = new Box (BoxLayout.Y_AXIS); vbox.add(flightStatus); @@ -153,7 +154,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { pane.add("Landed", landed); flightInfo = new AltosInfoTable(); - pane.add("Table", flightInfo.box()); + flightInfoPane = new JScrollPane(flightInfo.box()); + pane.add("Table", flightInfoPane); vbox.add(pane); diff --git a/ao-tools/altosui/AltosLanded.java b/ao-tools/altosui/AltosLanded.java index d170ccad..465c9dce 100644 --- a/ao-tools/altosui/AltosLanded.java +++ b/ao-tools/altosui/AltosLanded.java @@ -48,6 +48,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { public LandedValue (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; label = new JLabel(text); label.setFont(label_font); @@ -55,6 +56,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { c.gridx = 0; c.gridy = y; c.insets = new Insets(10, 10, 10, 10); c.anchor = GridBagConstraints.WEST; + c.weightx = 0; + c.fill = GridBagConstraints.VERTICAL; layout.setConstraints(label, c); add(label); @@ -63,7 +66,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.fill = GridBagConstraints.BOTH; layout.setConstraints(value, c); add(value); } diff --git a/ao-tools/altosui/AltosPad.java b/ao-tools/altosui/AltosPad.java index da047072..650ed012 100644 --- a/ao-tools/altosui/AltosPad.java +++ b/ao-tools/altosui/AltosPad.java @@ -46,11 +46,13 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { public LaunchStatus (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; lights = new AltosLights(); c.gridx = 0; c.gridy = y; c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; layout.setConstraints(lights, c); add(lights); @@ -60,7 +62,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { c.gridx = 1; c.gridy = y; c.insets = new Insets(10, 10, 10, 10); c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; layout.setConstraints(label, c); add(label); @@ -69,6 +72,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; layout.setConstraints(value, c); add(value); @@ -85,13 +90,16 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } public LaunchValue (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(10, 10, 10, 10); + c.weighty = 1; label = new JLabel(text); label.setFont(label_font); label.setHorizontalAlignment(SwingConstants.LEFT); c.gridx = 1; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; layout.setConstraints(label, c); add(label); @@ -100,7 +108,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.HORIZONTAL; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; layout.setConstraints(value, c); add(value); } @@ -221,13 +230,10 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { public AltosPad() { layout = new GridBagLayout(); - GridBagConstraints c; - label_font = new Font("Dialog", Font.PLAIN, 24); value_font = new Font("Monospaced", Font.PLAIN, 24); setLayout(layout); - c = new GridBagConstraints(); /* Elements in pad display: * * Battery voltage diff --git a/ao-tools/altosui/AltosStatusTable.java b/ao-tools/altosui/AltosStatusTable.java deleted file mode 100644 index 02c6232f..00000000 --- a/ao-tools/altosui/AltosStatusTable.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosStatusTable extends JTable { - private AltosFlightStatusTableModel flightStatusModel; - - private Font statusFont = new Font("SansSerif", Font.BOLD, 24); - - public AltosStatusTable() { - super((TableModel) new AltosFlightStatusTableModel()); - flightStatusModel = (AltosFlightStatusTableModel) getModel(); - - setFont(statusFont); - - TableColumnModel tcm = getColumnModel(); - - for (int i = 0; i < flightStatusModel.getColumnCount(); i++) { - DefaultTableCellRenderer r = new DefaultTableCellRenderer(); - r.setFont(statusFont); - r.setHorizontalAlignment(SwingConstants.CENTER); - tcm.getColumn(i).setCellRenderer(r); - } - - setRowHeight(rowHeight()); - setShowGrid(false); - } - - public int rowHeight() { - FontMetrics statusMetrics = getFontMetrics(statusFont); - return (statusMetrics.getHeight() + statusMetrics.getLeading()) * 15 / 10; - } - - public int height() { - return rowHeight * 4; - } - - public void set(AltosState state) { - flightStatusModel.set(state); - } -} diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index f4c743df..d11ea3e2 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -33,7 +33,7 @@ altosui_JAVA = \ AltosFlightDisplay.java \ AltosFlightInfoTableModel.java \ AltosFlightReader.java \ - AltosFlightStatusTableModel.java \ + AltosFlightStatus.java \ AltosFlightUI.java \ AltosGPS.java \ AltosGreatCircle.java \ @@ -61,7 +61,6 @@ altosui_JAVA = \ AltosSerialInUseException.java \ AltosSerialMonitor.java \ AltosState.java \ - AltosStatusTable.java \ AltosTelemetry.java \ AltosTelemetryIterable.java \ AltosUI.java \ -- cgit v1.2.3 From 511903704f7e1b22e88dd3e3cc35fd3c0583820e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 14 Nov 2010 03:26:57 -0800 Subject: altosui: With --replay option, exit when replay window is closed Otherwise, the application hangs around forever. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlightUI.java | 10 ++++++++- ao-tools/altosui/AltosUI.java | 41 +++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 21 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index ae31048d..5134a24e 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -56,6 +56,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { int cur_tab = 0; + boolean exit_on_close = false; + int which_tab(AltosState state) { if (state.state < Altos.ao_flight_boost) return tab_pad; @@ -122,8 +124,12 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { flightInfo.show(state, crc_errors); } + public void set_exit_on_close() { + exit_on_close = true; + } + public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { - AltosPreferences.init(this); + AltosPreferences.init(this); voice = in_voice; reader = in_reader; @@ -191,6 +197,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { disconnect(); setVisible(false); dispose(); + if (exit_on_close) + System.exit(0); } }); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 0d8f0e8d..a2e416ba 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -443,26 +443,27 @@ public class AltosUI extends JFrame { public static void main(final String[] args) { int process = 0; /* Handle batch-mode */ - if (args.length == 2 && args[0].equals("--replay")) { - String filename = args[1]; - FileInputStream in; - try { - in = new FileInputStream(filename); - } catch (Exception e) { - System.out.printf("Failed to open file '%s'\n", filename); - return; - } - AltosRecordIterable recs; - AltosReplayReader reader; - if (filename.endsWith("eeprom")) { - recs = new AltosEepromIterable(in); - } else { - recs = new AltosTelemetryIterable(in); - } - reader = new AltosReplayReader(recs.iterator(), filename); - new AltosFlightUI(new AltosVoice(), reader); - return; - } else if (args.length > 0) { + if (args.length == 2 && args[0].equals("--replay")) { + String filename = args[1]; + FileInputStream in; + try { + in = new FileInputStream(filename); + } catch (Exception e) { + System.out.printf("Failed to open file '%s'\n", filename); + return; + } + AltosRecordIterable recs; + AltosReplayReader reader; + if (filename.endsWith("eeprom")) { + recs = new AltosEepromIterable(in); + } else { + recs = new AltosTelemetryIterable(in); + } + reader = new AltosReplayReader(recs.iterator(), filename); + AltosFlightUI flight_ui = new AltosFlightUI(new AltosVoice(), reader); + flight_ui.set_exit_on_close(); + return; + } else if (args.length > 0) { for (int i = 0; i < args.length; i++) { if (args[i].equals("--kml")) process |= process_kml; -- cgit v1.2.3 From 524644d8d8ce3f8a5a914ecfc7e2a8d474d89095 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 15 Nov 2010 22:04:44 +0800 Subject: altosui: oops, missed a file in the previous commit AltosSerialInUseException.java just defines a new exception, thanks to java for making this live in a separate file. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerialInUseException.java | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ao-tools/altosui/AltosSerialInUseException.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerialInUseException.java b/ao-tools/altosui/AltosSerialInUseException.java new file mode 100644 index 00000000..4b108c7c --- /dev/null +++ b/ao-tools/altosui/AltosSerialInUseException.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import libaltosJNI.*; + +public class AltosSerialInUseException extends Exception { + public altos_device device; + + public AltosSerialInUseException (altos_device in_device) { + device = in_device; + } +} -- cgit v1.2.3 From 257e97137325f5dbbd6aa034f20fd6937b67df90 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 15 Nov 2010 22:38:35 +0800 Subject: altosui: eliminate menu bar, moving elements to buttons. This adds a new 'configure AltosUI' dialog to set the log directory and voice preferences. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfigureUI.java | 120 +++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 158 +++++---------------------------- ao-tools/altosui/Makefile.am | 1 + 3 files changed, 144 insertions(+), 135 deletions(-) create mode 100644 ao-tools/altosui/AltosConfigureUI.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfigureUI.java b/ao-tools/altosui/AltosConfigureUI.java new file mode 100644 index 00000000..88c180f1 --- /dev/null +++ b/ao-tools/altosui/AltosConfigureUI.java @@ -0,0 +1,120 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosConfigureUI extends JDialog { + JFrame owner; + AltosVoice voice; + Container pane; + + JRadioButton enable_voice; + JButton test_voice; + JButton close; + + JButton configure_log; + JTextField log_directory; + + public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) { + super(in_owner, "Configure AltosUI", false); + + GridBagConstraints c; + + Insets insets = new Insets(4, 4, 4, 4); + + owner = in_owner; + voice = in_voice; + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + c = new GridBagConstraints(); + c.insets = insets; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + + /* Enable Voice */ + c.gridx = 0; + c.gridy = 0; + enable_voice = new JRadioButton("Enable Voice", AltosPreferences.voice()); + enable_voice.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JRadioButton item = (JRadioButton) e.getSource(); + boolean enabled = item.isSelected(); + AltosPreferences.set_voice(enabled); + if (enabled) + voice.speak_always("Enable voice."); + else + voice.speak_always("Disable voice."); + } + }); + pane.add(enable_voice, c); + c.gridx = 1; + c.gridy = 0; + test_voice = new JButton("Test Voice"); + test_voice.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + voice.speak("That's one small step for man; one giant leap for mankind."); + } + }); + pane.add(test_voice, c); + + close = new JButton("Close"); + close.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + setVisible(false); + } + }); + c.gridx = 0; + c.gridy = 3; + c.gridwidth = 2; + pane.add(close, c); + + configure_log = new JButton("Configure Log"); + configure_log.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + AltosPreferences.ConfigureLog(); + log_directory.setText(AltosPreferences.logdir().getPath()); + } + }); + c.gridwidth = 1; + + c.gridx = 0; + c.gridy = 2; + pane.add(configure_log, c); + + log_directory = new JTextField(AltosPreferences.logdir().getPath()); + c.gridx = 1; + c.gridy = 2; + c.fill = GridBagConstraints.BOTH; + pane.add(log_directory, c); + + pack(); + setLocationRelativeTo(owner); + setVisible(true); + } +} diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index a2e416ba..bedf2459 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -144,9 +144,28 @@ public class AltosUI extends JFrame { } }); - setTitle("AltOS"); + b = addButton(0, 2, "Configure AltosUI"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ConfigureAltosUI(); + } + }); + + b = addButton(1, 2, "Flash Image"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + FlashImage(); + } + }); + + b = addButton(2, 2, "Quit"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); - createMenu(); + setTitle("AltOS"); pane.doLayout(); pane.validate(); @@ -232,139 +251,8 @@ public class AltosUI extends JFrame { new AltosGraphUI(AltosUI.this); } - /* Create the AltosUI menus - */ - private void createMenu() { - JMenuBar menubar = new JMenuBar(); - JMenu menu; - JMenuItem item; - JRadioButtonMenuItem radioitem; - - // File menu - { - menu = new JMenu("File"); - menu.setMnemonic(KeyEvent.VK_F); - menubar.add(menu); - - item = new JMenuItem("Flash Image",KeyEvent.VK_I); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - FlashImage(); - } - }); - menu.add(item); - - item = new JMenuItem("Export Data",KeyEvent.VK_E); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - ExportData(); - } - }); - menu.add(item); - - item = new JMenuItem("Graph Data",KeyEvent.VK_G); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - GraphData(); - } - }); - menu.add(item); - - item = new JMenuItem("Quit",KeyEvent.VK_Q); - item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, - ActionEvent.CTRL_MASK)); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - System.out.printf("exiting\n"); - System.exit(0); - } - }); - menu.add(item); - } - - // Device menu - if (false) { - menu = new JMenu("Device"); - menu.setMnemonic(KeyEvent.VK_D); - menubar.add(menu); - - item = new JMenuItem("Connect to Device",KeyEvent.VK_C); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - ConnectToDevice(); - } - }); - menu.add(item); - - menu.addSeparator(); - - item = new JMenuItem("Set Callsign",KeyEvent.VK_S); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - ConfigureCallsign(); - } - }); - - menu.add(item); - - item = new JMenuItem("Configure TeleMetrum device",KeyEvent.VK_T); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - ConfigureTeleMetrum(); - } - }); - - menu.add(item); - } - // Log menu - { - menu = new JMenu("Log"); - menu.setMnemonic(KeyEvent.VK_L); - menubar.add(menu); - - item = new JMenuItem("New Log",KeyEvent.VK_N); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - } - }); - menu.add(item); - - item = new JMenuItem("Configure Log",KeyEvent.VK_C); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - AltosPreferences.ConfigureLog(); - } - }); - menu.add(item); - } - // Voice menu - { - menu = new JMenu("Voice", true); - menu.setMnemonic(KeyEvent.VK_V); - menubar.add(menu); - - radioitem = new JRadioButtonMenuItem("Enable Voice", AltosPreferences.voice()); - radioitem.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - JRadioButtonMenuItem item = (JRadioButtonMenuItem) e.getSource(); - boolean enabled = item.isSelected(); - AltosPreferences.set_voice(enabled); - if (enabled) - voice.speak_always("Enable voice."); - else - voice.speak_always("Disable voice."); - } - }); - menu.add(radioitem); - item = new JMenuItem("Test Voice",KeyEvent.VK_T); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - voice.speak("That's one small step for man; one giant leap for mankind."); - } - }); - menu.add(item); - } - this.setJMenuBar(menubar); + private void ConfigureAltosUI() { + new AltosConfigureUI(AltosUI.this, voice); } static AltosRecordIterable open_logfile(String filename) { diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index d11ea3e2..8d0fe16e 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -14,6 +14,7 @@ altosui_JAVA = \ AltosChannelMenu.java \ AltosConfig.java \ AltosConfigUI.java \ + AltosConfigureUI.java \ AltosConvert.java \ AltosCRCException.java \ AltosCSV.java \ -- cgit v1.2.3 From 39e371561469d8e5059638ffa4e7075f391de268 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 15 Nov 2010 23:14:51 +0800 Subject: altosui: add reboot button to telemetrum configuration UI This lets you reconfigure and reboot telemetrum, including over the radio link. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 20 +++++++-- ao-tools/altosui/AltosConfigUI.java | 90 +++++++++++++++++++++---------------- 2 files changed, 68 insertions(+), 42 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 09e204a9..a0fdb623 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -198,12 +198,26 @@ public class AltosConfig implements Runnable, ActionListener { public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); - if (cmd.equals("save")) { + if (cmd.equals("Save")) { save_data(); set_ui(); - } else if (cmd.equals("reset")) { + } else if (cmd.equals("Reset")) { set_ui(); - } else if (cmd.equals("close")) { + } else if (cmd.equals("Reboot")) { + if (serial_line != null) { + try { + start_serial(); + serial_line.printf("r eboot\n"); + } catch (InterruptedException ie) { + } finally { + try { + stop_serial(); + } catch (InterruptedException ie) { + } + } + serial_line.close(); + } + } else if (cmd.equals("Close")) { if (serial_line != null) serial_line.close(); } diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index 9e3856b0..e04933eb 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -61,6 +61,7 @@ public class AltosConfigUI JButton save; JButton reset; + JButton reboot; JButton close; ActionListener listener; @@ -92,7 +93,7 @@ public class AltosConfigUI public void windowClosing(WindowEvent e) { ui.actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, - "close")); + "Close")); } } @@ -112,7 +113,7 @@ public class AltosConfigUI /* Product */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; - c.gridwidth = 3; + c.gridwidth = 4; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -120,8 +121,8 @@ public class AltosConfigUI pane.add(product_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 0; - c.gridwidth = 3; + c.gridx = 4; c.gridy = 0; + c.gridwidth = 4; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; @@ -132,7 +133,7 @@ public class AltosConfigUI /* Version */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 1; - c.gridwidth = 3; + c.gridwidth = 4; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -141,8 +142,8 @@ public class AltosConfigUI pane.add(version_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 1; - c.gridwidth = 3; + c.gridx = 4; c.gridy = 1; + c.gridwidth = 4; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; @@ -154,7 +155,7 @@ public class AltosConfigUI /* Serial */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 2; - c.gridwidth = 3; + c.gridwidth = 4; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -163,8 +164,8 @@ public class AltosConfigUI pane.add(serial_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 2; - c.gridwidth = 3; + c.gridx = 4; c.gridy = 2; + c.gridwidth = 4; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; @@ -176,7 +177,7 @@ public class AltosConfigUI /* Main deploy */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 3; - c.gridwidth = 3; + c.gridwidth = 4; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -185,8 +186,8 @@ public class AltosConfigUI pane.add(main_deploy_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 3; - c.gridwidth = 3; + c.gridx = 4; c.gridy = 3; + c.gridwidth = 4; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; @@ -200,7 +201,7 @@ public class AltosConfigUI /* Apogee delay */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 4; - c.gridwidth = 3; + c.gridwidth = 4; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -209,8 +210,8 @@ public class AltosConfigUI pane.add(apogee_delay_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 4; - c.gridwidth = 3; + c.gridx = 4; c.gridy = 4; + c.gridwidth = 4; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; @@ -224,7 +225,7 @@ public class AltosConfigUI /* Radio channel */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 5; - c.gridwidth = 3; + c.gridwidth = 4; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -233,8 +234,8 @@ public class AltosConfigUI pane.add(radio_channel_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 5; - c.gridwidth = 3; + c.gridx = 4; c.gridy = 5; + c.gridwidth = 4; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; @@ -248,7 +249,7 @@ public class AltosConfigUI /* Radio Calibration */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 6; - c.gridwidth = 3; + c.gridwidth = 4; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -257,8 +258,8 @@ public class AltosConfigUI pane.add(radio_calibration_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 6; - c.gridwidth = 3; + c.gridx = 4; c.gridy = 6; + c.gridwidth = 4; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; @@ -271,7 +272,7 @@ public class AltosConfigUI /* Callsign */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 7; - c.gridwidth = 3; + c.gridwidth = 4; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -280,8 +281,8 @@ public class AltosConfigUI pane.add(callsign_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 7; - c.gridwidth = 3; + c.gridx = 4; c.gridy = 7; + c.gridwidth = 4; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; @@ -294,36 +295,47 @@ public class AltosConfigUI /* Buttons */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 8; - c.gridwidth = 6; + c.gridwidth = 2; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; save = new JButton("Save"); pane.add(save, c); save.addActionListener(this); - save.setActionCommand("save"); + save.setActionCommand("Save"); c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 8; - c.gridwidth = 6; + c.gridx = 2; c.gridy = 8; + c.gridwidth = 2; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.CENTER; c.insets = il; reset = new JButton("Reset"); pane.add(reset, c); reset.addActionListener(this); - reset.setActionCommand("reset"); + reset.setActionCommand("Reset"); c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 8; - c.gridwidth = 6; + c.gridx = 4; c.gridy = 8; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + reboot = new JButton("Reboot"); + pane.add(reboot, c); + reboot.addActionListener(this); + reboot.setActionCommand("Reboot"); + + c = new GridBagConstraints(); + c.gridx = 6; c.gridy = 8; + c.gridwidth = 2; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_END; c.insets = il; close = new JButton("Close"); pane.add(close, c); close.addActionListener(this); - close.setActionCommand("close"); + close.setActionCommand("Close"); addWindowListener(new ConfigListener(this)); } @@ -336,12 +348,12 @@ public class AltosConfigUI } /* If any values have been changed, confirm before closing */ - public boolean check_dirty() { + public boolean check_dirty(String operation) { if (dirty) { - Object[] options = { "Close anyway", "Keep editing" }; + Object[] options = { String.format("%s anyway", operation), "Keep editing" }; int i; i = JOptionPane.showOptionDialog(this, - "Configuration modified, close anyway?", + String.format("Configuration modified. %s anyway?", operation), "Configuration Modified", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, @@ -356,11 +368,11 @@ public class AltosConfigUI public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); - if (cmd.equals("close")) - if (!check_dirty()) + if (cmd.equals("Close") || cmd.equals("Reboot")) + if (!check_dirty(cmd)) return; listener.actionPerformed(e); - if (cmd.equals("close")) { + if (cmd.equals("Close") || cmd.equals("Reboot")) { setVisible(false); dispose(); } -- cgit v1.2.3 From fcca333cda64be35f0c9fb0109eef1be3709dddd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 16 Nov 2010 21:49:59 +0800 Subject: altosui: Add callsign configuration in AltosUI configuration dialog This callsign is used during packet communication. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfigUI.java | 2 +- ao-tools/altosui/AltosConfigureUI.java | 56 ++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 13 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index e04933eb..ca89f58d 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -288,7 +288,7 @@ public class AltosConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = ir; c.ipady = 5; - callsign_value = new JTextField("N0CALL"); + callsign_value = new JTextField(AltosPreferences.callsign()); callsign_value.getDocument().addDocumentListener(this); pane.add(callsign_value, c); diff --git a/ao-tools/altosui/AltosConfigureUI.java b/ao-tools/altosui/AltosConfigureUI.java index 88c180f1..64c17eaf 100644 --- a/ao-tools/altosui/AltosConfigureUI.java +++ b/ao-tools/altosui/AltosConfigureUI.java @@ -22,13 +22,17 @@ import java.awt.event.*; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.*; +import javax.swing.event.*; import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -public class AltosConfigureUI extends JDialog { +public class AltosConfigureUI + extends JDialog + implements DocumentListener +{ JFrame owner; AltosVoice voice; Container pane; @@ -40,6 +44,22 @@ public class AltosConfigureUI extends JDialog { JButton configure_log; JTextField log_directory; + JLabel callsign_label; + JTextField callsign_value; + + /* DocumentListener interface methods */ + public void changedUpdate(DocumentEvent e) { + AltosPreferences.set_callsign(callsign_value.getText()); + } + + public void insertUpdate(DocumentEvent e) { + changedUpdate(e); + } + + public void removeUpdate(DocumentEvent e) { + changedUpdate(e); + } + public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) { super(in_owner, "Configure AltosUI", false); @@ -83,17 +103,6 @@ public class AltosConfigureUI extends JDialog { }); pane.add(test_voice, c); - close = new JButton("Close"); - close.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - setVisible(false); - } - }); - c.gridx = 0; - c.gridy = 3; - c.gridwidth = 2; - pane.add(close, c); - configure_log = new JButton("Configure Log"); configure_log.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -113,6 +122,29 @@ public class AltosConfigureUI extends JDialog { c.fill = GridBagConstraints.BOTH; pane.add(log_directory, c); + callsign_label = new JLabel("Callsign"); + c.gridx = 0; + c.gridy = 3; + pane.add(callsign_label, c); + + callsign_value = new JTextField(AltosPreferences.callsign()); + callsign_value.getDocument().addDocumentListener(this); + c.gridx = 1; + c.gridy = 3; + pane.add(callsign_value, c); + + close = new JButton("Close"); + close.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + setVisible(false); + } + }); + c.gridx = 0; + c.gridy = 4; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + pane.add(close, c); + pack(); setLocationRelativeTo(owner); setVisible(true); -- cgit v1.2.3 From d0eb41619544ead6d9dab3a8d024a12936c9cdd0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 16 Nov 2010 22:20:00 +0800 Subject: altosui: Cleanup flight UI layout Use common constants for fonts and insets Shrink fonts so that the window is < 600 pixels tall. Signed-off-by: Keith Packard --- ao-tools/altosui/Altos.java | 6 +++ ao-tools/altosui/AltosAscent.java | 24 +++++------- ao-tools/altosui/AltosDescent.java | 18 ++++----- ao-tools/altosui/AltosFlightInfoTableModel.java | 2 +- ao-tools/altosui/AltosFlightStatus.java | 7 +--- ao-tools/altosui/AltosFlightUI.java | 2 +- ao-tools/altosui/AltosLanded.java | 4 +- ao-tools/altosui/AltosPad.java | 50 +++++++++++++++++-------- 8 files changed, 64 insertions(+), 49 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java index 997550e0..197e98db 100644 --- a/ao-tools/altosui/Altos.java +++ b/ao-tools/altosui/Altos.java @@ -67,6 +67,12 @@ public class Altos { static boolean map_initialized = false; + static final int tab_elt_pad = 5; + + static final Font label_font = new Font("Dialog", Font.PLAIN, 22); + static final Font value_font = new Font("Monospaced", Font.PLAIN, 22); + static final Font status_font = new Font("SansSerif", Font.BOLD, 24); + static void initialize_map() { string_to_state.put("startup", ao_flight_startup); diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java index 7525b655..8e1b6347 100644 --- a/ao-tools/altosui/AltosAscent.java +++ b/ao-tools/altosui/AltosAscent.java @@ -30,8 +30,6 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosAscent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - Font label_font; - Font value_font; public class AscentValue { JLabel label; @@ -46,10 +44,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { c.weighty = 1; label = new JLabel(text); - label.setFont(label_font); + label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); c.gridx = 0; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; c.weightx = 0; @@ -57,7 +55,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(30); - value.setFont(value_font); + value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; @@ -95,10 +93,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { c.weighty = 1; label = new JLabel(text); - label.setFont(label_font); + label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); c.gridx = 0; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; c.weightx = 0; @@ -106,7 +104,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(15); - value.setFont(value_font); + value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.EAST; @@ -116,7 +114,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { add(value); max_value = new JTextField(15); - max_value.setFont(value_font); + max_value.setFont(Altos.value_font); max_value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.EAST; @@ -224,15 +222,15 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { JLabel cur, max; cur = new JLabel("Current"); - cur.setFont(label_font); + cur.setFont(Altos.label_font); c = new GridBagConstraints(); c.gridx = 1; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); layout.setConstraints(cur, c); add(cur); max = new JLabel("Maximum"); - max.setFont(label_font); + max.setFont(Altos.label_font); c.gridx = 2; c.gridy = y; layout.setConstraints(max, c); add(max); @@ -241,8 +239,6 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { public AltosAscent() { layout = new GridBagLayout(); - label_font = new Font("Dialog", Font.PLAIN, 24); - value_font = new Font("Monospaced", Font.PLAIN, 24); setLayout(layout); /* Elements in ascent display: diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index b69e36b6..ceb78e57 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -30,8 +30,6 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosDescent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - Font label_font; - Font value_font; public class DescentValue { JLabel label; @@ -51,10 +49,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { c.weighty = 1; label = new JLabel(text); - label.setFont(label_font); + label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); c.gridx = 0; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; c.weightx = 0; @@ -62,7 +60,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(30); - value.setFont(value_font); + value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.gridwidth = 2; @@ -161,10 +159,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { c.weighty = 1; label = new JLabel("Bearing"); - label.setFont(label_font); + label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); c.gridx = 0; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.weightx = 0; c.fill = GridBagConstraints.VERTICAL; @@ -172,7 +170,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(30); - value.setFont(value_font); + value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.EAST; @@ -182,7 +180,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { add(value); value_deg = new JTextField(5); - value_deg.setFont(value_font); + value_deg.setFont(Altos.value_font); value_deg.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.EAST; @@ -243,8 +241,6 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { public AltosDescent() { layout = new GridBagLayout(); - label_font = new Font("Dialog", Font.PLAIN, 24); - value_font = new Font("Monospaced", Font.PLAIN, 24); setLayout(layout); /* Elements in descent display */ diff --git a/ao-tools/altosui/AltosFlightInfoTableModel.java b/ao-tools/altosui/AltosFlightInfoTableModel.java index 2a22e3e5..3355ff52 100644 --- a/ao-tools/altosui/AltosFlightInfoTableModel.java +++ b/ao-tools/altosui/AltosFlightInfoTableModel.java @@ -46,7 +46,7 @@ public class AltosFlightInfoTableModel extends AbstractTableModel { public int getColumnCount() { return columnNames.length; } public String getColumnName(int col) { return columnNames[col]; } - public int getRowCount() { return 20; } + public int getRowCount() { return 17; } int current_row = 0; int prev_num_rows = 0; diff --git a/ao-tools/altosui/AltosFlightStatus.java b/ao-tools/altosui/AltosFlightStatus.java index b99a5325..59c9e9db 100644 --- a/ao-tools/altosui/AltosFlightStatus.java +++ b/ao-tools/altosui/AltosFlightStatus.java @@ -31,8 +31,6 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - private Font status_font; - public class FlightValue { JLabel label; JTextField value; @@ -51,14 +49,14 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay c.weighty = 1; label = new JLabel(text); - label.setFont(status_font); + label.setFont(Altos.status_font); label.setHorizontalAlignment(SwingConstants.CENTER); c.gridx = x; c.gridy = 0; layout.setConstraints(label, c); add(label); value = new JTextField(""); - value.setFont(status_font); + value.setFont(Altos.status_font); value.setHorizontalAlignment(SwingConstants.CENTER); c.gridx = x; c.gridy = 1; layout.setConstraints(value, c); @@ -145,7 +143,6 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay public AltosFlightStatus() { layout = new GridBagLayout(); - status_font = new Font("SansSerif", Font.BOLD, 24); setLayout(layout); call = new Call(layout, 0); diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 5134a24e..78b005c0 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -187,7 +187,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { this.setJMenuBar(menubar); } - this.setSize(new Dimension (width(), height())); + this.setSize(this.getPreferredSize()); this.validate(); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); diff --git a/ao-tools/altosui/AltosLanded.java b/ao-tools/altosui/AltosLanded.java index 465c9dce..0656ea6c 100644 --- a/ao-tools/altosui/AltosLanded.java +++ b/ao-tools/altosui/AltosLanded.java @@ -196,8 +196,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { public AltosLanded() { layout = new GridBagLayout(); - label_font = new Font("Dialog", Font.PLAIN, 24); - value_font = new Font("Monospaced", Font.PLAIN, 24); + label_font = new Font("Dialog", Font.PLAIN, 22); + value_font = new Font("Monospaced", Font.PLAIN, 22); setLayout(layout); /* Elements in descent display */ diff --git a/ao-tools/altosui/AltosPad.java b/ao-tools/altosui/AltosPad.java index 650ed012..8b258c7d 100644 --- a/ao-tools/altosui/AltosPad.java +++ b/ao-tools/altosui/AltosPad.java @@ -60,7 +60,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label.setFont(label_font); label.setHorizontalAlignment(SwingConstants.LEFT); c.gridx = 1; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; c.weightx = 0; @@ -90,7 +90,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } public LaunchValue (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); - c.insets = new Insets(10, 10, 10, 10); + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.weighty = 1; label = new JLabel(text); @@ -151,17 +151,32 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { Main main; - class GPS extends LaunchStatus { + class GPSLocked extends LaunchStatus { void show (AltosState state, int crc_errors) { value.setText(String.format("%4d sats", state.gps.nsat)); + lights.set(state.gps.locked); + } + public GPSLocked (GridBagLayout layout, int y) { + super (layout, y, "GPS Locked"); + } + } + + GPSLocked gps_locked; + + class GPSReady extends LaunchStatus { + void show (AltosState state, int crc_errors) { + if (state.gps_ready) + value.setText("Ready"); + else + value.setText(String.format("Waiting %d", state.gps_waiting)); lights.set(state.gps_ready); } - public GPS (GridBagLayout layout, int y) { - super (layout, y, "GPS Status"); + public GPSReady (GridBagLayout layout, int y) { + super (layout, y, "GPS Ready"); } } - GPS gps; + GPSReady gps_ready; String pos(double p, String pos, String neg) { String h = pos; @@ -211,7 +226,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { battery.reset(); apogee.reset(); main.reset(); - gps.reset(); + gps_locked.reset(); + gps_ready.reset(); pad_lat.reset(); pad_lon.reset(); pad_alt.reset(); @@ -221,7 +237,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { battery.show(state, crc_errors); apogee.show(state, crc_errors); main.show(state, crc_errors); - gps.show(state, crc_errors); + gps_locked.show(state, crc_errors); + gps_ready.show(state, crc_errors); pad_lat.show(state, crc_errors); pad_lon.show(state, crc_errors); pad_alt.show(state, crc_errors); @@ -230,24 +247,27 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { public AltosPad() { layout = new GridBagLayout(); - label_font = new Font("Dialog", Font.PLAIN, 24); - value_font = new Font("Monospaced", Font.PLAIN, 24); + label_font = new Font("Dialog", Font.PLAIN, 22); + value_font = new Font("Monospaced", Font.PLAIN, 22); setLayout(layout); /* Elements in pad display: * * Battery voltage * Igniter continuity - * GPS lock status and location + * GPS lock status + * GPS ready status + * GPS location * Pad altitude * RSSI */ battery = new Battery(layout, 0); apogee = new Apogee(layout, 1); main = new Main(layout, 2); - gps = new GPS(layout, 3); - pad_lat = new PadLat(layout, 4); - pad_lon = new PadLon(layout, 5); - pad_alt = new PadAlt(layout, 6); + gps_locked = new GPSLocked(layout, 3); + gps_ready = new GPSReady(layout, 4); + pad_lat = new PadLat(layout, 5); + pad_lon = new PadLon(layout, 6); + pad_alt = new PadAlt(layout, 7); } } -- cgit v1.2.3 From 1a4b6e96f823035b113f01d1bdfd61afc1f33e25 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 16 Nov 2010 22:46:29 +0800 Subject: altosui: Add igniter status to ascent and descent tabs Monitor igniters during all phases of the flight. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosAscent.java | 77 ++++++++++++++++++++++ ao-tools/altosui/AltosDescent.java | 130 +++++++++++++++++++++++++++++-------- ao-tools/altosui/AltosPad.java | 12 ++-- 3 files changed, 183 insertions(+), 36 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java index 8e1b6347..38ced95e 100644 --- a/ao-tools/altosui/AltosAscent.java +++ b/ao-tools/altosui/AltosAscent.java @@ -31,6 +31,53 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosAscent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; + public class AscentStatus { + JLabel label; + JTextField value; + AltosLights lights; + + void show(AltosState state, int crc_errors) {} + void reset() { + value.setText(""); + lights.set(false); + } + + public AscentStatus (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + lights = new AltosLights(); + c.gridx = 0; c.gridy = y; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(lights, c); + add(lights); + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(15); + value.setFont(Altos.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + + } + } + public class AscentValue { JLabel label; JTextField value; @@ -173,6 +220,30 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { return String.format("%s %4d° %9.6f", h, deg, min); } + class Apogee extends AscentStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.drogue_sense)); + lights.set(state.drogue_sense > 3.2); + } + public Apogee (GridBagLayout layout, int y) { + super(layout, y, "Apogee Igniter Voltage"); + } + } + + Apogee apogee; + + class Main extends AscentStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.main_sense)); + lights.set(state.main_sense > 3.2); + } + public Main (GridBagLayout layout, int y) { + super(layout, y, "Main Igniter Voltage"); + } + } + + Main main; + class Lat extends AscentValue { void show (AltosState state, int crc_errors) { if (state.gps != null) @@ -204,6 +275,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { public void reset() { lat.reset(); lon.reset(); + main.reset(); + apogee.reset(); height.reset(); speed.reset(); accel.reset(); @@ -213,6 +286,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { lat.show(state, crc_errors); lon.show(state, crc_errors); height.show(state, crc_errors); + main.show(state, crc_errors); + apogee.show(state, crc_errors); speed.show(state, crc_errors); accel.show(state, crc_errors); } @@ -253,5 +328,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { accel = new Accel(layout, 3); lat = new Lat(layout, 4); lon = new Lon(layout, 5); + apogee = new Apogee(layout, 6); + main = new Main(layout, 7); } } diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index ceb78e57..aacd2998 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -31,6 +31,52 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosDescent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; + public class DescentStatus { + JLabel label; + JTextField value; + AltosLights lights; + + void show(AltosState state, int crc_errors) {} + void reset() { + value.setText(""); + lights.set(false); + } + + public DescentStatus (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + lights = new AltosLights(); + c.gridx = 0; c.gridy = y; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(lights, c); + add(lights); + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(15); + value.setFont(Altos.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + + } + } public class DescentValue { JLabel label; JTextField value; @@ -44,14 +90,14 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value.setText(String.format(format, v)); } - public DescentValue (GridBagLayout layout, int y, String text) { + public DescentValue (GridBagLayout layout, int x, int y, String text) { GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; label = new JLabel(text); label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 0; c.gridy = y; + c.gridx = x + 0; c.gridy = y; c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; @@ -59,11 +105,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(30); + value = new JTextField(17); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 1; c.gridy = y; - c.gridwidth = 2; + c.gridx = x + 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -76,8 +121,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { void show (AltosState state, int crc_errors) { show("%6.0f m", state.height); } - public Height (GridBagLayout layout, int y) { - super (layout, y, "Height"); + public Height (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Height"); } } @@ -90,8 +135,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { speed = state.baro_speed; show("%6.0f m/s", speed); } - public Speed (GridBagLayout layout, int y) { - super (layout, y, "Speed"); + public Speed (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Speed"); } } @@ -115,8 +160,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { else value.setText("???"); } - public Lat (GridBagLayout layout, int y) { - super (layout, y, "Latitude"); + public Lat (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Latitude"); } } @@ -129,13 +174,37 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { else value.setText("???"); } - public Lon (GridBagLayout layout, int y) { - super (layout, y, "Longitude"); + public Lon (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Longitude"); } } Lon lon; + class Apogee extends DescentStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.drogue_sense)); + lights.set(state.drogue_sense > 3.2); + } + public Apogee (GridBagLayout layout, int y) { + super(layout, y, "Apogee Igniter Voltage"); + } + } + + Apogee apogee; + + class Main extends DescentStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.main_sense)); + lights.set(state.main_sense > 3.2); + } + public Main (GridBagLayout layout, int y) { + super(layout, y, "Main Igniter Voltage"); + } + } + + Main main; + class Bearing { JLabel label; JTextField value; @@ -154,14 +223,14 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value_deg.setText("???"); } } - public Bearing (GridBagLayout layout, int y) { + public Bearing (GridBagLayout layout, int x, int y) { GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; label = new JLabel("Bearing"); label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 0; c.gridy = y; + c.gridx = x + 0; c.gridy = y; c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.weightx = 0; @@ -172,9 +241,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value = new JTextField(30); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 1; c.gridy = y; + c.gridx = x + 1; c.gridy = y; c.anchor = GridBagConstraints.EAST; c.weightx = 1; + c.gridwidth = 2; c.fill = GridBagConstraints.BOTH; layout.setConstraints(value, c); add(value); @@ -182,7 +252,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value_deg = new JTextField(5); value_deg.setFont(Altos.value_font); value_deg.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; + c.gridx = x + 3; c.gridy = y; c.anchor = GridBagConstraints.EAST; c.weightx = 1; c.fill = GridBagConstraints.BOTH; @@ -200,8 +270,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { else value.setText("???"); } - public Elevation (GridBagLayout layout, int y) { - super (layout, y, "Elevation"); + public Elevation (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Elevation"); } } @@ -211,8 +281,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { void show (AltosState state, int crc_errors) { show("%6.0f m", state.range); } - public Range (GridBagLayout layout, int y) { - super (layout, y, "Range"); + public Range (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Range"); } } @@ -226,6 +296,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { bearing.reset(); elevation.reset(); range.reset(); + main.reset(); + apogee.reset(); } public void show(AltosState state, int crc_errors) { @@ -236,6 +308,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { range.show(state, crc_errors); lat.show(state, crc_errors); lon.show(state, crc_errors); + main.show(state, crc_errors); + apogee.show(state, crc_errors); } public AltosDescent() { @@ -244,12 +318,12 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { setLayout(layout); /* Elements in descent display */ - speed = new Speed(layout, 0); - height = new Height(layout, 1); - bearing = new Bearing(layout, 2); - elevation = new Elevation(layout, 3); - range = new Range(layout, 4); - lat = new Lat(layout, 5); - lon = new Lon(layout, 6); + speed = new Speed(layout, 0, 0); height = new Height(layout, 2, 0); + elevation = new Elevation(layout, 0, 1); range = new Range(layout, 2, 1); + bearing = new Bearing(layout, 0, 2); + lat = new Lat(layout, 0, 3); + lon = new Lon(layout, 0, 4); + apogee = new Apogee(layout, 5); + main = new Main(layout, 6); } } diff --git a/ao-tools/altosui/AltosPad.java b/ao-tools/altosui/AltosPad.java index 8b258c7d..77289f89 100644 --- a/ao-tools/altosui/AltosPad.java +++ b/ao-tools/altosui/AltosPad.java @@ -30,8 +30,6 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosPad extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - Font label_font; - Font value_font; public class LaunchStatus { JLabel label; @@ -57,7 +55,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { add(lights); label = new JLabel(text); - label.setFont(label_font); + label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); c.gridx = 1; c.gridy = y; c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); @@ -68,7 +66,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(15); - value.setFont(value_font); + value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.WEST; @@ -94,7 +92,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { c.weighty = 1; label = new JLabel(text); - label.setFont(label_font); + label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; @@ -104,7 +102,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(30); - value.setFont(value_font); + value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.EAST; @@ -247,8 +245,6 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { public AltosPad() { layout = new GridBagLayout(); - label_font = new Font("Dialog", Font.PLAIN, 22); - value_font = new Font("Monospaced", Font.PLAIN, 22); setLayout(layout); /* Elements in pad display: -- cgit v1.2.3 From 483346a03c94b200692f5e6d59f3feee4dcf2ace Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 19 Nov 2010 12:09:46 +1000 Subject: altosui: tile site maps --- ao-tools/altosui/AltosFlightUI.java | 4 +- ao-tools/altosui/AltosSiteMap.java | 138 +++--------------------- ao-tools/altosui/AltosSiteMapTile.java | 190 +++++++++++++++++++++++++++++++++ ao-tools/altosui/Makefile.am | 1 + 4 files changed, 206 insertions(+), 127 deletions(-) create mode 100644 ao-tools/altosui/AltosSiteMapTile.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 1372cc00..658d6f6f 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -48,6 +48,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { private AltosFlightStatus flightStatus; private JScrollPane flightInfoPane; + private JScrollPane sitemapPane; private AltosInfoTable flightInfo; static final int tab_pad = 1; @@ -167,7 +168,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { pane.add("Table", flightInfoPane); sitemap = new AltosSiteMap(); - pane.add("Site Map", sitemap); + sitemapPane = new JScrollPane(sitemap); + pane.add("Site Map", sitemapPane); vbox.add(pane); diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 25b77792..df1cc246 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -32,146 +32,32 @@ import java.awt.geom.Point2D; import java.awt.geom.Line2D; public class AltosSiteMap extends JComponent implements AltosFlightDisplay { - double lat, lng; - int zoom; - double scale_x, scale_y; - Point2D.Double coord_pt; - Point2D.Double last_pt; - - Graphics2D g2d; - - private boolean setLocation(double new_lat, double new_lng) { - int new_zoom = 15; - lat = new_lat; - lng = new_lng; - zoom = new_zoom; - scale_x = 256/360.0 * Math.pow(2, zoom); - scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - coord_pt = pt(lat, lng, new Point2D.Double(0,0)); - coord_pt.x = 320-coord_pt.x; - coord_pt.y = 320-coord_pt.y; - last_pt = null; - - try { - File pngfile = new File(AltosPreferences.logdir(), - FileCoord(lat, lng, zoom)); - System.out.printf("Trying file %s\n", pngfile); - BufferedImage myPicture = ImageIO.read(pngfile); - picLabel.setIcon(new ImageIcon( myPicture )); - g2d = myPicture.createGraphics(); - } catch (Exception e) { - // throw new RuntimeException(e); - return false; - } - return true; - } - - private static double limit(double v, double lo, double hi) { - if (v < lo) - return lo; - if (hi < v) - return hi; - return v; - } - - private static String FileCoord(double lat, double lng, int zoom) { - char chlat = lat < 0 ? 'S' : 'N'; - char chlng = lng < 0 ? 'E' : 'W'; - if (lat < 0) lat = -lat; - if (lng < 0) lng = -lng; - return String.format("map-%c%.3f,%c%.3f-%d.png", - chlat, lat, chlng, lng, zoom); - } - - - // based on google js - // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js - // search for fromLatLngToPoint and fromPointToLatLng - private Point2D.Double pt(double lat, double lng) { - return pt(lat, lng, coord_pt); - } - - private Point2D.Double pt(double lat, double lng, Point2D.Double centre) { - Point2D.Double res = new Point2D.Double(); - double e; - - res.x = centre.x + lng*scale_x; - e = limit(Math.sin(Math.toRadians(lat)),-(1-1.0E-15),1-1.0E-15); - res.y = centre.y + 0.5*Math.log((1+e)/(1-e))*-scale_y; - return res; - } - - public void reset() { - // ? + // nothing } - - static Color stateColors[] = { - Color.WHITE, // startup - Color.WHITE, // idle - Color.WHITE, // pad - Color.RED, // boost - Color.PINK, // fast - Color.YELLOW, // coast - Color.CYAN, // drogue - Color.BLUE, // main - Color.BLACK // landed - }; - - boolean drawn_landed_circle = false; - boolean nomaps = false; public void show(AltosState state, int crc_errors) { - if (nomaps) - return; - if (!state.gps_ready && state.pad_lat == 0 && state.pad_lon == 0) - return; - double plat = (int)(state.pad_lat*200)/200.0; - double plon = (int)(state.pad_lon*200)/200.0; - - if (last_pt == null) { - if (!setLocation(plat, plon)) { - nomaps = true; - return; - } - } - - Point2D.Double pt = pt(state.gps.lat, state.gps.lon); - if (last_pt != null && pt != last_pt) { - if (0 <= state.state && state.state < stateColors.length) { - g2d.setColor(stateColors[state.state]); - } - g2d.draw(new Line2D.Double(last_pt, pt)); - } - - if (state.state == 8 && !drawn_landed_circle) { - drawn_landed_circle = true; - g2d.setColor(Color.RED); - g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); - g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); - g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); + for (int x = 0; x < mapTiles.length; x++) { + mapTiles[x].show(state, crc_errors); } - - last_pt = pt; - repaint(); } - - JLabel picLabel = new JLabel(); + + AltosSiteMapTile [] mapTiles = new AltosSiteMapTile[9]; public AltosSiteMap() { + GridBagLayout layout = new GridBagLayout(); setLayout(layout); GridBagConstraints c = new GridBagConstraints(); - - c.gridx = 0; c.gridy = 0; - c.weightx = 1; c.weighty = 1; c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.BOTH; - picLabel = new JLabel(); - JScrollPane scrollPane = new JScrollPane(picLabel); - layout.setConstraints(scrollPane, c); - add(scrollPane); + for (int x = 0; x < 9; x++) { + c.gridx = x % 3; c.gridy = x / 3; + mapTiles[x] = new AltosSiteMapTile((x%3)-1, (x/3)-1); + layout.setConstraints(mapTiles[x], c); + add(mapTiles[x]); + } } } diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java new file mode 100644 index 00000000..d84941ae --- /dev/null +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -0,0 +1,190 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import javax.swing.*; +import javax.imageio.ImageIO; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.lang.Math; +import java.awt.geom.Point2D; +import java.awt.geom.Line2D; + +public class AltosSiteMapTile extends JLabel { + double lat, lng; + int zoom; + double scale_x, scale_y; + Point2D.Double coord_pt; + Point2D.Double last_pt; + + Graphics2D g2d; + + int off_x; + int off_y; + + int px_size = 512; + + private boolean setLocation(double new_lat, double new_lng) { + int new_zoom = 16; + lat = new_lat; + lng = new_lng; + zoom = new_zoom; + scale_x = 256/360.0 * Math.pow(2, zoom); + scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + coord_pt = pt(lat, lng, new Point2D.Double(0,0)); + coord_pt.x = px_size/2-coord_pt.x - off_x * px_size; + coord_pt.y = px_size/2-coord_pt.y - off_y * px_size; + last_pt = null; + + Point2D.Double map_latlng; + map_latlng = latlng(new Point2D.Double(px_size/2, px_size/2)); + + BufferedImage myPicture; + File pngfile = new File(AltosPreferences.logdir(), + FileCoord(map_latlng, zoom)); + try { + myPicture = ImageIO.read(pngfile); + System.out.printf("# Found file %s\n", pngfile); + } catch (Exception e) { + // throw new RuntimeException(e); + System.out.printf("# Failed to find file %s\n", pngfile); + System.out.printf(" wget -O '%s' 'http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32'\n", pngfile, map_latlng.x, map_latlng.y, zoom, px_size, px_size); + myPicture = new BufferedImage(px_size, px_size, + BufferedImage.TYPE_INT_RGB); + } + setIcon(new ImageIcon( myPicture )); + g2d = myPicture.createGraphics(); + return true; + } + + private static double limit(double v, double lo, double hi) { + if (v < lo) + return lo; + if (hi < v) + return hi; + return v; + } + + private static String FileCoord(Point2D.Double latlng, int zoom) { + double lat, lng; + lat = latlng.x; + lng = latlng.y; + return FileCoord(lat, lng, zoom); + } + private static String FileCoord(double lat, double lng, int zoom) { + char chlat = lat < 0 ? 'S' : 'N'; + char chlng = lng < 0 ? 'E' : 'W'; + if (lat < 0) lat = -lat; + if (lng < 0) lng = -lng; + return String.format("map-%c%.3f,%c%.3f-%d.png", + chlat, lat, chlng, lng, zoom); + } + + + // based on google js + // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js + // search for fromLatLngToPoint and fromPointToLatLng + private Point2D.Double pt(double lat, double lng) { + return pt(lat, lng, coord_pt); + } + + private Point2D.Double pt(double lat, double lng, Point2D.Double centre) { + Point2D.Double res = new Point2D.Double(); + double e; + + res.x = centre.x + lng*scale_x; + e = limit(Math.sin(Math.toRadians(lat)),-(1-1.0E-15),1-1.0E-15); + res.y = centre.y + 0.5*Math.log((1+e)/(1-e))*-scale_y; + return res; + } + + private Point2D.Double latlng(Point2D.Double pt) { + return latlng(pt, coord_pt); + } + private Point2D.Double latlng(Point2D.Double pt, Point2D.Double centre) { + double lat, lng; + double rads; + + lng = (pt.x - centre.x)/scale_x; + rads = 2 * Math.atan(Math.exp((pt.y-centre.y)/-scale_y)); + lat = Math.toDegrees(rads - Math.PI/2); + + return new Point2D.Double(lat,lng); + } + + static Color stateColors[] = { + Color.WHITE, // startup + Color.WHITE, // idle + Color.WHITE, // pad + Color.RED, // boost + Color.PINK, // fast + Color.YELLOW, // coast + Color.CYAN, // drogue + Color.BLUE, // main + Color.BLACK // landed + }; + + boolean drawn_landed_circle = false; + boolean nomaps = false; + public void show(AltosState state, int crc_errors) { + if (nomaps) + return; + if (!state.gps_ready && state.pad_lat == 0 && state.pad_lon == 0) + return; + double plat = (int)(state.pad_lat*200)/200.0; + double plon = (int)(state.pad_lon*200)/200.0; + + if (last_pt == null) { + if (!setLocation(plat, plon)) { + nomaps = true; + return; + } + } + + Point2D.Double pt = pt(state.gps.lat, state.gps.lon); + if (last_pt != null && pt != last_pt) { + if (0 <= state.state && state.state < stateColors.length) { + g2d.setColor(stateColors[state.state]); + } + g2d.draw(new Line2D.Double(last_pt, pt)); + } + + if (state.state == 8 && !drawn_landed_circle) { + drawn_landed_circle = true; + g2d.setColor(Color.RED); + g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); + g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); + g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); + } + + last_pt = pt; + repaint(); + } + + public AltosSiteMapTile(int x_tile_offset, int y_tile_offset) { + off_x = x_tile_offset; + off_y = y_tile_offset; + } +} + diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 1c24ce13..b6b2e572 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -62,6 +62,7 @@ altosui_JAVA = \ AltosSerialInUseException.java \ AltosSerialMonitor.java \ AltosSiteMap.java \ + AltosSiteMapTile.java \ AltosState.java \ AltosTelemetry.java \ AltosTelemetryIterable.java \ -- cgit v1.2.3 From fda93afcd8aa4133b0e5f008b824d072e338d0ed Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 19 Nov 2010 13:02:05 +1000 Subject: AltosSiteMapTile: autoscale to about 2 nmi per tile --- ao-tools/altosui/AltosSiteMapTile.java | 37 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index d84941ae..919de825 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -32,7 +32,6 @@ import java.awt.geom.Point2D; import java.awt.geom.Line2D; public class AltosSiteMapTile extends JLabel { - double lat, lng; int zoom; double scale_x, scale_y; Point2D.Double coord_pt; @@ -45,16 +44,20 @@ public class AltosSiteMapTile extends JLabel { int px_size = 512; - private boolean setLocation(double new_lat, double new_lng) { - int new_zoom = 16; - lat = new_lat; - lng = new_lng; - zoom = new_zoom; + private boolean setLocation(double lat, double lng) { + Point2D.Double north_1nm; + for (zoom = 3; zoom < 22; zoom++) { + coord_pt = pt(lat, lng, new Point2D.Double(0,0), zoom); + north_1nm = pt(lat+1/60.0, lng, new Point2D.Double(0,0), zoom); + if (coord_pt.y - north_1nm.y > px_size/2) + break; + } + coord_pt.x = px_size/2 - ((long)coord_pt.x/px_size + off_x) * px_size; + coord_pt.y = px_size/2 - ((long)coord_pt.y/px_size + off_y) * px_size; + scale_x = 256/360.0 * Math.pow(2, zoom); scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - coord_pt = pt(lat, lng, new Point2D.Double(0,0)); - coord_pt.x = px_size/2-coord_pt.x - off_x * px_size; - coord_pt.y = px_size/2-coord_pt.y - off_y * px_size; + last_pt = null; Point2D.Double map_latlng; @@ -97,7 +100,7 @@ public class AltosSiteMapTile extends JLabel { char chlng = lng < 0 ? 'E' : 'W'; if (lat < 0) lat = -lat; if (lng < 0) lng = -lng; - return String.format("map-%c%.3f,%c%.3f-%d.png", + return String.format("map-%c%.6f,%c%.6f-%d.png", chlat, lat, chlng, lng, zoom); } @@ -106,10 +109,20 @@ public class AltosSiteMapTile extends JLabel { // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js // search for fromLatLngToPoint and fromPointToLatLng private Point2D.Double pt(double lat, double lng) { - return pt(lat, lng, coord_pt); + return pt(lat, lng, coord_pt, scale_x, scale_y); + } + + private static Point2D.Double pt(double lat, double lng, + Point2D.Double centre, int zoom) + { + double scale_x = 256/360.0 * Math.pow(2, zoom); + double scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + return pt(lat, lng, centre, scale_x, scale_y); } - private Point2D.Double pt(double lat, double lng, Point2D.Double centre) { + private static Point2D.Double pt(double lat, double lng, + Point2D.Double centre, double scale_x, double scale_y) + { Point2D.Double res = new Point2D.Double(); double e; -- cgit v1.2.3 From fa45336062523838ba8abb08427cdc4d9c7de7a8 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 19 Nov 2010 13:17:29 +1000 Subject: AltosSiteMapTile: adjust centering calculation --- ao-tools/altosui/AltosSiteMapTile.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index 919de825..6f5ddede 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -52,8 +52,8 @@ public class AltosSiteMapTile extends JLabel { if (coord_pt.y - north_1nm.y > px_size/2) break; } - coord_pt.x = px_size/2 - ((long)coord_pt.x/px_size + off_x) * px_size; - coord_pt.y = px_size/2 - ((long)coord_pt.y/px_size + off_y) * px_size; + coord_pt.x = -px_size * Math.floor(coord_pt.x/px_size + off_x); + coord_pt.y = -px_size * Math.floor(coord_pt.y/px_size + off_y); scale_x = 256/360.0 * Math.pow(2, zoom); scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); -- cgit v1.2.3 From 90b9bc4475011bead7117ed72fa5efa0f77b2813 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 19 Nov 2010 13:30:00 +1000 Subject: AltosSiteMapTile: adjust scale to 1 nmi per tile --- ao-tools/altosui/AltosSiteMapTile.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index 6f5ddede..c14fb93f 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -45,11 +45,13 @@ public class AltosSiteMapTile extends JLabel { int px_size = 512; private boolean setLocation(double lat, double lng) { - Point2D.Double north_1nm; + Point2D.Double north_step; + double step_nm = 0.5; for (zoom = 3; zoom < 22; zoom++) { coord_pt = pt(lat, lng, new Point2D.Double(0,0), zoom); - north_1nm = pt(lat+1/60.0, lng, new Point2D.Double(0,0), zoom); - if (coord_pt.y - north_1nm.y > px_size/2) + north_step = pt(lat+step_nm/60.0, lng, + new Point2D.Double(0,0), zoom); + if (coord_pt.y - north_step.y > px_size/2) break; } coord_pt.x = -px_size * Math.floor(coord_pt.x/px_size + off_x); -- cgit v1.2.3 From 24ffcf86c43290ce0f70fb4ee0984b3debdb8a5f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 Nov 2010 15:41:30 +0800 Subject: altosui: Add igniter ground testing code Not yet hooked up, but the UI is finished. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosIgnite.java | 155 ++++++++++++++++++++++++++++++ ao-tools/altosui/AltosIgniteUI.java | 183 ++++++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 23 +++-- ao-tools/altosui/Makefile.am | 2 + 4 files changed, 357 insertions(+), 6 deletions(-) create mode 100644 ao-tools/altosui/AltosIgnite.java create mode 100644 ao-tools/altosui/AltosIgniteUI.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosIgnite.java b/ao-tools/altosui/AltosIgnite.java new file mode 100644 index 00000000..5c27e8fa --- /dev/null +++ b/ao-tools/altosui/AltosIgnite.java @@ -0,0 +1,155 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.io.*; + +public class AltosIgnite { + AltosDevice device; + AltosSerial serial; + boolean remote; + final static int None = 0; + final static int Apogee = 1; + final static int Main = 2; + + final static int Unknown = 0; + final static int Ready = 1; + final static int Active = 2; + final static int Open = 3; + + private void start_serial() throws InterruptedException { + if (remote) { + serial.set_channel(AltosPreferences.channel(device.getSerial())); + serial.set_callsign(AltosPreferences.callsign()); + serial.printf("~\np\n"); + serial.flush_input(); + } + } + + private void stop_serial() throws InterruptedException { + if (serial == null) + return; + if (remote) { + serial.printf("~"); + serial.flush_output(); + } + } + + class string_ref { + String value; + + public String get() { + return value; + } + public void set(String i) { + value = i; + } + public string_ref() { + value = null; + } + } + + private boolean get_string(String line, String label, string_ref s) { + if (line.startsWith(label)) { + String quoted = line.substring(label.length()).trim(); + + if (quoted.startsWith("\"")) + quoted = quoted.substring(1); + if (quoted.endsWith("\"")) + quoted = quoted.substring(0,quoted.length()-1); + s.set(quoted); + return true; + } else { + return false; + } + } + + private int status(String status_name) { + if (status_name.equals("unknown")) + return Unknown; + if (status_name.equals("ready")) + return Ready; + if (status_name.equals("active")) + return Active; + if (status_name.equals("open")) + return Open; + return Unknown; + } + + public int status(int igniter) { + int status = Unknown; + if (serial == null) + return status; + string_ref status_name = new string_ref(); + try { + start_serial(); + serial.printf("t\n"); + for (;;) { + String line = serial.get_reply(); + if (get_string(line, "Igniter: drogue Status: ", status_name)) + if (igniter == Apogee) + status = status(status_name.get()); + if (get_string(line, "Igniter: main Status: ", status_name)) { + if (igniter == Main) + status = status(status_name.get()); + break; + } + } + } catch (InterruptedException ie) { + } finally { + try { + stop_serial(); + } catch (InterruptedException ie) { + } + } + return status; + } + + public void fire(int igniter) { + if (serial == null) + return; + try { + start_serial(); + switch (igniter) { + case Main: + serial.printf("i DoIt main\n"); + break; + case Apogee: + serial.printf("i DoIt drogue\n"); + break; + } + } catch (InterruptedException ie) { + } finally { + try { + stop_serial(); + } catch (InterruptedException ie) { + } + } + } + + public AltosIgnite(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { + + device = in_device; + serial = null; +// serial = new AltosSerial(device); + remote = false; + +// if (!device.matchProduct(AltosDevice.product_telemetrum)) +// remote = true; + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosIgniteUI.java b/ao-tools/altosui/AltosIgniteUI.java new file mode 100644 index 00000000..62da413c --- /dev/null +++ b/ao-tools/altosui/AltosIgniteUI.java @@ -0,0 +1,183 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import javax.swing.event.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; + +public class AltosIgniteUI + extends JDialog + implements ActionListener +{ + JFrame owner; + JLabel label; + JRadioButton apogee; + JRadioButton main; + JToggleButton arm; + JButton fire; + javax.swing.Timer timer; + + final static int timeout = 1 * 1000; + + int time_remaining; + + void set_arm_text() { + if (arm.isSelected()) + arm.setText(String.format("%d", time_remaining)); + else + arm.setText("Arm"); + } + + void start_timer() { + time_remaining = 10; + set_arm_text(); + timer.restart(); + } + + void stop_timer() { + time_remaining = 0; + arm.setSelected(false); + arm.setEnabled(false); + fire.setEnabled(false); + timer.stop(); + set_arm_text(); + } + + void cancel () { + apogee.setSelected(false); + main.setSelected(false); + fire.setEnabled(false); + stop_timer(); + } + + void tick_timer() { + --time_remaining; + if (time_remaining <= 0) + cancel(); + else + set_arm_text(); + } + + void fire() { + if (arm.isEnabled() && arm.isSelected() && time_remaining > 0) { + int igniter = AltosIgnite.None; + if (apogee.isSelected() && !main.isSelected()) + igniter = AltosIgnite.Apogee; + else if (main.isSelected() && !apogee.isSelected()) + igniter = AltosIgnite.Main; + System.out.printf ("fire %d\n", igniter); + cancel(); + } + } + + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + if (cmd.equals("apogee") || cmd.equals("main")) { + stop_timer(); + arm.setEnabled(true); + } + + if (cmd.equals("apogee") && apogee.isSelected()) + main.setSelected(false); + if (cmd.equals("main") && main.isSelected()) + apogee.setSelected(false); + + if (cmd.equals("arm")) { + if (arm.isSelected()) { + fire.setEnabled(true); + start_timer(); + } else + cancel(); + } + if (cmd.equals("fire")) + fire(); + if (cmd.equals("tick")) + tick_timer(); + } + + public AltosIgniteUI(JFrame in_owner) { + Container pane = getContentPane(); + GridBagConstraints c = new GridBagConstraints(); + Insets i = new Insets(4,4,4,4); + + timer = new javax.swing.Timer(timeout, this); + timer.setActionCommand("tick"); + + owner = in_owner; + + pane.setLayout(new GridBagLayout()); + + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + c.weightx = 1; + c.weighty = 1; + + c.gridx = 0; + c.gridy = 0; + c.gridwidth = 2; + label = new JLabel ("Fire Igniter"); + pane.add(label, c); + + c.gridx = 0; + c.gridy = 1; + c.gridwidth = 1; + apogee = new JRadioButton ("Apogee"); + pane.add(apogee, c); + apogee.addActionListener(this); + apogee.setActionCommand("apogee"); + + c.gridx = 1; + c.gridy = 1; + c.gridwidth = 1; + main = new JRadioButton ("Main"); + pane.add(main, c); + main.addActionListener(this); + main.setActionCommand("main"); + + c.gridx = 0; + c.gridy = 2; + c.gridwidth = 1; + arm = new JToggleButton ("Arm"); + pane.add(arm, c); + arm.addActionListener(this); + arm.setActionCommand("arm"); + arm.setEnabled(false); + + c.gridx = 1; + c.gridy = 2; + c.gridwidth = 1; + fire = new JButton ("Fire"); + fire.setEnabled(false); + pane.add(fire, c); + fire.addActionListener(this); + fire.setActionCommand("fire"); + + pack(); + setLocationRelativeTo(owner); + setVisible(true); + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index bedf2459..5e9566f0 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -125,40 +125,47 @@ public class AltosUI extends JFrame { Replay(); } }); - b = addButton(0, 1, "Graph Data"); + b = addButton(3, 0, "Graph Data"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GraphData(); } }); - b = addButton(1, 1, "Export Data"); + b = addButton(4, 0, "Export Data"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ExportData(); } }); - b = addButton(2, 1, "Configure TeleMetrum"); + b = addButton(0, 1, "Configure TeleMetrum"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ConfigureTeleMetrum(); } }); - b = addButton(0, 2, "Configure AltosUI"); + b = addButton(1, 1, "Configure AltosUI"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ConfigureAltosUI(); } }); - b = addButton(1, 2, "Flash Image"); + b = addButton(2, 1, "Flash Image"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FlashImage(); } }); - b = addButton(2, 2, "Quit"); + b = addButton(3, 1, "Fire Igniter"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + FireIgniter(); + } + }); + + b = addButton(4, 1, "Quit"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); @@ -215,6 +222,10 @@ public class AltosUI extends JFrame { new AltosFlashUI(AltosUI.this); } + void FireIgniter() { + new AltosIgniteUI(AltosUI.this); + } + /* * Replay a flight from telemetry data */ diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 8d0fe16e..25977b12 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -40,6 +40,8 @@ altosui_JAVA = \ AltosGreatCircle.java \ AltosHexfile.java \ Altos.java \ + AltosIgnite.java \ + AltosIgniteUI.java \ AltosInfoTable.java \ AltosKML.java \ AltosLanded.java \ -- cgit v1.2.3 From 8f72f08839346fb225238420324f0edcd070e531 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 Nov 2010 17:14:17 +0800 Subject: altosui: Unify datafile selection to AltosDataChooser Instead of having several separate intefaces, use a single dialog for selecting data files for graph/export/replay. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSVUI.java | 73 +++++++++++++------------- ao-tools/altosui/AltosDataChooser.java | 79 +++++++++++++++++++++++++++++ ao-tools/altosui/AltosGraphDataChooser.java | 79 ----------------------------- ao-tools/altosui/AltosGraphUI.java | 17 +++---- ao-tools/altosui/AltosLogfileChooser.java | 78 ---------------------------- ao-tools/altosui/AltosUI.java | 17 +++++-- ao-tools/altosui/Makefile.am | 3 +- 7 files changed, 140 insertions(+), 206 deletions(-) create mode 100644 ao-tools/altosui/AltosDataChooser.java delete mode 100644 ao-tools/altosui/AltosGraphDataChooser.java delete mode 100644 ao-tools/altosui/AltosLogfileChooser.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSVUI.java b/ao-tools/altosui/AltosCSVUI.java index 16f25338..e1b6002d 100644 --- a/ao-tools/altosui/AltosCSVUI.java +++ b/ao-tools/altosui/AltosCSVUI.java @@ -30,16 +30,15 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosCSVUI extends JDialog - implements Runnable, ActionListener + implements ActionListener { - JFrame frame; - Thread thread; - AltosRecordIterable iterable; - AltosWriter writer; JFileChooser csv_chooser; + JPanel accessory; JComboBox combo_box; + AltosRecordIterable iterable; + AltosWriter writer; - static String[] combo_box_items = { "CSV", "KML" }; + static String[] combo_box_items = { "Comma Separated Values (.CSV)", "Googleearth Data (.KML)" }; void set_default_file() { File current = csv_chooser.getSelectedFile(); @@ -47,57 +46,63 @@ public class AltosCSVUI String new_name = null; String selected = (String) combo_box.getSelectedItem(); - if (selected.equals("CSV")) + if (selected.contains("CSV")) new_name = Altos.replace_extension(current_name, ".csv"); - else if (selected.equals("KML")) + else if (selected.contains("KML")) new_name = Altos.replace_extension(current_name, ".kml"); if (new_name != null) csv_chooser.setSelectedFile(new File(new_name)); } - public void run() { - AltosLogfileChooser chooser; + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("comboBoxChanged")) + set_default_file(); + } + + public AltosCSVUI(JFrame frame, AltosRecordIterable in_iterable, File source_file) { + iterable = in_iterable; + csv_chooser = new JFileChooser(source_file); + + accessory = new JPanel(); + accessory.setLayout(new GridBagLayout()); - chooser = new AltosLogfileChooser(frame); - iterable = chooser.runDialog(); - if (iterable == null) - return; + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.weightx = 1; + c.weighty = 0; + c.insets = new Insets (4, 4, 4, 4); + + JLabel accessory_label = new JLabel("Export File Type"); + c.gridx = 0; + c.gridy = 0; + accessory.add(accessory_label, c); - csv_chooser = new JFileChooser(chooser.file()); combo_box = new JComboBox(combo_box_items); combo_box.addActionListener(this); - csv_chooser.setAccessory(combo_box); - csv_chooser.setSelectedFile(chooser.file()); + c.gridx = 0; + c.gridy = 1; + accessory.add(combo_box, c); + + csv_chooser.setAccessory(accessory); + csv_chooser.setSelectedFile(source_file); set_default_file(); int ret = csv_chooser.showSaveDialog(frame); if (ret == JFileChooser.APPROVE_OPTION) { - File file = csv_chooser.getSelectedFile(); - String type = (String) combo_box.getSelectedItem(); + File file = csv_chooser.getSelectedFile(); + String type = (String) combo_box.getSelectedItem(); try { - if (type.equals("CSV")) + if (type.contains("CSV")) writer = new AltosCSV(file); else writer = new AltosKML(file); + writer.write(iterable); + writer.close(); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, file.getName(), "Cannot open file", JOptionPane.ERROR_MESSAGE); } - writer.write(iterable); - writer.close(); } } - - public void actionPerformed(ActionEvent e) { - System.out.printf("command %s param %s\n", e.getActionCommand(), e.paramString()); - if (e.getActionCommand().equals("comboBoxChanged")) - set_default_file(); - } - - public AltosCSVUI(JFrame in_frame) { - frame = in_frame; - thread = new Thread(this); - thread.start(); - } } diff --git a/ao-tools/altosui/AltosDataChooser.java b/ao-tools/altosui/AltosDataChooser.java new file mode 100644 index 00000000..15de05c2 --- /dev/null +++ b/ao-tools/altosui/AltosDataChooser.java @@ -0,0 +1,79 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; + +public class AltosDataChooser extends JFileChooser { + JFrame frame; + String filename; + File file; + + public String filename() { + return filename; + } + + public File file() { + return file; + } + + public AltosRecordIterable runDialog() { + int ret; + + ret = showOpenDialog(frame); + if (ret == APPROVE_OPTION) { + file = getSelectedFile(); + if (file == null) + return null; + filename = file.getName(); + try { + if (filename.endsWith("eeprom")) { + FileInputStream in = new FileInputStream(file); + return new AltosEepromIterable(in); + } else if (filename.endsWith("telem")) { + FileInputStream in = new FileInputStream(file); + return new AltosTelemetryIterable(in); + } else { + throw new FileNotFoundException(); + } + } catch (FileNotFoundException fe) { + JOptionPane.showMessageDialog(frame, + filename, + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + } + return null; + } + + public AltosDataChooser(JFrame in_frame) { + frame = in_frame; + setDialogTitle("Select Flight Record File"); + setFileFilter(new FileNameExtensionFilter("Flight data file", + "telem", "eeprom")); + setCurrentDirectory(AltosPreferences.logdir()); + } +} diff --git a/ao-tools/altosui/AltosGraphDataChooser.java b/ao-tools/altosui/AltosGraphDataChooser.java deleted file mode 100644 index d128f4d5..00000000 --- a/ao-tools/altosui/AltosGraphDataChooser.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; - -public class AltosGraphDataChooser extends JFileChooser { - JFrame frame; - String filename; - File file; - - public String filename() { - return filename; - } - - public File file() { - return file; - } - - public Iterable runDialog() { - int ret; - - ret = showOpenDialog(frame); - if (ret == APPROVE_OPTION) { - file = getSelectedFile(); - if (file == null) - return null; - filename = file.getName(); - try { - if (filename.endsWith("eeprom")) { - FileInputStream in = new FileInputStream(file); - return new AltosDataPointReader(new AltosEepromIterable(in)); - } else if (filename.endsWith("telem")) { - FileInputStream in = new FileInputStream(file); - return new AltosDataPointReader(new AltosTelemetryIterable(in)); - } else { - throw new FileNotFoundException(); - } - } catch (FileNotFoundException fe) { - JOptionPane.showMessageDialog(frame, - filename, - "Cannot open file", - JOptionPane.ERROR_MESSAGE); - } - } - return null; - } - - public AltosGraphDataChooser(JFrame in_frame) { - frame = in_frame; - setDialogTitle("Select Flight Record File"); - setFileFilter(new FileNameExtensionFilter("Flight data file", - "telem", "eeprom")); - setCurrentDirectory(AltosPreferences.logdir()); - } -} diff --git a/ao-tools/altosui/AltosGraphUI.java b/ao-tools/altosui/AltosGraphUI.java index 908aa3b4..cd158651 100644 --- a/ao-tools/altosui/AltosGraphUI.java +++ b/ao-tools/altosui/AltosGraphUI.java @@ -151,18 +151,15 @@ public class AltosGraphUI extends JFrame } } - public AltosGraphUI(JFrame frame) - { - super("Altos Graph"); + public AltosGraphUI(AltosRecordIterable records) { + super("Altos Graph"); - AltosGraphDataChooser chooser; - chooser = new AltosGraphDataChooser(frame); - Iterable reader = chooser.runDialog(); - if (reader == null) - return; + Iterable reader = new AltosDataPointReader (records); + if (reader == null) + return; - init(reader, 0); - } + init(reader, 0); + } public AltosGraphUI(Iterable data, int which) { diff --git a/ao-tools/altosui/AltosLogfileChooser.java b/ao-tools/altosui/AltosLogfileChooser.java deleted file mode 100644 index 8b9d77d6..00000000 --- a/ao-tools/altosui/AltosLogfileChooser.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; - -public class AltosLogfileChooser extends JFileChooser { - JFrame frame; - String filename; - File file; - - public String filename() { - return filename; - } - - public File file() { - return file; - } - - public AltosRecordIterable runDialog() { - int ret; - - ret = showOpenDialog(frame); - if (ret == APPROVE_OPTION) { - file = getSelectedFile(); - if (file == null) - return null; - filename = file.getName(); - try { - FileInputStream in; - - in = new FileInputStream(file); - if (filename.endsWith("eeprom")) - return new AltosEepromIterable(in); - else - return new AltosTelemetryIterable(in); - } catch (FileNotFoundException fe) { - JOptionPane.showMessageDialog(frame, - filename, - "Cannot open file", - JOptionPane.ERROR_MESSAGE); - } - } - return null; - } - - public AltosLogfileChooser(JFrame in_frame) { - frame = in_frame; - setDialogTitle("Select Flight Record File"); - setFileFilter(new FileNameExtensionFilter("Flight data file", - "eeprom", - "telem")); - setCurrentDirectory(AltosPreferences.logdir()); - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 5e9566f0..c82c8e8a 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -230,8 +230,9 @@ public class AltosUI extends JFrame { * Replay a flight from telemetry data */ private void Replay() { - AltosLogfileChooser chooser = new AltosLogfileChooser( + AltosDataChooser chooser = new AltosDataChooser( AltosUI.this); + AltosRecordIterable iterable = chooser.runDialog(); if (iterable != null) { AltosFlightReader reader = new AltosReplayReader(iterable.iterator(), @@ -252,14 +253,24 @@ public class AltosUI extends JFrame { */ private void ExportData() { - new AltosCSVUI(AltosUI.this); + AltosDataChooser chooser; + chooser = new AltosDataChooser(this); + AltosRecordIterable record_reader = chooser.runDialog(); + if (record_reader == null) + return; + new AltosCSVUI(AltosUI.this, record_reader, chooser.file()); } /* Load a flight log CSV file and display a pretty graph. */ private void GraphData() { - new AltosGraphUI(AltosUI.this); + AltosDataChooser chooser; + chooser = new AltosDataChooser(this); + AltosRecordIterable record_reader = chooser.runDialog(); + if (record_reader == null) + return; + new AltosGraphUI(record_reader); } private void ConfigureAltosUI() { diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 25977b12..a603ca8a 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -48,7 +48,6 @@ altosui_JAVA = \ AltosLed.java \ AltosLights.java \ AltosLine.java \ - AltosLogfileChooser.java \ AltosLog.java \ AltosPad.java \ AltosParse.java \ @@ -73,7 +72,7 @@ altosui_JAVA = \ AltosGraph.java \ AltosGraphTime.java \ AltosGraphUI.java \ - AltosGraphDataChooser.java \ + AltosDataChooser.java \ AltosVoice.java JFREECHART_CLASS= \ -- cgit v1.2.3 From 0e7a10f71803d60f8b34c5a91efd220449442769 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 Nov 2010 17:16:03 +0800 Subject: altosui: Clean up global AltosUI configuration settings dialog This dialog had a mish-mash of styles and was confusing. Now it's got a label for each line, and suitable setters for each element Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfigureUI.java | 71 +++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 18 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfigureUI.java b/ao-tools/altosui/AltosConfigureUI.java index 64c17eaf..153c59fd 100644 --- a/ao-tools/altosui/AltosConfigureUI.java +++ b/ao-tools/altosui/AltosConfigureUI.java @@ -75,12 +75,25 @@ public class AltosConfigureUI c = new GridBagConstraints(); c.insets = insets; c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; + c.anchor = GridBagConstraints.WEST; - /* Enable Voice */ + /* Nice label at the top */ c.gridx = 0; c.gridy = 0; - enable_voice = new JRadioButton("Enable Voice", AltosPreferences.voice()); + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + pane.add(new JLabel ("Configure AltOS UI"), c); + + /* Voice settings */ + c.gridx = 0; + c.gridy = 1; + c.gridwidth = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + pane.add(new JLabel("Voice"), c); + + enable_voice = new JRadioButton("Enable", AltosPreferences.voice()); enable_voice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JRadioButton item = (JRadioButton) e.getSource(); @@ -92,9 +105,20 @@ public class AltosConfigureUI voice.speak_always("Disable voice."); } }); - pane.add(enable_voice, c); c.gridx = 1; - c.gridy = 0; + c.gridy = 1; + c.gridwidth = 1; + c.weightx = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + pane.add(enable_voice, c); + + c.gridx = 2; + c.gridy = 1; + c.gridwidth = 1; + c.weightx = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.EAST; test_voice = new JButton("Test Voice"); test_voice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -103,36 +127,46 @@ public class AltosConfigureUI }); pane.add(test_voice, c); - configure_log = new JButton("Configure Log"); + /* Log directory settings */ + c.gridx = 0; + c.gridy = 2; + c.gridwidth = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + pane.add(new JLabel("Log Directory"), c); + + configure_log = new JButton(AltosPreferences.logdir().getPath()); configure_log.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AltosPreferences.ConfigureLog(); - log_directory.setText(AltosPreferences.logdir().getPath()); + configure_log.setText(AltosPreferences.logdir().getPath()); } }); - c.gridwidth = 1; - - c.gridx = 0; - c.gridy = 2; - pane.add(configure_log, c); - - log_directory = new JTextField(AltosPreferences.logdir().getPath()); c.gridx = 1; c.gridy = 2; + c.gridwidth = 2; c.fill = GridBagConstraints.BOTH; - pane.add(log_directory, c); + c.anchor = GridBagConstraints.WEST; + pane.add(configure_log, c); - callsign_label = new JLabel("Callsign"); + /* Callsign setting */ c.gridx = 0; c.gridy = 3; - pane.add(callsign_label, c); + c.gridwidth = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + pane.add(new JLabel("Callsign"), c); callsign_value = new JTextField(AltosPreferences.callsign()); callsign_value.getDocument().addDocumentListener(this); c.gridx = 1; c.gridy = 3; + c.gridwidth = 2; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.WEST; pane.add(callsign_value, c); + /* And a close button at the bottom */ close = new JButton("Close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -141,8 +175,9 @@ public class AltosConfigureUI }); c.gridx = 0; c.gridy = 4; - c.gridwidth = 2; + c.gridwidth = 3; c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; pane.add(close, c); pack(); -- cgit v1.2.3 From 9ffc2eb53a47e435f39b02896b0e43ae5f47f450 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 Nov 2010 18:25:48 -0800 Subject: altosui: Use timeouts to recover from broken packet links. This puts timeouts every place the system reads from the packet link and aborts the in-progress operation if it takes more than a second to get a response. Also mixed in here are persistent igniter status displays for the ejection testing UI. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 95 +++++++++-------- ao-tools/altosui/AltosEepromDownload.java | 26 +++-- ao-tools/altosui/AltosFlashUI.java | 2 +- ao-tools/altosui/AltosIgnite.java | 58 ++++++----- ao-tools/altosui/AltosIgniteUI.java | 162 ++++++++++++++++++++++++++--- ao-tools/altosui/AltosSerial.java | 11 +- ao-tools/altosui/AltosTelemetryReader.java | 2 +- ao-tools/altosui/AltosUI.java | 6 +- 8 files changed, 268 insertions(+), 94 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index a0fdb623..19503dcb 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -26,7 +26,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.*; import libaltosJNI.*; @@ -123,12 +123,14 @@ public class AltosConfig implements Runnable, ActionListener { } } - void get_data() throws InterruptedException { + void get_data() throws InterruptedException, TimeoutException { try { start_serial(); serial_line.printf("c s\nv\n"); for (;;) { - String line = serial_line.get_reply(); + String line = serial_line.get_reply(1000); + if (line == null) + throw new TimeoutException(); get_int(line, "serial-number", serial); get_int(line, "Main deploy:", main_deploy); get_int(line, "Apogee delay:", apogee_delay); @@ -147,27 +149,34 @@ public class AltosConfig implements Runnable, ActionListener { } } - void init_ui () { + void init_ui () throws InterruptedException, TimeoutException { config_ui = new AltosConfigUI(owner); config_ui.addActionListener(this); set_ui(); } - void set_ui() { - try { - if (serial_line != null) - get_data(); - config_ui.set_serial(serial.get()); - config_ui.set_product(product.get()); - config_ui.set_version(version.get()); - config_ui.set_main_deploy(main_deploy.get()); - config_ui.set_apogee_delay(apogee_delay.get()); - config_ui.set_radio_channel(radio_channel.get()); - config_ui.set_radio_calibration(radio_calibration.get()); - config_ui.set_callsign(callsign.get()); - config_ui.set_clean(); - } catch (InterruptedException ie) { - } + void abort() { + JOptionPane.showMessageDialog(owner, + String.format("Connection to \"%s\" failed", + device.toString()), + "Connection Failed", + JOptionPane.ERROR_MESSAGE); + serial_line.close(); + serial_line = null; + } + + void set_ui() throws InterruptedException, TimeoutException { + if (serial_line != null) + get_data(); + config_ui.set_serial(serial.get()); + config_ui.set_product(product.get()); + config_ui.set_version(version.get()); + config_ui.set_main_deploy(main_deploy.get()); + config_ui.set_apogee_delay(apogee_delay.get()); + config_ui.set_radio_channel(radio_channel.get()); + config_ui.set_radio_calibration(radio_calibration.get()); + config_ui.set_callsign(callsign.get()); + config_ui.set_clean(); } void run_dialog() { @@ -198,28 +207,28 @@ public class AltosConfig implements Runnable, ActionListener { public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); - if (cmd.equals("Save")) { - save_data(); - set_ui(); - } else if (cmd.equals("Reset")) { - set_ui(); - } else if (cmd.equals("Reboot")) { - if (serial_line != null) { - try { + try { + if (cmd.equals("Save")) { + save_data(); + set_ui(); + } else if (cmd.equals("Reset")) { + set_ui(); + } else if (cmd.equals("Reboot")) { + if (serial_line != null) { start_serial(); serial_line.printf("r eboot\n"); - } catch (InterruptedException ie) { - } finally { - try { - stop_serial(); - } catch (InterruptedException ie) { - } + serial_line.flush_output(); + stop_serial(); + serial_line.close(); } - serial_line.close(); + } else if (cmd.equals("Close")) { + if (serial_line != null) + serial_line.close(); } - } else if (cmd.equals("Close")) { - if (serial_line != null) - serial_line.close(); + } catch (InterruptedException ie) { + abort(); + } catch (TimeoutException te) { + abort(); } } @@ -227,8 +236,10 @@ public class AltosConfig implements Runnable, ActionListener { try { init_ui(); config_ui.make_visible(); -// } catch (InterruptedException ie) { - } finally { + } catch (InterruptedException ie) { + abort(); + } catch (TimeoutException te) { + abort(); } } @@ -255,18 +266,18 @@ public class AltosConfig implements Runnable, ActionListener { } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(owner, String.format("Cannot open device \"%s\"", - device.getPath()), + device.toString()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(owner, String.format("Device \"%s\" already in use", - device.getPath()), + device.toString()), "Device in use", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(owner, - device.getPath(), + device.toString(), ee.getLocalizedMessage(), JOptionPane.ERROR_MESSAGE); } diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 8996b924..912ff476 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -26,7 +26,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.*; import libaltosJNI.*; @@ -78,7 +78,7 @@ public class AltosEepromDownload implements Runnable { Thread eeprom_thread; AltosEepromMonitor monitor; - void CaptureLog() throws IOException, InterruptedException { + void CaptureLog() throws IOException, InterruptedException, TimeoutException { int serial = 0; int block, state_block = 0; int addr; @@ -97,8 +97,10 @@ public class AltosEepromDownload implements Runnable { /* Pull the serial number out of the version information */ for (;;) { - String line = serial_line.get_reply(); + String line = serial_line.get_reply(1000); + if (line == null) + throw new TimeoutException(); if (line.startsWith("serial-number")) { try { serial = Integer.parseInt(line.substring(13).trim()); @@ -125,7 +127,9 @@ public class AltosEepromDownload implements Runnable { any_valid = false; monitor.set_value(state_names[state], state, block - state_block); for (addr = 0; addr < 0x100;) { - String line = serial_line.get_reply(); + String line = serial_line.get_reply(1000); + if (line == null) + throw new TimeoutException(); int[] values = ParseHex(line); if (values == null) { @@ -228,10 +232,16 @@ public class AltosEepromDownload implements Runnable { CaptureLog(); } catch (IOException ee) { JOptionPane.showMessageDialog(frame, - device.getPath(), + device.toString(), ee.getLocalizedMessage(), JOptionPane.ERROR_MESSAGE); } catch (InterruptedException ie) { + } catch (TimeoutException te) { + JOptionPane.showMessageDialog(frame, + String.format("Connection to \"%s\" failed", + device.toString()), + "Connection Failed", + JOptionPane.ERROR_MESSAGE); } if (remote) serial_line.printf("~"); @@ -256,18 +266,18 @@ public class AltosEepromDownload implements Runnable { } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, String.format("Cannot open device \"%s\"", - device.getPath()), + device.toString()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(frame, String.format("Device \"%s\" already in use", - device.getPath()), + device.toString()), "Device in use", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(frame, - device.getPath(), + device.toString(), ee.getLocalizedMessage(), JOptionPane.ERROR_MESSAGE); } diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index b09cb594..d3b72c67 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -90,7 +90,7 @@ public class AltosFlashUI } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(frame, String.format("Device \"%s\" already in use", - debug_dongle.getPath()), + debug_dongle.toString()), "Device in use", JOptionPane.ERROR_MESSAGE); } catch (IOException e) { diff --git a/ao-tools/altosui/AltosIgnite.java b/ao-tools/altosui/AltosIgnite.java index 5c27e8fa..8e92ec1b 100644 --- a/ao-tools/altosui/AltosIgnite.java +++ b/ao-tools/altosui/AltosIgnite.java @@ -18,6 +18,7 @@ package altosui; import java.io.*; +import java.util.concurrent.*; public class AltosIgnite { AltosDevice device; @@ -91,35 +92,40 @@ public class AltosIgnite { return Unknown; } - public int status(int igniter) { + public int status(int igniter) throws InterruptedException, TimeoutException { int status = Unknown; if (serial == null) return status; string_ref status_name = new string_ref(); - try { - start_serial(); - serial.printf("t\n"); - for (;;) { - String line = serial.get_reply(); - if (get_string(line, "Igniter: drogue Status: ", status_name)) - if (igniter == Apogee) - status = status(status_name.get()); - if (get_string(line, "Igniter: main Status: ", status_name)) { - if (igniter == Main) - status = status(status_name.get()); - break; - } - } - } catch (InterruptedException ie) { - } finally { - try { - stop_serial(); - } catch (InterruptedException ie) { + start_serial(); + serial.printf("t\n"); + for (;;) { + String line = serial.get_reply(1000); + if (line == null) + throw new TimeoutException(); + if (get_string(line, "Igniter: drogue Status: ", status_name)) + if (igniter == Apogee) + status = status(status_name.get()); + if (get_string(line, "Igniter: main Status: ", status_name)) { + if (igniter == Main) + status = status(status_name.get()); + break; } } + stop_serial(); return status; } + public String status_string(int status) { + switch (status) { + case Unknown: return "Unknown"; + case Ready: return "Ready"; + case Active: return "Active"; + case Open: return "Open"; + default: return "Unknown"; + } + } + public void fire(int igniter) { if (serial == null) return; @@ -142,14 +148,18 @@ public class AltosIgnite { } } + public void close() { + serial.close(); + serial = null; + } + public AltosIgnite(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { device = in_device; - serial = null; -// serial = new AltosSerial(device); + serial = new AltosSerial(device); remote = false; -// if (!device.matchProduct(AltosDevice.product_telemetrum)) -// remote = true; + if (!device.matchProduct(AltosDevice.product_telemetrum)) + remote = true; } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosIgniteUI.java b/ao-tools/altosui/AltosIgniteUI.java index 62da413c..caecc3ef 100644 --- a/ao-tools/altosui/AltosIgniteUI.java +++ b/ao-tools/altosui/AltosIgniteUI.java @@ -27,22 +27,31 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; +import java.util.concurrent.*; public class AltosIgniteUI extends JDialog implements ActionListener { + AltosDevice device; + AltosIgnite ignite; JFrame owner; JLabel label; JRadioButton apogee; + JLabel apogee_status_label; JRadioButton main; + JLabel main_status_label; JToggleButton arm; JButton fire; javax.swing.Timer timer; + int apogee_status; + int main_status; + final static int timeout = 1 * 1000; int time_remaining; + boolean timer_running; void set_arm_text() { if (arm.isSelected()) @@ -54,7 +63,7 @@ public class AltosIgniteUI void start_timer() { time_remaining = 10; set_arm_text(); - timer.restart(); + timer_running = true; } void stop_timer() { @@ -62,7 +71,7 @@ public class AltosIgniteUI arm.setSelected(false); arm.setEnabled(false); fire.setEnabled(false); - timer.stop(); + timer_running = false; set_arm_text(); } @@ -73,12 +82,47 @@ public class AltosIgniteUI stop_timer(); } + void get_ignite_status() throws InterruptedException, TimeoutException { + apogee_status = ignite.status(AltosIgnite.Apogee); + main_status = ignite.status(AltosIgnite.Main); + } + + void set_ignite_status() throws InterruptedException, TimeoutException { + get_ignite_status(); + apogee_status_label.setText(String.format("\"%s\"", ignite.status_string(apogee_status))); + main_status_label.setText(String.format("\"%s\"", ignite.status_string(main_status))); + } + + void close() { + timer.stop(); + setVisible(false); + ignite.close(); + } + + void abort() { + close(); + JOptionPane.showMessageDialog(owner, + String.format("Connection to \"%s\" failed", + device.toString()), + "Connection Failed", + JOptionPane.ERROR_MESSAGE); + } + void tick_timer() { - --time_remaining; - if (time_remaining <= 0) - cancel(); - else - set_arm_text(); + if (timer_running) { + --time_remaining; + if (time_remaining <= 0) + cancel(); + else + set_arm_text(); + } + try { + set_ignite_status(); + } catch (InterruptedException ie) { + abort(); + } catch (TimeoutException te) { + abort(); + } } void fire() { @@ -88,7 +132,7 @@ public class AltosIgniteUI igniter = AltosIgnite.Apogee; else if (main.isSelected() && !apogee.isSelected()) igniter = AltosIgnite.Main; - System.out.printf ("fire %d\n", igniter); + ignite.fire(igniter); cancel(); } } @@ -97,13 +141,18 @@ public class AltosIgniteUI String cmd = e.getActionCommand(); if (cmd.equals("apogee") || cmd.equals("main")) { stop_timer(); - arm.setEnabled(true); } - if (cmd.equals("apogee") && apogee.isSelected()) + if (cmd.equals("apogee") && apogee.isSelected()) { main.setSelected(false); - if (cmd.equals("main") && main.isSelected()) + if (apogee_status == AltosIgnite.Ready) + arm.setEnabled(true); + } + if (cmd.equals("main") && main.isSelected()) { apogee.setSelected(false); + if (main_status == AltosIgnite.Ready) + arm.setEnabled(true); + } if (cmd.equals("arm")) { if (arm.isSelected()) { @@ -116,15 +165,71 @@ public class AltosIgniteUI fire(); if (cmd.equals("tick")) tick_timer(); + if (cmd.equals("close")) { + close(); + } + } + + /* A window listener to catch closing events and tell the config code */ + class ConfigListener extends WindowAdapter { + AltosIgniteUI ui; + + public ConfigListener(AltosIgniteUI this_ui) { + ui = this_ui; + } + + public void windowClosing(WindowEvent e) { + ui.actionPerformed(new ActionEvent(e.getSource(), + ActionEvent.ACTION_PERFORMED, + "close")); + } + } + + private boolean open() { + device = AltosDeviceDialog.show(owner, AltosDevice.product_any); + if (device != null) { + try { + ignite = new AltosIgnite(device); + return true; + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(owner, + String.format("Cannot open device \"%s\"", + device.toString()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(owner, + String.format("Device \"%s\" already in use", + device.toString()), + "Device in use", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(owner, + device.toString(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } + } + return false; } public AltosIgniteUI(JFrame in_owner) { + + owner = in_owner; + apogee_status = AltosIgnite.Unknown; + main_status = AltosIgnite.Unknown; + + if (!open()) + return; + Container pane = getContentPane(); GridBagConstraints c = new GridBagConstraints(); Insets i = new Insets(4,4,4,4); timer = new javax.swing.Timer(timeout, this); timer.setActionCommand("tick"); + timer_running = false; + timer.restart(); owner = in_owner; @@ -139,12 +244,14 @@ public class AltosIgniteUI c.gridx = 0; c.gridy = 0; c.gridwidth = 2; + c.anchor = GridBagConstraints.CENTER; label = new JLabel ("Fire Igniter"); pane.add(label, c); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; apogee = new JRadioButton ("Apogee"); pane.add(apogee, c); apogee.addActionListener(this); @@ -153,14 +260,40 @@ public class AltosIgniteUI c.gridx = 1; c.gridy = 1; c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; + apogee_status_label = new JLabel(); + pane.add(apogee_status_label, c); + + c.gridx = 0; + c.gridy = 2; + c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; main = new JRadioButton ("Main"); pane.add(main, c); main.addActionListener(this); main.setActionCommand("main"); - c.gridx = 0; + c.gridx = 1; c.gridy = 2; c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; + main_status_label = new JLabel(); + pane.add(main_status_label, c); + + try { + set_ignite_status(); + } catch (InterruptedException ie) { + abort(); + return; + } catch (TimeoutException te) { + abort(); + return; + } + + c.gridx = 0; + c.gridy = 3; + c.gridwidth = 1; + c.anchor = GridBagConstraints.CENTER; arm = new JToggleButton ("Arm"); pane.add(arm, c); arm.addActionListener(this); @@ -168,8 +301,9 @@ public class AltosIgniteUI arm.setEnabled(false); c.gridx = 1; - c.gridy = 2; + c.gridy = 3; c.gridwidth = 1; + c.anchor = GridBagConstraints.CENTER; fire = new JButton ("Fire"); fire.setEnabled(false); pane.add(fire, c); @@ -179,5 +313,7 @@ public class AltosIgniteUI pack(); setLocationRelativeTo(owner); setVisible(true); + + addWindowListener(new ConfigListener(this)); } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 99a92fdb..0d32a5ae 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -132,6 +132,14 @@ public class AltosSerial implements Runnable { return line.line; } + public String get_reply(int timeout) throws InterruptedException { + flush_output(); + AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS); + if (line == null) + return null; + return line.line; + } + public void add_monitor(LinkedBlockingQueue q) { set_monitor(true); monitors.add(q); @@ -185,10 +193,9 @@ public class AltosSerial implements Runnable { throw new AltosSerialInUseException(device); devices_opened.add(device.getPath()); } - close(); altos = libaltos.altos_open(device); if (altos == null) - throw new FileNotFoundException(device.getPath()); + throw new FileNotFoundException(device.toString()); input_thread = new Thread(this); input_thread.start(); print("~\nE 0\n"); diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index ff02c722..379e0e67 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -55,7 +55,7 @@ class AltosTelemetryReader extends AltosFlightReader { device = in_device; serial = new AltosSerial(device); log = new AltosLog(serial); - name = device.getPath(); + name = device.toString(); telem = new LinkedBlockingQueue(); serial.add_monitor(telem); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index c82c8e8a..b573ef7f 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -53,18 +53,18 @@ public class AltosUI extends JFrame { } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, String.format("Cannot open device \"%s\"", - device.getPath()), + device.toString()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(AltosUI.this, String.format("Device \"%s\" already in use", - device.getPath()), + device.toString()), "Device in use", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, - device.getPath(), + device.toString(), "Unkonwn I/O error", JOptionPane.ERROR_MESSAGE); } -- cgit v1.2.3 From 594e80572821f1848db062d0cff18ca8bf0d90ce Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 Nov 2010 22:44:48 -0800 Subject: altosui: switch channel selector to combo box. Shorten displayed device names A combo box displays the current value, which is quite nice to have. Add a 'toShortString' for AltosDevice so that the window frames and error messages don't have extra spaces generated by the altos_device toString method. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosChannelMenu.java | 24 +++++------- ao-tools/altosui/AltosConfig.java | 8 ++-- ao-tools/altosui/AltosDebug.java | 2 +- ao-tools/altosui/AltosDevice.java | 9 +++++ ao-tools/altosui/AltosEepromDownload.java | 10 ++--- ao-tools/altosui/AltosFlashUI.java | 2 +- ao-tools/altosui/AltosFlightUI.java | 62 ++++++++++++++++-------------- ao-tools/altosui/AltosIgniteUI.java | 8 ++-- ao-tools/altosui/AltosSerial.java | 6 +-- ao-tools/altosui/AltosTelemetryReader.java | 2 +- ao-tools/altosui/AltosUI.java | 6 +-- 11 files changed, 74 insertions(+), 65 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosChannelMenu.java b/ao-tools/altosui/AltosChannelMenu.java index 504c13c6..8069c853 100644 --- a/ao-tools/altosui/AltosChannelMenu.java +++ b/ao-tools/altosui/AltosChannelMenu.java @@ -28,8 +28,7 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -public class AltosChannelMenu extends JMenu implements ActionListener { - ButtonGroup group; +public class AltosChannelMenu extends JComboBox implements ActionListener { int channel; LinkedList listeners; @@ -38,33 +37,28 @@ public class AltosChannelMenu extends JMenu implements ActionListener { } public void actionPerformed(ActionEvent e) { - channel = Integer.parseInt(e.getActionCommand()); + channel = getSelectedIndex(); + + ActionEvent newe = new ActionEvent(this, channel, e.getActionCommand()); ListIterator i = listeners.listIterator(); - ActionEvent newe = new ActionEvent(this, channel, e.getActionCommand()); while (i.hasNext()) { ActionListener listener = i.next(); listener.actionPerformed(newe); } + setMaximumSize(getPreferredSize()); } public AltosChannelMenu(int current_channel) { - super("Channel", true); - group = new ButtonGroup(); channel = current_channel; listeners = new LinkedList(); - for (int c = 0; c <= 9; c++) { - JRadioButtonMenuItem radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c, - 434.550 + c * 0.1), - c == channel); - radioitem.setActionCommand(String.format("%d", c)); - radioitem.addActionListener(this); - add(radioitem); - group.add(radioitem); - } + for (int c = 0; c <= 9; c++) + addItem(String.format("Channel %1d (%7.3fMHz)", c, 434.550 + c * 0.1)); + setSelectedIndex(channel); + setMaximumRowCount(10); } } diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 19503dcb..6bda20d8 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -158,7 +158,7 @@ public class AltosConfig implements Runnable, ActionListener { void abort() { JOptionPane.showMessageDialog(owner, String.format("Connection to \"%s\" failed", - device.toString()), + device.toShortString()), "Connection Failed", JOptionPane.ERROR_MESSAGE); serial_line.close(); @@ -266,18 +266,18 @@ public class AltosConfig implements Runnable, ActionListener { } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(owner, String.format("Cannot open device \"%s\"", - device.toString()), + device.toShortString()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(owner, String.format("Device \"%s\" already in use", - device.toString()), + device.toShortString()), "Device in use", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(owner, - device.toString(), + device.toShortString(), ee.getLocalizedMessage(), JOptionPane.ERROR_MESSAGE); } diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index 9aa35d3f..8d435b66 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -261,7 +261,7 @@ public class AltosDebug extends AltosSerial { printf ("R\n"); } - public AltosDebug (altos_device in_device) throws FileNotFoundException, AltosSerialInUseException { + public AltosDebug (AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { super(in_device); } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index f646305b..f0fda57b 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -101,6 +101,15 @@ public class AltosDevice extends altos_device { getName(), getSerial(), getPath()); } + public String toShortString() { + String name = getName(); + if (name == null) + name = "Altus Metrum"; + return String.format("%s %d %s", + name, getSerial(), getPath()); + + } + public boolean isAltusMetrum() { if (getVendor() != vendor_altusmetrum) return false; diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 912ff476..fb5dcfc0 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -232,14 +232,14 @@ public class AltosEepromDownload implements Runnable { CaptureLog(); } catch (IOException ee) { JOptionPane.showMessageDialog(frame, - device.toString(), + device.toShortString(), ee.getLocalizedMessage(), JOptionPane.ERROR_MESSAGE); } catch (InterruptedException ie) { } catch (TimeoutException te) { JOptionPane.showMessageDialog(frame, String.format("Connection to \"%s\" failed", - device.toString()), + device.toShortString()), "Connection Failed", JOptionPane.ERROR_MESSAGE); } @@ -266,18 +266,18 @@ public class AltosEepromDownload implements Runnable { } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, String.format("Cannot open device \"%s\"", - device.toString()), + device.toShortString()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(frame, String.format("Device \"%s\" already in use", - device.toString()), + device.toShortString()), "Device in use", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(frame, - device.toString(), + device.toShortString(), ee.getLocalizedMessage(), JOptionPane.ERROR_MESSAGE); } diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index d3b72c67..f63097ac 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -90,7 +90,7 @@ public class AltosFlashUI } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(frame, String.format("Device \"%s\" already in use", - debug_dongle.toString()), + debug_dongle.toShortString()), "Device in use", JOptionPane.ERROR_MESSAGE); } catch (IOException e) { diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 78b005c0..56ab7ebc 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -36,8 +36,6 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { AltosFlightReader reader; AltosDisplayThread thread; - private Box vbox; - JTabbedPane pane; AltosPad pad; @@ -128,22 +126,47 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { exit_on_close = true; } + Container bag; + public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { AltosPreferences.init(this); voice = in_voice; reader = in_reader; + bag = getContentPane(); + bag.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg"); if (imgURL != null) setIconImage(new ImageIcon(imgURL).getImage()); setTitle(String.format("AltOS %s", reader.name)); - flightStatus = new AltosFlightStatus(); + if (serial >= 0) { + // Channel menu + JComboBox channels = new AltosChannelMenu(AltosPreferences.channel(serial)); + channels.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int channel = Integer.parseInt(e.getActionCommand()); + reader.set_channel(channel); + AltosPreferences.set_channel(serial, channel); + } + }); + c.gridx = 0; + c.gridy = 0; + c.anchor = GridBagConstraints.WEST; + bag.add (channels, c); + } - vbox = new Box (BoxLayout.Y_AXIS); - vbox.add(flightStatus); + flightStatus = new AltosFlightStatus(); + c.gridx = 0; + c.gridy = 1; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + bag.add(flightStatus, c); pane = new JTabbedPane(); @@ -163,29 +186,12 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { flightInfoPane = new JScrollPane(flightInfo.box()); pane.add("Table", flightInfoPane); - vbox.add(pane); - - this.add(vbox); - - if (serial >= 0) { - JMenuBar menubar = new JMenuBar(); - - // Channel menu - { - JMenu menu = new AltosChannelMenu(AltosPreferences.channel(serial)); - menu.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - int channel = Integer.parseInt(e.getActionCommand()); - reader.set_channel(channel); - AltosPreferences.set_channel(serial, channel); - } - }); - menu.setMnemonic(KeyEvent.VK_C); - menubar.add(menu); - } - - this.setJMenuBar(menubar); - } + c.gridx = 0; + c.gridy = 2; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + c.weighty = 1; + bag.add(pane, c); this.setSize(this.getPreferredSize()); this.validate(); diff --git a/ao-tools/altosui/AltosIgniteUI.java b/ao-tools/altosui/AltosIgniteUI.java index caecc3ef..0207e39f 100644 --- a/ao-tools/altosui/AltosIgniteUI.java +++ b/ao-tools/altosui/AltosIgniteUI.java @@ -103,7 +103,7 @@ public class AltosIgniteUI close(); JOptionPane.showMessageDialog(owner, String.format("Connection to \"%s\" failed", - device.toString()), + device.toShortString()), "Connection Failed", JOptionPane.ERROR_MESSAGE); } @@ -194,18 +194,18 @@ public class AltosIgniteUI } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(owner, String.format("Cannot open device \"%s\"", - device.toString()), + device.toShortString()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(owner, String.format("Device \"%s\" already in use", - device.toString()), + device.toShortString()), "Device in use", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(owner, - device.toString(), + device.toShortString(), ee.getLocalizedMessage(), JOptionPane.ERROR_MESSAGE); } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 0d32a5ae..ab74486b 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -38,7 +38,7 @@ public class AltosSerial implements Runnable { static List devices_opened = Collections.synchronizedList(new LinkedList()); - altos_device device; + AltosDevice device; SWIGTYPE_p_altos_file altos; LinkedList> monitors; LinkedBlockingQueue reply_queue; @@ -195,7 +195,7 @@ public class AltosSerial implements Runnable { } altos = libaltos.altos_open(device); if (altos == null) - throw new FileNotFoundException(device.toString()); + throw new FileNotFoundException(device.toShortString()); input_thread = new Thread(this); input_thread.start(); print("~\nE 0\n"); @@ -233,7 +233,7 @@ public class AltosSerial implements Runnable { } } - public AltosSerial(altos_device in_device) throws FileNotFoundException, AltosSerialInUseException { + public AltosSerial(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { device = in_device; line = ""; monitor_mode = false; diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index 379e0e67..de5f50e9 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -55,7 +55,7 @@ class AltosTelemetryReader extends AltosFlightReader { device = in_device; serial = new AltosSerial(device); log = new AltosLog(serial); - name = device.toString(); + name = device.toShortString(); telem = new LinkedBlockingQueue(); serial.add_monitor(telem); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index b573ef7f..6bfde014 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -53,18 +53,18 @@ public class AltosUI extends JFrame { } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, String.format("Cannot open device \"%s\"", - device.toString()), + device.toShortString()), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(AltosUI.this, String.format("Device \"%s\" already in use", - device.toString()), + device.toShortString()), "Device in use", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, - device.toString(), + device.toShortString(), "Unkonwn I/O error", JOptionPane.ERROR_MESSAGE); } -- cgit v1.2.3 From 8c8dc3794c7b5fa5a5b43b1c461d6c8bb3ab425d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 Nov 2010 23:09:15 -0800 Subject: altosui: When switching log files, don't terminate log thread The log thread automatically switches output files when the incoming telemetry changes. Don't use 'close' for that as 'close' terminates the log thread as well as closing the file. Create a new 'close_log_file' function which just closes the file. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosLog.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java index 137147d5..11319768 100644 --- a/ao-tools/altosui/AltosLog.java +++ b/ao-tools/altosui/AltosLog.java @@ -36,15 +36,23 @@ class AltosLog implements Runnable { FileWriter log_file; Thread log_thread; - void close() { + private void close_log_file() { if (log_file != null) { try { log_file.close(); } catch (IOException io) { } + log_file = null; } - if (log_thread != null) + } + + void close() { + close_log_file(); + if (log_thread != null) { + log_thread.interrupt(); + log_thread = null; log_thread.interrupt(); + } } boolean open (AltosTelemetry telem) throws IOException { @@ -74,7 +82,7 @@ class AltosLog implements Runnable { try { AltosTelemetry telem = new AltosTelemetry(line.line); if (telem.serial != serial || telem.flight != flight || log_file == null) { - close(); + close_log_file(); serial = telem.serial; flight = telem.flight; open(telem); -- cgit v1.2.3 From 7920ed5c34b088f45ce4213b061ddd1ffe22cee8 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 Nov 2010 23:18:51 -0800 Subject: altosui: calling thread.interrupt with null thread doesn't work well This was a left-over from debugging the previous patch. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosLog.java | 1 - 1 file changed, 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java index 11319768..dd147d21 100644 --- a/ao-tools/altosui/AltosLog.java +++ b/ao-tools/altosui/AltosLog.java @@ -51,7 +51,6 @@ class AltosLog implements Runnable { if (log_thread != null) { log_thread.interrupt(); log_thread = null; - log_thread.interrupt(); } } -- cgit v1.2.3 From 71c41eadd12c3ece5fffce7669e4991778046d4e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Nov 2010 00:09:03 -0800 Subject: altosui: Initialize display thread state in constructor instead of run Some state will get set before run is called, initializing it there can be too late. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDisplayThread.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDisplayThread.java b/ao-tools/altosui/AltosDisplayThread.java index 375965b9..3e719130 100644 --- a/ao-tools/altosui/AltosDisplayThread.java +++ b/ao-tools/altosui/AltosDisplayThread.java @@ -116,10 +116,6 @@ public class AltosDisplayThread extends Thread { } public void run () { - - reported_landing = 0; - state = null; - report_interval = 10000; try { for (;;) { set_report_time(); @@ -159,6 +155,12 @@ public class AltosDisplayThread extends Thread { } else if (spoken) set_report_time(); } + + public IdleThread() { + state = null; + reported_landing = 0; + report_interval = 10000; + } } boolean tell(AltosState state, AltosState old_state) { -- cgit v1.2.3 From 9a99cabc1c34c657fc95246192ba6d330f5f22d3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Nov 2010 00:13:58 -0800 Subject: altosui: Fix channel changing in flight UI to actually work Replacing the menu with a combo box required reworking the way events are delivered from that widget back to the channel changing function. Just delete the old magic and use the JComboBox action listener directly. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosChannelMenu.java | 20 -------------------- ao-tools/altosui/AltosFlightUI.java | 5 +++-- 2 files changed, 3 insertions(+), 22 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosChannelMenu.java b/ao-tools/altosui/AltosChannelMenu.java index 8069c853..abbb86f4 100644 --- a/ao-tools/altosui/AltosChannelMenu.java +++ b/ao-tools/altosui/AltosChannelMenu.java @@ -30,31 +30,11 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosChannelMenu extends JComboBox implements ActionListener { int channel; - LinkedList listeners; - - public void addActionListener(ActionListener l) { - listeners.add(l); - } - - public void actionPerformed(ActionEvent e) { - channel = getSelectedIndex(); - - ActionEvent newe = new ActionEvent(this, channel, e.getActionCommand()); - - ListIterator i = listeners.listIterator(); - - while (i.hasNext()) { - ActionListener listener = i.next(); - listener.actionPerformed(newe); - } - setMaximumSize(getPreferredSize()); - } public AltosChannelMenu(int current_channel) { channel = current_channel; - listeners = new LinkedList(); for (int c = 0; c <= 9; c++) addItem(String.format("Channel %1d (%7.3fMHz)", c, 434.550 + c * 0.1)); setSelectedIndex(channel); diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 56ab7ebc..ac88aa15 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -127,6 +127,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { } Container bag; + JComboBox channels; public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { AltosPreferences.init(this); @@ -147,10 +148,10 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { if (serial >= 0) { // Channel menu - JComboBox channels = new AltosChannelMenu(AltosPreferences.channel(serial)); + channels = new AltosChannelMenu(AltosPreferences.channel(serial)); channels.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - int channel = Integer.parseInt(e.getActionCommand()); + int channel = channels.getSelectedIndex(); reader.set_channel(channel); AltosPreferences.set_channel(serial, channel); } -- cgit v1.2.3 From 58f8d069ce9488e2987b8e92caa69fe68cda7569 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sat, 20 Nov 2010 21:06:37 +1000 Subject: AltosSiteMap: add autoscroll and grabndrag scroll --- ao-tools/altosui/AltosFlightUI.java | 4 +--- ao-tools/altosui/AltosSiteMap.java | 38 +++++++++++++++++++++++++++++++--- ao-tools/altosui/AltosSiteMapTile.java | 32 +++++++++++++++++++++------- 3 files changed, 61 insertions(+), 13 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 6db6c67b..c85fc977 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -46,7 +46,6 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { private AltosFlightStatus flightStatus; private JScrollPane flightInfoPane; - private JScrollPane sitemapPane; private AltosInfoTable flightInfo; static final int tab_pad = 1; @@ -192,8 +191,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { pane.add("Table", flightInfoPane); sitemap = new AltosSiteMap(); - sitemapPane = new JScrollPane(sitemap); - pane.add("Site Map", sitemapPane); + pane.add("Site Map", sitemap); c.gridx = 0; c.gridy = 2; diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index df1cc246..1db83959 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -21,6 +21,7 @@ import java.awt.*; import java.awt.image.*; import java.awt.event.*; import javax.swing.*; +import javax.swing.event.MouseInputAdapter; import javax.imageio.ImageIO; import javax.swing.table.*; import java.io.*; @@ -31,7 +32,7 @@ import java.lang.Math; import java.awt.geom.Point2D; import java.awt.geom.Line2D; -public class AltosSiteMap extends JComponent implements AltosFlightDisplay { +public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { public void reset() { // nothing } @@ -43,10 +44,40 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { AltosSiteMapTile [] mapTiles = new AltosSiteMapTile[9]; + class GrabNDrag extends MouseInputAdapter { + private JComponent scroll; + private Point startPt = new Point(); + + public GrabNDrag(JComponent parent) { + scroll = parent; + } + + public void mousePressed(MouseEvent e) { + startPt.setLocation(e.getPoint()); + } + public void mouseDragged(MouseEvent e) { + int xd = e.getX() - startPt.x; + int yd = e.getY() - startPt.y; + + Rectangle r = scroll.getVisibleRect(); + r.x -= xd; + r.y -= yd; + scroll.scrollRectToVisible(r); + } + } + public AltosSiteMap() { + JComponent comp = new JComponent() { + GrabNDrag scroller = new GrabNDrag(this); + { + addMouseMotionListener(scroller); + addMouseListener(scroller); + setAutoscrolls(true); + } + }; GridBagLayout layout = new GridBagLayout(); - setLayout(layout); + comp.setLayout(layout); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; @@ -56,8 +87,9 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay { c.gridx = x % 3; c.gridy = x / 3; mapTiles[x] = new AltosSiteMapTile((x%3)-1, (x/3)-1); layout.setConstraints(mapTiles[x], c); - add(mapTiles[x]); + comp.add(mapTiles[x]); } + setViewportView(comp); } } diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index c14fb93f..df57aa7d 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -65,21 +65,19 @@ public class AltosSiteMapTile extends JLabel { Point2D.Double map_latlng; map_latlng = latlng(new Point2D.Double(px_size/2, px_size/2)); - BufferedImage myPicture; File pngfile = new File(AltosPreferences.logdir(), FileCoord(map_latlng, zoom)); try { + BufferedImage myPicture; myPicture = ImageIO.read(pngfile); + setIcon(new ImageIcon( myPicture )); System.out.printf("# Found file %s\n", pngfile); + g2d = myPicture.createGraphics(); } catch (Exception e) { // throw new RuntimeException(e); System.out.printf("# Failed to find file %s\n", pngfile); System.out.printf(" wget -O '%s' 'http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32'\n", pngfile, map_latlng.x, map_latlng.y, zoom, px_size, px_size); - myPicture = new BufferedImage(px_size, px_size, - BufferedImage.TYPE_INT_RGB); } - setIcon(new ImageIcon( myPicture )); - g2d = myPicture.createGraphics(); return true; } @@ -167,8 +165,8 @@ public class AltosSiteMapTile extends JLabel { return; if (!state.gps_ready && state.pad_lat == 0 && state.pad_lon == 0) return; - double plat = (int)(state.pad_lat*200)/200.0; - double plon = (int)(state.pad_lon*200)/200.0; + double plat = state.pad_lat; + double plon = state.pad_lon; if (last_pt == null) { if (!setLocation(plat, plon)) { @@ -185,6 +183,19 @@ public class AltosSiteMapTile extends JLabel { g2d.draw(new Line2D.Double(last_pt, pt)); } + if (0 <= pt.x && pt.x < px_size) { + if (0 <= pt.y && pt.y < px_size) { + int dx = 500, dy = 250; + if (last_pt != null && state.state > 2) { + dx = Math.min(200, 20 + (int) Math.abs(last_pt.x - pt.x)); + dy = Math.min(100, 10 + (int) Math.abs(last_pt.y - pt.y)); + } + Rectangle r = new Rectangle((int)pt.x-dx, (int)pt.y-dy, + dx*2, dy*2); + scrollRectToVisible(r); + } + } + if (state.state == 8 && !drawn_landed_circle) { drawn_landed_circle = true; g2d.setColor(Color.RED); @@ -198,6 +209,13 @@ public class AltosSiteMapTile extends JLabel { } public AltosSiteMapTile(int x_tile_offset, int y_tile_offset) { + BufferedImage myPicture = new BufferedImage(px_size, px_size, + BufferedImage.TYPE_INT_RGB); + setIcon(new ImageIcon( myPicture )); + g2d = myPicture.createGraphics(); + g2d.setColor(Color.GRAY); + g2d.fillRect(0, 0, px_size, px_size); + off_x = x_tile_offset; off_y = y_tile_offset; } -- cgit v1.2.3 From 20f714bbe3137de8fb7491b39985021fd1774930 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sat, 20 Nov 2010 22:49:51 +1000 Subject: AltosSiteMapTile: seperate map and drawing layers --- ao-tools/altosui/AltosSiteMapTile.java | 94 ++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 38 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index df57aa7d..ca68412a 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -31,18 +31,33 @@ import java.lang.Math; import java.awt.geom.Point2D; import java.awt.geom.Line2D; -public class AltosSiteMapTile extends JLabel { +public class AltosSiteMapTile extends JLayeredPane { int zoom; double scale_x, scale_y; Point2D.Double coord_pt; Point2D.Double last_pt; + JLabel mapLabel; + JLabel draw; Graphics2D g2d; int off_x; int off_y; - int px_size = 512; + static final int px_size = 512; + + private void loadMap() { + Point2D.Double map_latlng = latlng(px_size/2, px_size/2); + File pngfile = new File(AltosPreferences.logdir(), + FileCoord(map_latlng, zoom)); + try { + mapLabel.setIcon(new ImageIcon(ImageIO.read(pngfile))); + } catch (Exception e) { + // throw new RuntimeException(e); + System.out.printf("# Failed to find file %s\n", pngfile); + System.out.printf(" wget -O '%s' 'http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32'\n", pngfile, map_latlng.x, map_latlng.y, zoom, px_size, px_size); + } + } private boolean setLocation(double lat, double lng) { Point2D.Double north_step; @@ -62,22 +77,6 @@ public class AltosSiteMapTile extends JLabel { last_pt = null; - Point2D.Double map_latlng; - map_latlng = latlng(new Point2D.Double(px_size/2, px_size/2)); - - File pngfile = new File(AltosPreferences.logdir(), - FileCoord(map_latlng, zoom)); - try { - BufferedImage myPicture; - myPicture = ImageIO.read(pngfile); - setIcon(new ImageIcon( myPicture )); - System.out.printf("# Found file %s\n", pngfile); - g2d = myPicture.createGraphics(); - } catch (Exception e) { - // throw new RuntimeException(e); - System.out.printf("# Failed to find file %s\n", pngfile); - System.out.printf(" wget -O '%s' 'http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32'\n", pngfile, map_latlng.x, map_latlng.y, zoom, px_size, px_size); - } return true; } @@ -132,6 +131,9 @@ public class AltosSiteMapTile extends JLabel { return res; } + private Point2D.Double latlng(double x, double y) { + return latlng(new Point2D.Double(x,y), coord_pt); + } private Point2D.Double latlng(Point2D.Double pt) { return latlng(pt, coord_pt); } @@ -159,24 +161,22 @@ public class AltosSiteMapTile extends JLabel { }; boolean drawn_landed_circle = false; - boolean nomaps = false; public void show(AltosState state, int crc_errors) { - if (nomaps) - return; - if (!state.gps_ready && state.pad_lat == 0 && state.pad_lon == 0) - return; - double plat = state.pad_lat; - double plon = state.pad_lon; + if (!state.gps_ready) { + if (state.pad_lat == 0 && state.pad_lon == 0) + return; + if (state.ngps < 3) + return; + } if (last_pt == null) { - if (!setLocation(plat, plon)) { - nomaps = true; - return; - } + setLocation(state.pad_lat, state.pad_lon); + loadMap(); + last_pt = pt; } Point2D.Double pt = pt(state.gps.lat, state.gps.lon); - if (last_pt != null && pt != last_pt) { + if (pt != last_pt) { if (0 <= state.state && state.state < stateColors.length) { g2d.setColor(stateColors[state.state]); } @@ -186,7 +186,7 @@ public class AltosSiteMapTile extends JLabel { if (0 <= pt.x && pt.x < px_size) { if (0 <= pt.y && pt.y < px_size) { int dx = 500, dy = 250; - if (last_pt != null && state.state > 2) { + if (state.state > 2) { dx = Math.min(200, 20 + (int) Math.abs(last_pt.x - pt.x)); dy = Math.min(100, 10 + (int) Math.abs(last_pt.y - pt.y)); } @@ -207,14 +207,32 @@ public class AltosSiteMapTile extends JLabel { last_pt = pt; repaint(); } - + + public static Graphics2D fillLabel(JLabel l, Color c) { + BufferedImage img = new BufferedImage(px_size, px_size, + BufferedImage.TYPE_INT_ARGB); + Graphics2D g = img.createGraphics(); + g.setColor(c); + g.fillRect(0, 0, px_size, px_size); + l.setIcon(new ImageIcon(img)); + return g; + } + public AltosSiteMapTile(int x_tile_offset, int y_tile_offset) { - BufferedImage myPicture = new BufferedImage(px_size, px_size, - BufferedImage.TYPE_INT_RGB); - setIcon(new ImageIcon( myPicture )); - g2d = myPicture.createGraphics(); - g2d.setColor(Color.GRAY); - g2d.fillRect(0, 0, px_size, px_size); + setPreferredSize(new Dimension(px_size, px_size)); + + mapLabel = new JLabel(); + fillLabel(mapLabel, Color.GRAY); + mapLabel.setOpaque(true); + mapLabel.setBounds(0, 0, px_size, px_size); + add(mapLabel, new Integer(0)); + + draw = new JLabel(); + g2d = fillLabel(draw, new Color(127, 127, 127, 0)); + draw.setBounds(0, 0, px_size, px_size); + draw.setOpaque(false); + + add(draw, new Integer(1)); off_x = x_tile_offset; off_y = y_tile_offset; -- cgit v1.2.3 From 25ffe1cc7823895886b4777f310b4bda1c80133b Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 00:07:16 +1000 Subject: AltosSiteMap: automatic fetching of map data --- ao-tools/altosui/AltosSiteMapLabel.java | 142 ++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosSiteMapTile.java | 32 +------ ao-tools/altosui/Makefile.am | 1 + 3 files changed, 147 insertions(+), 28 deletions(-) create mode 100644 ao-tools/altosui/AltosSiteMapLabel.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMapLabel.java b/ao-tools/altosui/AltosSiteMapLabel.java new file mode 100644 index 00000000..1a371c5b --- /dev/null +++ b/ao-tools/altosui/AltosSiteMapLabel.java @@ -0,0 +1,142 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import javax.swing.*; +import javax.imageio.ImageIO; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.net.URL; +import java.net.URLConnection; + +public class AltosSiteMapLabel extends JLabel { + public static boolean fetchMap(File file, String url) { + URL u; + try { + u = new URL(url); + } catch (java.net.MalformedURLException e) { + return false; + } + + byte[] data; + try { + URLConnection uc = u.openConnection(); + int contentLength = uc.getContentLength(); + InputStream in = new BufferedInputStream(uc.getInputStream()); + int bytesRead = 0; + int offset = 0; + data = new byte[contentLength]; + while (offset < contentLength) { + bytesRead = in.read(data, offset, data.length - offset); + if (bytesRead == -1) + break; + offset += bytesRead; + } + in.close(); + + if (offset != contentLength) { + return false; + } + } catch (IOException e) { + return false; + } + + try { + FileOutputStream out = new FileOutputStream(file); + out.write(data); + out.flush(); + out.close(); + } catch (FileNotFoundException e) { + return false; + } catch (IOException e) { + if (file.exists()) { + file.delete(); + } + return false; + } + return true; + } + + public void fetchAndLoadMap(final File pngfile, final String url) { + System.out.printf("# Trying to fetch %s...\n", pngfile); + + Thread thread = new Thread() { + public void run() { + try { + if (fetchMap(pngfile, url)) { + setIcon(new ImageIcon(ImageIO.read(pngfile))); + } + } catch (Exception e) { + System.out.printf("# Failed to fetch file %s\n", pngfile); + System.out.printf(" wget -O '%s' ''\n", pngfile, url); + } + } + }; + thread.start(); + } + + public void fetchMap(double lat, double lng, int zoom, int px_size) { + File pngfile = MapFile(lat, lng, zoom); + String url = MapURL(lat, lng, zoom, px_size); + + if (!pngfile.exists()) { + fetchMap(pngfile, url); + } + } + + public void loadMap(double lat, double lng, int zoom, int px_size) { + File pngfile = MapFile(lat, lng, zoom); + String url = MapURL(lat, lng, zoom, px_size); + + if (!pngfile.exists()) { + fetchAndLoadMap(pngfile, url); + return; + } + + try { + setIcon(new ImageIcon(ImageIO.read(pngfile))); + return; + } catch (IOException e) { + System.out.printf("# IO error trying to load %s\n", pngfile); + return; + } + } + + private static File MapFile(double lat, double lng, int zoom) { + char chlat = lat < 0 ? 'S' : 'N'; + char chlng = lng < 0 ? 'E' : 'W'; + if (lat < 0) lat = -lat; + if (lng < 0) lng = -lng; + return new File(AltosPreferences.logdir(), + String.format("map-%c%.6f,%c%.6f-%d.png", + chlat, lat, chlng, lng, zoom)); + } + + private static String MapURL(double lat, double lng, + int zoom, int px_size) + { + return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32", lat, lng, zoom, px_size, px_size); + } +} + diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index ca68412a..56bc98af 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -37,7 +37,7 @@ public class AltosSiteMapTile extends JLayeredPane { Point2D.Double coord_pt; Point2D.Double last_pt; - JLabel mapLabel; + AltosSiteMapLabel mapLabel; JLabel draw; Graphics2D g2d; @@ -48,15 +48,7 @@ public class AltosSiteMapTile extends JLayeredPane { private void loadMap() { Point2D.Double map_latlng = latlng(px_size/2, px_size/2); - File pngfile = new File(AltosPreferences.logdir(), - FileCoord(map_latlng, zoom)); - try { - mapLabel.setIcon(new ImageIcon(ImageIO.read(pngfile))); - } catch (Exception e) { - // throw new RuntimeException(e); - System.out.printf("# Failed to find file %s\n", pngfile); - System.out.printf(" wget -O '%s' 'http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32'\n", pngfile, map_latlng.x, map_latlng.y, zoom, px_size, px_size); - } + mapLabel.loadMap(map_latlng.x, map_latlng.y, zoom, px_size); } private boolean setLocation(double lat, double lng) { @@ -88,22 +80,6 @@ public class AltosSiteMapTile extends JLayeredPane { return v; } - private static String FileCoord(Point2D.Double latlng, int zoom) { - double lat, lng; - lat = latlng.x; - lng = latlng.y; - return FileCoord(lat, lng, zoom); - } - private static String FileCoord(double lat, double lng, int zoom) { - char chlat = lat < 0 ? 'S' : 'N'; - char chlng = lng < 0 ? 'E' : 'W'; - if (lat < 0) lat = -lat; - if (lng < 0) lng = -lng; - return String.format("map-%c%.6f,%c%.6f-%d.png", - chlat, lat, chlng, lng, zoom); - } - - // based on google js // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js // search for fromLatLngToPoint and fromPointToLatLng @@ -172,7 +148,7 @@ public class AltosSiteMapTile extends JLayeredPane { if (last_pt == null) { setLocation(state.pad_lat, state.pad_lon); loadMap(); - last_pt = pt; + last_pt = pt(state.pad_lat, state.pad_lon); } Point2D.Double pt = pt(state.gps.lat, state.gps.lon); @@ -221,7 +197,7 @@ public class AltosSiteMapTile extends JLayeredPane { public AltosSiteMapTile(int x_tile_offset, int y_tile_offset) { setPreferredSize(new Dimension(px_size, px_size)); - mapLabel = new JLabel(); + mapLabel = new AltosSiteMapLabel(); fillLabel(mapLabel, Color.GRAY); mapLabel.setOpaque(true); mapLabel.setBounds(0, 0, px_size, px_size); diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 41afdf27..334608f6 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -63,6 +63,7 @@ altosui_JAVA = \ AltosSerialInUseException.java \ AltosSerialMonitor.java \ AltosSiteMap.java \ + AltosSiteMapLabel.java \ AltosSiteMapTile.java \ AltosState.java \ AltosTelemetry.java \ -- cgit v1.2.3 From 51e403145d28ac913e36d205077a613845596be2 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 00:17:51 +1000 Subject: AltosSiteMapTile: draw boost circle as well as landed --- ao-tools/altosui/AltosSiteMapTile.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index 56bc98af..6035a794 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -137,6 +137,7 @@ public class AltosSiteMapTile extends JLayeredPane { }; boolean drawn_landed_circle = false; + boolean drawn_boost_circle = false; public void show(AltosState state, int crc_errors) { if (!state.gps_ready) { if (state.pad_lat == 0 && state.pad_lon == 0) @@ -172,9 +173,16 @@ public class AltosSiteMapTile extends JLayeredPane { } } + if (state.state == 3 && !drawn_boost_circle) { + drawn_boost_circle = true; + g2d.setColor(Color.RED); + g2d.drawOval((int)last_pt.x-5, (int)last_pt.y-5, 10, 10); + g2d.drawOval((int)last_pt.x-20, (int)last_pt.y-20, 40, 40); + g2d.drawOval((int)last_pt.x-35, (int)last_pt.y-35, 70, 70); + } if (state.state == 8 && !drawn_landed_circle) { drawn_landed_circle = true; - g2d.setColor(Color.RED); + g2d.setColor(Color.BLACK); g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); -- cgit v1.2.3 From 89f44c5587ea4f927d5e398b6af919df0d6561c3 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 01:27:01 +1000 Subject: AltosAscent/Descent: tidy up layout --- ao-tools/altosui/AltosAscent.java | 15 +-- ao-tools/altosui/AltosDescent.java | 195 ++++++++++++++++++------------------- 2 files changed, 101 insertions(+), 109 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java index 38ced95e..9bba6633 100644 --- a/ao-tools/altosui/AltosAscent.java +++ b/ao-tools/altosui/AltosAscent.java @@ -69,6 +69,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; + c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -93,7 +94,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { label = new JLabel(text); label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 0; c.gridy = y; + c.gridx = 1; c.gridy = y; c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; @@ -104,7 +105,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { value = new JTextField(30); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 1; c.gridy = y; + c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.gridwidth = 2; @@ -142,7 +143,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { label = new JLabel(text); label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 0; c.gridy = y; + c.gridx = 1; c.gridy = y; c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; @@ -153,7 +154,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { value = new JTextField(15); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 1; c.gridy = y; + c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -163,7 +164,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { max_value = new JTextField(15); max_value.setFont(Altos.value_font); max_value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; + c.gridx = 3; c.gridy = y; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -299,14 +300,14 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { cur = new JLabel("Current"); cur.setFont(Altos.label_font); c = new GridBagConstraints(); - c.gridx = 1; c.gridy = y; + c.gridx = 2; c.gridy = y; c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); layout.setConstraints(cur, c); add(cur); max = new JLabel("Maximum"); max.setFont(Altos.label_font); - c.gridx = 2; c.gridy = y; + c.gridx = 3; c.gridy = y; layout.setConstraints(max, c); add(max); } diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index aacd2998..379946e1 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -31,12 +31,12 @@ import java.util.concurrent.LinkedBlockingQueue; public class AltosDescent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - public class DescentStatus { + public abstract class DescentStatus { JLabel label; JTextField value; AltosLights lights; - void show(AltosState state, int crc_errors) {} + abstract void show(AltosState state, int crc_errors); void reset() { value.setText(""); lights.set(false); @@ -69,6 +69,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; + c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -77,15 +78,17 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { } } - public class DescentValue { + + public abstract class DescentValue { JLabel label; JTextField value; - void show(AltosState state, int crc_errors) {} void reset() { value.setText(""); } + abstract void show(AltosState state, int crc_errors); + void show(String format, double v) { value.setText(String.format(format, v)); } @@ -97,7 +100,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { label = new JLabel(text); label.setFont(Altos.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = x + 0; c.gridy = y; + c.gridx = x + 1; c.gridy = y; c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; @@ -108,7 +111,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value = new JTextField(17); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 1; c.gridy = y; + c.gridx = x + 2; c.gridy = y; + c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -117,12 +121,70 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { } } - class Height extends DescentValue { + public abstract class DescentDualValue { + JLabel label; + JTextField value1; + JTextField value2; + + void reset() { + value1.setText(""); + value2.setText(""); + } + + abstract void show(AltosState state, int crc_errors); + void show(String v1, String v2) { + value1.setText(v1); + value2.setText(v2); + } + void show(String f1, double v1, String f2, double v2) { + value1.setText(String.format(f1, v1)); + value2.setText(String.format(f2, v2)); + } + + public DescentDualValue (GridBagLayout layout, int x, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = x + 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value1 = new JTextField(17); + value1.setFont(Altos.value_font); + value1.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = x + 2; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value1, c); + add(value1); + + value2 = new JTextField(17); + value2.setFont(Altos.value_font); + value2.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = x + 3; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value2, c); + add(value2); + } + } + + class Height extends DescentDualValue { void show (AltosState state, int crc_errors) { - show("%6.0f m", state.height); + show("%6.0f m", state.height, + "%3.0f°", state.elevation); } public Height (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Height"); + super (layout, x, y, "Height/Elevation"); } } @@ -153,33 +215,20 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { return String.format("%s %4d° %9.6f", h, deg, min); } - class Lat extends DescentValue { + class LatLon extends DescentDualValue { void show (AltosState state, int crc_errors) { if (state.gps != null) - value.setText(pos(state.gps.lat,"N", "S")); + show(pos(state.gps.lat,"N", "S"), + pos(state.gps.lon,"W", "E")); else - value.setText("???"); + show("???", "???"); } - public Lat (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Latitude"); + public LatLon (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Lat/Long"); } } - Lat lat; - - class Lon extends DescentValue { - void show (AltosState state, int crc_errors) { - if (state.gps != null) - value.setText(pos(state.gps.lon,"E", "W")); - else - value.setText("???"); - } - public Lon (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Longitude"); - } - } - - Lon lon; + LatLon latlon; class Apogee extends DescentStatus { void show (AltosState state, int crc_errors) { @@ -205,78 +254,23 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { Main main; - class Bearing { - JLabel label; - JTextField value; - JTextField value_deg; - void reset () { - value.setText(""); - value_deg.setText(""); - } + class Bearing extends DescentDualValue { void show (AltosState state, int crc_errors) { if (state.from_pad != null) { - value.setText(state.from_pad.bearing_words( - AltosGreatCircle.BEARING_LONG)); - value_deg.setText(String.format("%3.0f°", state.from_pad.bearing)); + show( state.from_pad.bearing_words( + AltosGreatCircle.BEARING_LONG), + String.format("%3.0f°", state.from_pad.bearing)); } else { - value.setText("???"); - value_deg.setText("???"); + show("???", "???"); } } public Bearing (GridBagLayout layout, int x, int y) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel("Bearing"); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = x + 0; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.weightx = 0; - c.fill = GridBagConstraints.VERTICAL; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(30); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 1; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.weightx = 1; - c.gridwidth = 2; - c.fill = GridBagConstraints.BOTH; - layout.setConstraints(value, c); - add(value); - - value_deg = new JTextField(5); - value_deg.setFont(Altos.value_font); - value_deg.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 3; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.weightx = 1; - c.fill = GridBagConstraints.BOTH; - layout.setConstraints(value_deg, c); - add(value_deg); - } + super (layout, x, y, "Bearing"); + } } Bearing bearing; - class Elevation extends DescentValue { - void show (AltosState state, int crc_errors) { - if (state.from_pad != null) - show("%3.0f°", state.elevation); - else - value.setText("???"); - } - public Elevation (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Elevation"); - } - } - - Elevation elevation; - class Range extends DescentValue { void show (AltosState state, int crc_errors) { show("%6.0f m", state.range); @@ -289,12 +283,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { Range range; public void reset() { - lat.reset(); - lon.reset(); + latlon.reset(); height.reset(); speed.reset(); bearing.reset(); - elevation.reset(); range.reset(); main.reset(); apogee.reset(); @@ -304,10 +296,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { height.show(state, crc_errors); speed.show(state, crc_errors); bearing.show(state, crc_errors); - elevation.show(state, crc_errors); range.show(state, crc_errors); - lat.show(state, crc_errors); - lon.show(state, crc_errors); + latlon.show(state, crc_errors); main.show(state, crc_errors); apogee.show(state, crc_errors); } @@ -318,11 +308,12 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { setLayout(layout); /* Elements in descent display */ - speed = new Speed(layout, 0, 0); height = new Height(layout, 2, 0); - elevation = new Elevation(layout, 0, 1); range = new Range(layout, 2, 1); - bearing = new Bearing(layout, 0, 2); - lat = new Lat(layout, 0, 3); - lon = new Lon(layout, 0, 4); + speed = new Speed(layout, 0, 0); + height = new Height(layout, 0, 1); + range = new Range(layout, 0, 2); + bearing = new Bearing(layout, 0, 3); + latlon = new LatLon(layout, 0, 4); + apogee = new Apogee(layout, 5); main = new Main(layout, 6); } -- cgit v1.2.3 From 6f8bc2ad20b715343e0510563ab0f14787ef3e07 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 01:34:52 +1000 Subject: AltosDescent: switch elev from height to range --- ao-tools/altosui/AltosDescent.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index 379946e1..930b8968 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -178,13 +178,12 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { } } - class Height extends DescentDualValue { + class Height extends DescentValue { void show (AltosState state, int crc_errors) { - show("%6.0f m", state.height, - "%3.0f°", state.elevation); + show("%6.0f m", state.height); } public Height (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Height/Elevation"); + super (layout, x, y, "Height"); } } @@ -224,7 +223,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { show("???", "???"); } public LatLon (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Lat/Long"); + super (layout, x, y, "Latitude, Longitude"); } } @@ -257,9 +256,9 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Bearing extends DescentDualValue { void show (AltosState state, int crc_errors) { if (state.from_pad != null) { - show( state.from_pad.bearing_words( - AltosGreatCircle.BEARING_LONG), - String.format("%3.0f°", state.from_pad.bearing)); + show( String.format("%3.0f°", state.from_pad.bearing), + state.from_pad.bearing_words( + AltosGreatCircle.BEARING_LONG)); } else { show("???", "???"); } @@ -271,12 +270,13 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { Bearing bearing; - class Range extends DescentValue { + class Range extends DescentDualValue { void show (AltosState state, int crc_errors) { - show("%6.0f m", state.range); + show("%6.0f m", state.range, + "%3.0f°", state.elevation); } public Range (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Range"); + super (layout, x, y, "Range, Elevation"); } } -- cgit v1.2.3 From b47517d4c2e49f6f7b9954d2c85f96397fe1103e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Nov 2010 14:06:37 -0800 Subject: altosui: re-indent --- ao-tools/altosui/AltosAscent.java | 2 +- ao-tools/altosui/AltosDescent.java | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java index 9bba6633..b1b812a1 100644 --- a/ao-tools/altosui/AltosAscent.java +++ b/ao-tools/altosui/AltosAscent.java @@ -69,7 +69,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; - c.gridwidth = 2; + c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index 930b8968..d6de8b98 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -69,7 +69,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; - c.gridwidth = 2; + c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -112,7 +112,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = x + 2; c.gridy = y; - c.gridwidth = 2; + c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -133,9 +133,9 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { abstract void show(AltosState state, int crc_errors); void show(String v1, String v2) { - value1.setText(v1); - value2.setText(v2); - } + value1.setText(v1); + value2.setText(v2); + } void show(String f1, double v1, String f2, double v2) { value1.setText(String.format(f1, v1)); value2.setText(String.format(f2, v2)); @@ -217,8 +217,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class LatLon extends DescentDualValue { void show (AltosState state, int crc_errors) { if (state.gps != null) - show(pos(state.gps.lat,"N", "S"), - pos(state.gps.lon,"W", "E")); + show(pos(state.gps.lat,"N", "S"), + pos(state.gps.lon,"W", "E")); else show("???", "???"); } @@ -256,16 +256,16 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Bearing extends DescentDualValue { void show (AltosState state, int crc_errors) { if (state.from_pad != null) { - show( String.format("%3.0f°", state.from_pad.bearing), - state.from_pad.bearing_words( - AltosGreatCircle.BEARING_LONG)); + show( String.format("%3.0f°", state.from_pad.bearing), + state.from_pad.bearing_words( + AltosGreatCircle.BEARING_LONG)); } else { show("???", "???"); } } public Bearing (GridBagLayout layout, int x, int y) { super (layout, x, y, "Bearing"); - } + } } Bearing bearing; @@ -273,7 +273,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Range extends DescentDualValue { void show (AltosState state, int crc_errors) { show("%6.0f m", state.range, - "%3.0f°", state.elevation); + "%3.0f°", state.elevation); } public Range (GridBagLayout layout, int x, int y) { super (layout, x, y, "Range, Elevation"); @@ -308,11 +308,11 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { setLayout(layout); /* Elements in descent display */ - speed = new Speed(layout, 0, 0); - height = new Height(layout, 0, 1); - range = new Range(layout, 0, 2); - bearing = new Bearing(layout, 0, 3); - latlon = new LatLon(layout, 0, 4); + speed = new Speed(layout, 0, 0); + height = new Height(layout, 0, 1); + range = new Range(layout, 0, 2); + bearing = new Bearing(layout, 0, 3); + latlon = new LatLon(layout, 0, 4); apogee = new Apogee(layout, 5); main = new Main(layout, 6); -- cgit v1.2.3 From 72f5e05f9f0055f2cef8b840812f090556c94338 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 08:18:39 +1000 Subject: AltosSiteMap: major refactoring --- ao-tools/altosui/AltosSiteMap.java | 214 ++++++++++++++++++++++++++++---- ao-tools/altosui/AltosSiteMapCache.java | 103 +++++++++++++++ ao-tools/altosui/AltosSiteMapLabel.java | 142 --------------------- ao-tools/altosui/AltosSiteMapTile.java | 117 ++--------------- ao-tools/altosui/AltosUI.java | 6 +- ao-tools/altosui/Makefile.am | 3 +- 6 files changed, 316 insertions(+), 269 deletions(-) create mode 100644 ao-tools/altosui/AltosSiteMapCache.java delete mode 100644 ao-tools/altosui/AltosSiteMapLabel.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 1db83959..a8b66dac 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -33,36 +33,206 @@ import java.awt.geom.Point2D; import java.awt.geom.Line2D; public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { + // max vertical step in a tile in naut. miles + static final double tile_size_nmi = 1.0; + + static final int px_size = 512; + + private static Point2D.Double translatePoint(Point2D.Double p, + Point2D.Double d) + { + return new Point2D.Double(p.x + d.x, p.y + d.y); + } + + static class LatLng { + public double lat, lng; + public LatLng(double lat, double lng) { + this.lat = lat; + this.lng = lng; + } + } + + // based on google js + // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js + // search for fromLatLngToPoint and fromPointToLatLng + private static Point2D.Double pt(LatLng latlng, int zoom) { + double scale_x = 256/360.0 * Math.pow(2, zoom); + double scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + return pt(latlng, scale_x, scale_y); + } + + private static Point2D.Double pt(LatLng latlng, + double scale_x, double scale_y) + { + Point2D.Double res = new Point2D.Double(); + double e; + + res.x = latlng.lng * scale_x; + + e = Math.sin(Math.toRadians(latlng.lat)); + e = Math.max(e,-(1-1.0E-15)); + e = Math.min(e, 1-1.0E-15 ); + + res.y = 0.5*Math.log((1+e)/(1-e))*-scale_y; + return res; + } + + static private LatLng latlng(Point2D.Double pt, + double scale_x, double scale_y) + { + double lat, lng; + double rads; + + lng = pt.x/scale_x; + rads = 2 * Math.atan(Math.exp(-pt.y/scale_y)); + lat = Math.toDegrees(rads - Math.PI/2); + + return new LatLng(lat,lng); + } + + int zoom; + double scale_x, scale_y; + + private Point2D.Double pt(double lat, double lng) { + return pt(new LatLng(lat, lng), scale_x, scale_y); + } + + private LatLng latlng(double x, double y) { + return latlng(new Point2D.Double(x,y), scale_x, scale_y); + } + private LatLng latlng(Point2D.Double pt) { + return latlng(pt, scale_x, scale_y); + } + + AltosSiteMapTile [] mapTiles = new AltosSiteMapTile[9]; + Point2D.Double [] tileOffset = new Point2D.Double[9]; + + private Point2D.Double getBaseLocation(double lat, double lng) { + Point2D.Double locn, north_step; + + zoom = 2; + // stupid loop structure to please Java's control flow analysis + do { + zoom++; + scale_x = 256/360.0 * Math.pow(2, zoom); + scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + locn = pt(lat, lng); + north_step = pt(lat+tile_size_nmi/60.0, lng); + if (locn.y - north_step.y > px_size) + break; + } while (zoom < 22); + locn.x = -px_size * Math.floor(locn.x/px_size); + locn.y = -px_size * Math.floor(locn.y/px_size); + return locn; + } + public void reset() { // nothing } - public void show(AltosState state, int crc_errors) { - for (int x = 0; x < mapTiles.length; x++) { - mapTiles[x].show(state, crc_errors); + + private void bgLoadMap(final int i, + final File pngfile, final String pngurl) + { + Thread thread = new Thread() { + public void run() { + ImageIcon res; + res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl); + if (res != null) { + mapTiles[i].loadMap(res); + } else { + System.out.printf("# Failed to fetch file %s\n", pngfile); + System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); + } + } + }; + thread.start(); + } + + public static void prefetchMaps(double lat, double lng, int w, int h) { + AltosPreferences.init(null); + + AltosSiteMap asm = new AltosSiteMap(true); + Point2D.Double c = asm.getBaseLocation(lat, lng); + Point2D.Double p = new Point2D.Double(); + Point2D.Double p2; + int dx = -w/2, dy = -h/2; + for (int y = dy; y < h+dy; y++) { + for (int x = dx; x < w+dx; x++) { + LatLng map_latlng = asm.latlng( + -c.x + x*px_size + px_size/2, + -c.y + y*px_size + px_size/2); + File pngfile = asm.MapFile(map_latlng.lat, map_latlng.lng); + String pngurl = asm.MapURL(map_latlng.lat, map_latlng.lng); + if (pngfile.exists()) { + System.out.printf("Already have %s\n", pngfile); + } else if (AltosSiteMapCache.fetchMap(pngfile, pngurl)) { + System.out.printf("Fetched map %s\n", pngfile); + } else { + System.out.printf("# Failed to fetch file %s\n", pngfile); + System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); + } + } } } - - AltosSiteMapTile [] mapTiles = new AltosSiteMapTile[9]; - class GrabNDrag extends MouseInputAdapter { - private JComponent scroll; - private Point startPt = new Point(); + private void initMaps(double lat, double lng) { + Point2D.Double c = getBaseLocation(lat, lng); + Point2D.Double p = new Point2D.Double(); + + for (int i = 0; i < 9; i++) { + int x = i%3 - 1, y = i/3 - 1; - public GrabNDrag(JComponent parent) { - scroll = parent; + tileOffset[i] = new Point2D.Double( + c.x - x*px_size, p.y = c.y - y*px_size); + LatLng map_latlng = latlng( + -tileOffset[i].x+px_size/2, + -tileOffset[i].y+px_size/2); + + File pngfile = MapFile(map_latlng.lat, map_latlng.lng); + String pngurl = MapURL(map_latlng.lat, map_latlng.lng); + bgLoadMap(i, pngfile, pngurl); + } + } + + private File MapFile(double lat, double lng) { + char chlat = lat < 0 ? 'S' : 'N'; + char chlng = lng < 0 ? 'E' : 'W'; + if (lat < 0) lat = -lat; + if (lng < 0) lng = -lng; + return new File(AltosPreferences.logdir(), + String.format("map-%c%.6f,%c%.6f-%d.png", + chlat, lat, chlng, lng, zoom)); + } + + private String MapURL(double lat, double lng) { + return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32", lat, lng, zoom, px_size, px_size); + } + + boolean initialised = false; + public void show(AltosState state, int crc_errors) { + // if insufficient gps data, nothing to update + if (!state.gps_ready) { + if (state.pad_lat == 0 && state.pad_lon == 0) + return; + if (state.ngps < 3) + return; + } + + if (!initialised) { + initMaps(state.pad_lat, state.pad_lon); + initialised = true; } - public void mousePressed(MouseEvent e) { - startPt.setLocation(e.getPoint()); + Point2D.Double pt = pt(state.gps.lat, state.gps.lon); + for (int x = 0; x < mapTiles.length; x++) { + mapTiles[x].show(state, crc_errors, + translatePoint(pt, tileOffset[x])); } - public void mouseDragged(MouseEvent e) { - int xd = e.getX() - startPt.x; - int yd = e.getY() - startPt.y; - - Rectangle r = scroll.getVisibleRect(); - r.x -= xd; - r.y -= yd; - scroll.scrollRectToVisible(r); + } + + private AltosSiteMap(boolean knowWhatYouAreDoing) { + if (!knowWhatYouAreDoing) { + throw new RuntimeException("Arggh."); } } @@ -83,9 +253,11 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.BOTH; + // put some space between the map tiles, debugging only + // c.insets = new Insets(5, 5, 5, 5); for (int x = 0; x < 9; x++) { c.gridx = x % 3; c.gridy = x / 3; - mapTiles[x] = new AltosSiteMapTile((x%3)-1, (x/3)-1); + mapTiles[x] = new AltosSiteMapTile(px_size); layout.setConstraints(mapTiles[x], c); comp.add(mapTiles[x]); } diff --git a/ao-tools/altosui/AltosSiteMapCache.java b/ao-tools/altosui/AltosSiteMapCache.java new file mode 100644 index 00000000..dbdcbf65 --- /dev/null +++ b/ao-tools/altosui/AltosSiteMapCache.java @@ -0,0 +1,103 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import javax.swing.*; +import javax.imageio.ImageIO; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.net.URL; +import java.net.URLConnection; + +public class AltosSiteMapCache extends JLabel { + public static boolean fetchMap(File file, String url) { + URL u; + try { + u = new URL(url); + } catch (java.net.MalformedURLException e) { + return false; + } + + byte[] data; + try { + URLConnection uc = u.openConnection(); + int contentLength = uc.getContentLength(); + InputStream in = new BufferedInputStream(uc.getInputStream()); + int bytesRead = 0; + int offset = 0; + data = new byte[contentLength]; + while (offset < contentLength) { + bytesRead = in.read(data, offset, data.length - offset); + if (bytesRead == -1) + break; + offset += bytesRead; + } + in.close(); + + if (offset != contentLength) { + return false; + } + } catch (IOException e) { + return false; + } + + try { + FileOutputStream out = new FileOutputStream(file); + out.write(data); + out.flush(); + out.close(); + } catch (FileNotFoundException e) { + return false; + } catch (IOException e) { + if (file.exists()) { + file.delete(); + } + return false; + } + return true; + } + + public static ImageIcon fetchAndLoadMap(File pngfile, String url) { + if (!pngfile.exists()) { + if (!fetchMap(pngfile, url)) { + return null; + } + } + return loadMap(pngfile, url); + } + + public static ImageIcon loadMap(File pngfile, String url) { + if (!pngfile.exists()) { + return null; + } + + try { + return new ImageIcon(ImageIO.read(pngfile)); + } catch (IOException e) { + System.out.printf("# IO error trying to load %s\n", pngfile); + return null; + } + } +} + diff --git a/ao-tools/altosui/AltosSiteMapLabel.java b/ao-tools/altosui/AltosSiteMapLabel.java deleted file mode 100644 index 1a371c5b..00000000 --- a/ao-tools/altosui/AltosSiteMapLabel.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import java.awt.*; -import java.awt.image.*; -import java.awt.event.*; -import javax.swing.*; -import javax.imageio.ImageIO; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.net.URL; -import java.net.URLConnection; - -public class AltosSiteMapLabel extends JLabel { - public static boolean fetchMap(File file, String url) { - URL u; - try { - u = new URL(url); - } catch (java.net.MalformedURLException e) { - return false; - } - - byte[] data; - try { - URLConnection uc = u.openConnection(); - int contentLength = uc.getContentLength(); - InputStream in = new BufferedInputStream(uc.getInputStream()); - int bytesRead = 0; - int offset = 0; - data = new byte[contentLength]; - while (offset < contentLength) { - bytesRead = in.read(data, offset, data.length - offset); - if (bytesRead == -1) - break; - offset += bytesRead; - } - in.close(); - - if (offset != contentLength) { - return false; - } - } catch (IOException e) { - return false; - } - - try { - FileOutputStream out = new FileOutputStream(file); - out.write(data); - out.flush(); - out.close(); - } catch (FileNotFoundException e) { - return false; - } catch (IOException e) { - if (file.exists()) { - file.delete(); - } - return false; - } - return true; - } - - public void fetchAndLoadMap(final File pngfile, final String url) { - System.out.printf("# Trying to fetch %s...\n", pngfile); - - Thread thread = new Thread() { - public void run() { - try { - if (fetchMap(pngfile, url)) { - setIcon(new ImageIcon(ImageIO.read(pngfile))); - } - } catch (Exception e) { - System.out.printf("# Failed to fetch file %s\n", pngfile); - System.out.printf(" wget -O '%s' ''\n", pngfile, url); - } - } - }; - thread.start(); - } - - public void fetchMap(double lat, double lng, int zoom, int px_size) { - File pngfile = MapFile(lat, lng, zoom); - String url = MapURL(lat, lng, zoom, px_size); - - if (!pngfile.exists()) { - fetchMap(pngfile, url); - } - } - - public void loadMap(double lat, double lng, int zoom, int px_size) { - File pngfile = MapFile(lat, lng, zoom); - String url = MapURL(lat, lng, zoom, px_size); - - if (!pngfile.exists()) { - fetchAndLoadMap(pngfile, url); - return; - } - - try { - setIcon(new ImageIcon(ImageIO.read(pngfile))); - return; - } catch (IOException e) { - System.out.printf("# IO error trying to load %s\n", pngfile); - return; - } - } - - private static File MapFile(double lat, double lng, int zoom) { - char chlat = lat < 0 ? 'S' : 'N'; - char chlng = lng < 0 ? 'E' : 'W'; - if (lat < 0) lat = -lat; - if (lng < 0) lng = -lng; - return new File(AltosPreferences.logdir(), - String.format("map-%c%.6f,%c%.6f-%d.png", - chlat, lat, chlng, lng, zoom)); - } - - private static String MapURL(double lat, double lng, - int zoom, int px_size) - { - return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32", lat, lng, zoom, px_size, px_size); - } -} - diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index 6035a794..de28fc8b 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -32,96 +32,15 @@ import java.awt.geom.Point2D; import java.awt.geom.Line2D; public class AltosSiteMapTile extends JLayeredPane { - int zoom; - double scale_x, scale_y; Point2D.Double coord_pt; Point2D.Double last_pt; - AltosSiteMapLabel mapLabel; + JLabel mapLabel; JLabel draw; Graphics2D g2d; - int off_x; - int off_y; - - static final int px_size = 512; - - private void loadMap() { - Point2D.Double map_latlng = latlng(px_size/2, px_size/2); - mapLabel.loadMap(map_latlng.x, map_latlng.y, zoom, px_size); - } - - private boolean setLocation(double lat, double lng) { - Point2D.Double north_step; - double step_nm = 0.5; - for (zoom = 3; zoom < 22; zoom++) { - coord_pt = pt(lat, lng, new Point2D.Double(0,0), zoom); - north_step = pt(lat+step_nm/60.0, lng, - new Point2D.Double(0,0), zoom); - if (coord_pt.y - north_step.y > px_size/2) - break; - } - coord_pt.x = -px_size * Math.floor(coord_pt.x/px_size + off_x); - coord_pt.y = -px_size * Math.floor(coord_pt.y/px_size + off_y); - - scale_x = 256/360.0 * Math.pow(2, zoom); - scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - - last_pt = null; - - return true; - } - - private static double limit(double v, double lo, double hi) { - if (v < lo) - return lo; - if (hi < v) - return hi; - return v; - } - - // based on google js - // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js - // search for fromLatLngToPoint and fromPointToLatLng - private Point2D.Double pt(double lat, double lng) { - return pt(lat, lng, coord_pt, scale_x, scale_y); - } - - private static Point2D.Double pt(double lat, double lng, - Point2D.Double centre, int zoom) - { - double scale_x = 256/360.0 * Math.pow(2, zoom); - double scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - return pt(lat, lng, centre, scale_x, scale_y); - } - - private static Point2D.Double pt(double lat, double lng, - Point2D.Double centre, double scale_x, double scale_y) - { - Point2D.Double res = new Point2D.Double(); - double e; - - res.x = centre.x + lng*scale_x; - e = limit(Math.sin(Math.toRadians(lat)),-(1-1.0E-15),1-1.0E-15); - res.y = centre.y + 0.5*Math.log((1+e)/(1-e))*-scale_y; - return res; - } - - private Point2D.Double latlng(double x, double y) { - return latlng(new Point2D.Double(x,y), coord_pt); - } - private Point2D.Double latlng(Point2D.Double pt) { - return latlng(pt, coord_pt); - } - private Point2D.Double latlng(Point2D.Double pt, Point2D.Double centre) { - double lat, lng; - double rads; - - lng = (pt.x - centre.x)/scale_x; - rads = 2 * Math.atan(Math.exp((pt.y-centre.y)/-scale_y)); - lat = Math.toDegrees(rads - Math.PI/2); - - return new Point2D.Double(lat,lng); + public void loadMap(ImageIcon icn) { + mapLabel.setIcon(icn); } static Color stateColors[] = { @@ -138,21 +57,13 @@ public class AltosSiteMapTile extends JLayeredPane { boolean drawn_landed_circle = false; boolean drawn_boost_circle = false; - public void show(AltosState state, int crc_errors) { - if (!state.gps_ready) { - if (state.pad_lat == 0 && state.pad_lon == 0) - return; - if (state.ngps < 3) - return; - } - + public void show(AltosState state, int crc_errors, Point2D.Double pt) { if (last_pt == null) { - setLocation(state.pad_lat, state.pad_lon); - loadMap(); - last_pt = pt(state.pad_lat, state.pad_lon); + // setLocation(state.pad_lat, state.pad_lon); + // loadMap(); + last_pt = pt; } - Point2D.Double pt = pt(state.gps.lat, state.gps.lon); if (pt != last_pt) { if (0 <= state.state && state.state < stateColors.length) { g2d.setColor(stateColors[state.state]); @@ -160,6 +71,7 @@ public class AltosSiteMapTile extends JLayeredPane { g2d.draw(new Line2D.Double(last_pt, pt)); } + int px_size = getWidth(); if (0 <= pt.x && pt.x < px_size) { if (0 <= pt.y && pt.y < px_size) { int dx = 500, dy = 250; @@ -192,7 +104,7 @@ public class AltosSiteMapTile extends JLayeredPane { repaint(); } - public static Graphics2D fillLabel(JLabel l, Color c) { + public static Graphics2D fillLabel(JLabel l, Color c, int px_size) { BufferedImage img = new BufferedImage(px_size, px_size, BufferedImage.TYPE_INT_ARGB); Graphics2D g = img.createGraphics(); @@ -202,24 +114,21 @@ public class AltosSiteMapTile extends JLayeredPane { return g; } - public AltosSiteMapTile(int x_tile_offset, int y_tile_offset) { + public AltosSiteMapTile(int px_size) { setPreferredSize(new Dimension(px_size, px_size)); - mapLabel = new AltosSiteMapLabel(); - fillLabel(mapLabel, Color.GRAY); + mapLabel = new JLabel(); + fillLabel(mapLabel, Color.GRAY, px_size); mapLabel.setOpaque(true); mapLabel.setBounds(0, 0, px_size, px_size); add(mapLabel, new Integer(0)); draw = new JLabel(); - g2d = fillLabel(draw, new Color(127, 127, 127, 0)); + g2d = fillLabel(draw, new Color(127, 127, 127, 0), px_size); draw.setBounds(0, 0, px_size, px_size); draw.setOpaque(false); add(draw, new Integer(1)); - - off_x = x_tile_offset; - off_y = y_tile_offset; } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 6bfde014..93a5e0d8 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -353,7 +353,11 @@ public class AltosUI extends JFrame { public static void main(final String[] args) { int process = 0; /* Handle batch-mode */ - if (args.length == 2 && args[0].equals("--replay")) { + if (args.length == 3 && args[0].equals("--fetchmaps")) { + double lat = Double.parseDouble(args[1]); + double lon = Double.parseDouble(args[2]); + AltosSiteMap.prefetchMaps(lat, lon, 5, 5); + } else if (args.length == 2 && args[0].equals("--replay")) { String filename = args[1]; FileInputStream in; try { diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 334608f6..93a43b12 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -10,6 +10,7 @@ CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(FREETTS)/ bin_SCRIPTS=altosui altosui_JAVA = \ + GrabNDrag.java \ AltosAscent.java \ AltosChannelMenu.java \ AltosConfig.java \ @@ -63,7 +64,7 @@ altosui_JAVA = \ AltosSerialInUseException.java \ AltosSerialMonitor.java \ AltosSiteMap.java \ - AltosSiteMapLabel.java \ + AltosSiteMapCache.java \ AltosSiteMapTile.java \ AltosState.java \ AltosTelemetry.java \ -- cgit v1.2.3 From 66ebd954d9c9a44a8db0ee713c682e39306fabd8 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 08:28:24 +1000 Subject: Add GrabNDrag.java --- ao-tools/altosui/GrabNDrag.java | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 ao-tools/altosui/GrabNDrag.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/GrabNDrag.java b/ao-tools/altosui/GrabNDrag.java new file mode 100644 index 00000000..b44f3fe2 --- /dev/null +++ b/ao-tools/altosui/GrabNDrag.java @@ -0,0 +1,51 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.MouseInputAdapter; +import javax.imageio.ImageIO; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; + +class GrabNDrag extends MouseInputAdapter { + private JComponent scroll; + private Point startPt = new Point(); + + public GrabNDrag(JComponent parent) { + scroll = parent; + } + + public void mousePressed(MouseEvent e) { + startPt.setLocation(e.getPoint()); + } + public void mouseDragged(MouseEvent e) { + int xd = e.getX() - startPt.x; + int yd = e.getY() - startPt.y; + + Rectangle r = scroll.getVisibleRect(); + r.x -= xd; + r.y -= yd; + scroll.scrollRectToVisible(r); + } +} -- cgit v1.2.3 From 37f0201d724693528f37ac7d275f68f90cf94da0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Nov 2010 14:31:23 -0800 Subject: altosui: change descent tab formatting to four columns This places labels to the left of each field. For igniter voltages, it uses three columns for the labels. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosAscent.java | 8 ++-- ao-tools/altosui/AltosDescent.java | 93 ++++++++++++++++++++++++++------------ ao-tools/altosui/AltosLanded.java | 2 +- ao-tools/altosui/AltosPad.java | 4 +- 4 files changed, 70 insertions(+), 37 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java index b1b812a1..2ceaa183 100644 --- a/ao-tools/altosui/AltosAscent.java +++ b/ao-tools/altosui/AltosAscent.java @@ -65,7 +65,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(15); + value = new JTextField(17); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -102,7 +102,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(30); + value = new JTextField(17); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -151,7 +151,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(15); + value = new JTextField(17); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -161,7 +161,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(value, c); add(value); - max_value = new JTextField(15); + max_value = new JTextField(17); max_value.setFont(Altos.value_font); max_value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 3; c.gridy = y; diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index d6de8b98..abe64fdc 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -61,15 +61,16 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; + c.gridwidth = 3; c.weightx = 0; layout.setConstraints(label, c); add(label); - value = new JTextField(15); + value = new JTextField(17); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.gridwidth = 2; + c.gridx = 4; c.gridy = y; + c.gridwidth = 1; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -93,6 +94,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value.setText(String.format(format, v)); } + void show(String v) { + value.setText(v); + } + public DescentValue (GridBagLayout layout, int x, int y, String text) { GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -105,19 +110,17 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; c.weightx = 0; - layout.setConstraints(label, c); - add(label); + add(label, c); value = new JTextField(17); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = x + 2; c.gridy = y; - c.gridwidth = 2; + c.gridwidth = 1; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; - layout.setConstraints(value, c); - add(value); + add(value, c); } } @@ -169,10 +172,11 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value2 = new JTextField(17); value2.setFont(Altos.value_font); value2.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 3; c.gridy = y; + c.gridx = x + 4; c.gridy = y; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; + c.gridwidth = 1; layout.setConstraints(value2, c); add(value2); } @@ -211,23 +215,36 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { } int deg = (int) Math.floor(p); double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %4d° %9.6f", h, deg, min); + return String.format("%s %d° %9.6f", h, deg, min); } - class LatLon extends DescentDualValue { + class Lat extends DescentValue { void show (AltosState state, int crc_errors) { if (state.gps != null) - show(pos(state.gps.lat,"N", "S"), - pos(state.gps.lon,"W", "E")); + show(pos(state.gps.lat,"N", "S")); else - show("???", "???"); + show("???"); } - public LatLon (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Latitude, Longitude"); + public Lat (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Latitude"); } } - LatLon latlon; + Lat lat; + + class Lon extends DescentValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + show(pos(state.gps.lon,"W", "E")); + else + show("???"); + } + public Lon (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Longitude"); + } + } + + Lon lon; class Apogee extends DescentStatus { void show (AltosState state, int crc_errors) { @@ -270,24 +287,36 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { Bearing bearing; - class Range extends DescentDualValue { + class Range extends DescentValue { void show (AltosState state, int crc_errors) { - show("%6.0f m", state.range, - "%3.0f°", state.elevation); + show("%6.0f m", state.range); } public Range (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Range, Elevation"); + super (layout, x, y, "Range"); } } Range range; + class Elevation extends DescentValue { + void show (AltosState state, int crc_errors) { + show("%3.0f°", state.elevation); + } + public Elevation (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Elevation"); + } + } + + Elevation elevation; + public void reset() { - latlon.reset(); + lat.reset(); + lon.reset(); height.reset(); speed.reset(); bearing.reset(); range.reset(); + elevation.reset(); main.reset(); apogee.reset(); } @@ -297,7 +326,9 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { speed.show(state, crc_errors); bearing.show(state, crc_errors); range.show(state, crc_errors); - latlon.show(state, crc_errors); + elevation.show(state, crc_errors); + lat.show(state, crc_errors); + lon.show(state, crc_errors); main.show(state, crc_errors); apogee.show(state, crc_errors); } @@ -309,12 +340,14 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { /* Elements in descent display */ speed = new Speed(layout, 0, 0); - height = new Height(layout, 0, 1); - range = new Range(layout, 0, 2); - bearing = new Bearing(layout, 0, 3); - latlon = new LatLon(layout, 0, 4); - - apogee = new Apogee(layout, 5); - main = new Main(layout, 6); + height = new Height(layout, 2, 0); + elevation = new Elevation(layout, 0, 1); + range = new Range(layout, 2, 1); + bearing = new Bearing(layout, 0, 2); + lat = new Lat(layout, 0, 3); + lon = new Lon(layout, 2, 3); + + apogee = new Apogee(layout, 4); + main = new Main(layout, 5); } } diff --git a/ao-tools/altosui/AltosLanded.java b/ao-tools/altosui/AltosLanded.java index 0656ea6c..059dbb6d 100644 --- a/ao-tools/altosui/AltosLanded.java +++ b/ao-tools/altosui/AltosLanded.java @@ -61,7 +61,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(30); + value = new JTextField(17); value.setFont(value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; diff --git a/ao-tools/altosui/AltosPad.java b/ao-tools/altosui/AltosPad.java index 77289f89..480e4d79 100644 --- a/ao-tools/altosui/AltosPad.java +++ b/ao-tools/altosui/AltosPad.java @@ -65,7 +65,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(15); + value = new JTextField(17); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -101,7 +101,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(30); + value = new JTextField(17); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; -- cgit v1.2.3 From 82636305021c41d676f5f0f11378724fe0de0079 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 08:44:13 +1000 Subject: AltosSiteMap: be more polite about preferred size --- ao-tools/altosui/AltosSiteMap.java | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index a8b66dac..a241cbd0 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -262,6 +262,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { comp.add(mapTiles[x]); } setViewportView(comp); + setPreferredSize(new Dimension(500,200)); } } -- cgit v1.2.3 From 1e712647dd6df1e77650db705f3ac32a3c8f6907 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 08:58:44 +1000 Subject: altosui: reindent --- ao-tools/altosui/AltosSiteMap.java | 463 ++++++++++++++++---------------- ao-tools/altosui/AltosSiteMapCache.java | 126 ++++----- ao-tools/altosui/AltosSiteMapTile.java | 196 +++++++------- 3 files changed, 393 insertions(+), 392 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index a241cbd0..5f5e30f0 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -33,236 +33,237 @@ import java.awt.geom.Point2D; import java.awt.geom.Line2D; public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { - // max vertical step in a tile in naut. miles - static final double tile_size_nmi = 1.0; - - static final int px_size = 512; - - private static Point2D.Double translatePoint(Point2D.Double p, - Point2D.Double d) - { - return new Point2D.Double(p.x + d.x, p.y + d.y); - } - - static class LatLng { - public double lat, lng; - public LatLng(double lat, double lng) { - this.lat = lat; - this.lng = lng; - } - } - - // based on google js - // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js - // search for fromLatLngToPoint and fromPointToLatLng - private static Point2D.Double pt(LatLng latlng, int zoom) { - double scale_x = 256/360.0 * Math.pow(2, zoom); - double scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - return pt(latlng, scale_x, scale_y); - } - - private static Point2D.Double pt(LatLng latlng, - double scale_x, double scale_y) - { - Point2D.Double res = new Point2D.Double(); - double e; - - res.x = latlng.lng * scale_x; - - e = Math.sin(Math.toRadians(latlng.lat)); - e = Math.max(e,-(1-1.0E-15)); - e = Math.min(e, 1-1.0E-15 ); - - res.y = 0.5*Math.log((1+e)/(1-e))*-scale_y; - return res; - } - - static private LatLng latlng(Point2D.Double pt, - double scale_x, double scale_y) - { - double lat, lng; - double rads; - - lng = pt.x/scale_x; - rads = 2 * Math.atan(Math.exp(-pt.y/scale_y)); - lat = Math.toDegrees(rads - Math.PI/2); - - return new LatLng(lat,lng); - } - - int zoom; - double scale_x, scale_y; - - private Point2D.Double pt(double lat, double lng) { - return pt(new LatLng(lat, lng), scale_x, scale_y); - } - - private LatLng latlng(double x, double y) { - return latlng(new Point2D.Double(x,y), scale_x, scale_y); - } - private LatLng latlng(Point2D.Double pt) { - return latlng(pt, scale_x, scale_y); - } - - AltosSiteMapTile [] mapTiles = new AltosSiteMapTile[9]; - Point2D.Double [] tileOffset = new Point2D.Double[9]; - - private Point2D.Double getBaseLocation(double lat, double lng) { - Point2D.Double locn, north_step; - - zoom = 2; - // stupid loop structure to please Java's control flow analysis - do { - zoom++; - scale_x = 256/360.0 * Math.pow(2, zoom); - scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - locn = pt(lat, lng); - north_step = pt(lat+tile_size_nmi/60.0, lng); - if (locn.y - north_step.y > px_size) - break; - } while (zoom < 22); - locn.x = -px_size * Math.floor(locn.x/px_size); - locn.y = -px_size * Math.floor(locn.y/px_size); - return locn; - } - - public void reset() { - // nothing - } - - private void bgLoadMap(final int i, - final File pngfile, final String pngurl) - { - Thread thread = new Thread() { - public void run() { - ImageIcon res; - res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl); - if (res != null) { - mapTiles[i].loadMap(res); - } else { - System.out.printf("# Failed to fetch file %s\n", pngfile); - System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); - } - } - }; - thread.start(); - } - - public static void prefetchMaps(double lat, double lng, int w, int h) { - AltosPreferences.init(null); - - AltosSiteMap asm = new AltosSiteMap(true); - Point2D.Double c = asm.getBaseLocation(lat, lng); - Point2D.Double p = new Point2D.Double(); - Point2D.Double p2; - int dx = -w/2, dy = -h/2; - for (int y = dy; y < h+dy; y++) { - for (int x = dx; x < w+dx; x++) { - LatLng map_latlng = asm.latlng( - -c.x + x*px_size + px_size/2, - -c.y + y*px_size + px_size/2); - File pngfile = asm.MapFile(map_latlng.lat, map_latlng.lng); - String pngurl = asm.MapURL(map_latlng.lat, map_latlng.lng); - if (pngfile.exists()) { - System.out.printf("Already have %s\n", pngfile); - } else if (AltosSiteMapCache.fetchMap(pngfile, pngurl)) { - System.out.printf("Fetched map %s\n", pngfile); - } else { - System.out.printf("# Failed to fetch file %s\n", pngfile); - System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); - } - } - } - } - - private void initMaps(double lat, double lng) { - Point2D.Double c = getBaseLocation(lat, lng); - Point2D.Double p = new Point2D.Double(); - - for (int i = 0; i < 9; i++) { - int x = i%3 - 1, y = i/3 - 1; - - tileOffset[i] = new Point2D.Double( - c.x - x*px_size, p.y = c.y - y*px_size); - LatLng map_latlng = latlng( - -tileOffset[i].x+px_size/2, - -tileOffset[i].y+px_size/2); - - File pngfile = MapFile(map_latlng.lat, map_latlng.lng); - String pngurl = MapURL(map_latlng.lat, map_latlng.lng); - bgLoadMap(i, pngfile, pngurl); - } - } - - private File MapFile(double lat, double lng) { - char chlat = lat < 0 ? 'S' : 'N'; - char chlng = lng < 0 ? 'E' : 'W'; - if (lat < 0) lat = -lat; - if (lng < 0) lng = -lng; - return new File(AltosPreferences.logdir(), - String.format("map-%c%.6f,%c%.6f-%d.png", - chlat, lat, chlng, lng, zoom)); - } - - private String MapURL(double lat, double lng) { - return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32", lat, lng, zoom, px_size, px_size); - } - - boolean initialised = false; - public void show(AltosState state, int crc_errors) { - // if insufficient gps data, nothing to update - if (!state.gps_ready) { - if (state.pad_lat == 0 && state.pad_lon == 0) - return; - if (state.ngps < 3) - return; - } - - if (!initialised) { - initMaps(state.pad_lat, state.pad_lon); - initialised = true; - } - - Point2D.Double pt = pt(state.gps.lat, state.gps.lon); - for (int x = 0; x < mapTiles.length; x++) { - mapTiles[x].show(state, crc_errors, - translatePoint(pt, tileOffset[x])); - } - } - - private AltosSiteMap(boolean knowWhatYouAreDoing) { - if (!knowWhatYouAreDoing) { - throw new RuntimeException("Arggh."); - } - } - - public AltosSiteMap() { - JComponent comp = new JComponent() { - GrabNDrag scroller = new GrabNDrag(this); - { - addMouseMotionListener(scroller); - addMouseListener(scroller); - setAutoscrolls(true); - } - }; - - GridBagLayout layout = new GridBagLayout(); - comp.setLayout(layout); - - GridBagConstraints c = new GridBagConstraints(); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.BOTH; - - // put some space between the map tiles, debugging only - // c.insets = new Insets(5, 5, 5, 5); - for (int x = 0; x < 9; x++) { - c.gridx = x % 3; c.gridy = x / 3; - mapTiles[x] = new AltosSiteMapTile(px_size); - layout.setConstraints(mapTiles[x], c); - comp.add(mapTiles[x]); - } - setViewportView(comp); - setPreferredSize(new Dimension(500,200)); - } + // max vertical step in a tile in naut. miles + static final double tile_size_nmi = 1.0; + + static final int px_size = 512; + + private static Point2D.Double translatePoint(Point2D.Double p, + Point2D.Double d) + { + return new Point2D.Double(p.x + d.x, p.y + d.y); + } + + static class LatLng { + public double lat, lng; + public LatLng(double lat, double lng) { + this.lat = lat; + this.lng = lng; + } + } + + // based on google js + // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js + // search for fromLatLngToPoint and fromPointToLatLng + private static Point2D.Double pt(LatLng latlng, int zoom) { + double scale_x = 256/360.0 * Math.pow(2, zoom); + double scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + return pt(latlng, scale_x, scale_y); + } + + private static Point2D.Double pt(LatLng latlng, + double scale_x, double scale_y) + { + Point2D.Double res = new Point2D.Double(); + double e; + + res.x = latlng.lng * scale_x; + + e = Math.sin(Math.toRadians(latlng.lat)); + e = Math.max(e,-(1-1.0E-15)); + e = Math.min(e, 1-1.0E-15 ); + + res.y = 0.5*Math.log((1+e)/(1-e))*-scale_y; + return res; + } + + static private LatLng latlng(Point2D.Double pt, + double scale_x, double scale_y) + { + double lat, lng; + double rads; + + lng = pt.x/scale_x; + rads = 2 * Math.atan(Math.exp(-pt.y/scale_y)); + lat = Math.toDegrees(rads - Math.PI/2); + + return new LatLng(lat,lng); + } + + int zoom; + double scale_x, scale_y; + + private Point2D.Double pt(double lat, double lng) { + return pt(new LatLng(lat, lng), scale_x, scale_y); + } + + private LatLng latlng(double x, double y) { + return latlng(new Point2D.Double(x,y), scale_x, scale_y); + } + private LatLng latlng(Point2D.Double pt) { + return latlng(pt, scale_x, scale_y); + } + + AltosSiteMapTile [] mapTiles = new AltosSiteMapTile[9]; + Point2D.Double [] tileOffset = new Point2D.Double[9]; + + private Point2D.Double getBaseLocation(double lat, double lng) { + Point2D.Double locn, north_step; + + zoom = 2; + // stupid loop structure to please Java's control flow analysis + do { + zoom++; + scale_x = 256/360.0 * Math.pow(2, zoom); + scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + locn = pt(lat, lng); + north_step = pt(lat+tile_size_nmi/60.0, lng); + if (locn.y - north_step.y > px_size) + break; + } while (zoom < 22); + locn.x = -px_size * Math.floor(locn.x/px_size); + locn.y = -px_size * Math.floor(locn.y/px_size); + return locn; + } + + public void reset() { + // nothing + } + + private void bgLoadMap(final int i, + final File pngfile, final String pngurl) + { + Thread thread = new Thread() { + public void run() { + ImageIcon res; + res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl); + if (res != null) { + mapTiles[i].loadMap(res); + } else { + System.out.printf("# Failed to fetch file %s\n", pngfile); + System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); + } + } + }; + thread.start(); + } + + public static void prefetchMaps(double lat, double lng, int w, int h) { + AltosPreferences.init(null); + + AltosSiteMap asm = new AltosSiteMap(true); + Point2D.Double c = asm.getBaseLocation(lat, lng); + Point2D.Double p = new Point2D.Double(); + Point2D.Double p2; + int dx = -w/2, dy = -h/2; + for (int y = dy; y < h+dy; y++) { + for (int x = dx; x < w+dx; x++) { + LatLng map_latlng = asm.latlng( + -c.x + x*px_size + px_size/2, + -c.y + y*px_size + px_size/2); + File pngfile = asm.MapFile(map_latlng.lat, map_latlng.lng); + String pngurl = asm.MapURL(map_latlng.lat, map_latlng.lng); + if (pngfile.exists()) { + System.out.printf("Already have %s\n", pngfile); + } else if (AltosSiteMapCache.fetchMap(pngfile, pngurl)) { + System.out.printf("Fetched map %s\n", pngfile); + } else { + System.out.printf("# Failed to fetch file %s\n", pngfile); + System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); + } + } + } + } + + private void initMaps(double lat, double lng) { + Point2D.Double c = getBaseLocation(lat, lng); + Point2D.Double p = new Point2D.Double(); + + for (int i = 0; i < 9; i++) { + int x = i%3 - 1, y = i/3 - 1; + + tileOffset[i] = new Point2D.Double( + c.x - x*px_size, p.y = c.y - y*px_size); + LatLng map_latlng = latlng( + -tileOffset[i].x+px_size/2, + -tileOffset[i].y+px_size/2); + + File pngfile = MapFile(map_latlng.lat, map_latlng.lng); + String pngurl = MapURL(map_latlng.lat, map_latlng.lng); + bgLoadMap(i, pngfile, pngurl); + } + } + + private File MapFile(double lat, double lng) { + char chlat = lat < 0 ? 'S' : 'N'; + char chlng = lng < 0 ? 'E' : 'W'; + if (lat < 0) lat = -lat; + if (lng < 0) lng = -lng; + return new File(AltosPreferences.logdir(), + String.format("map-%c%.6f,%c%.6f-%d.png", + chlat, lat, chlng, lng, zoom)); + } + + private String MapURL(double lat, double lng) { + return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32", lat, lng, zoom, px_size, px_size); + } + + boolean initialised = false; + public void show(AltosState state, int crc_errors) { + // if insufficient gps data, nothing to update + if (!state.gps_ready) { + if (state.pad_lat == 0 && state.pad_lon == 0) + return; + if (state.ngps < 3) + return; + } + + if (!initialised) { + initMaps(state.pad_lat, state.pad_lon); + initialised = true; + } + + Point2D.Double pt = pt(state.gps.lat, state.gps.lon); + for (int x = 0; x < mapTiles.length; x++) { + mapTiles[x].show(state, crc_errors, + translatePoint(pt, tileOffset[x])); + } + } + + private AltosSiteMap(boolean knowWhatYouAreDoing) { + if (!knowWhatYouAreDoing) { + throw new RuntimeException("Arggh."); + } + } + + public AltosSiteMap() { + JComponent comp = new JComponent() { + GrabNDrag scroller = new GrabNDrag(this); + { + addMouseMotionListener(scroller); + addMouseListener(scroller); + setAutoscrolls(true); + } + }; + + GridBagLayout layout = new GridBagLayout(); + comp.setLayout(layout); + + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.BOTH; + + // put some space between the map tiles, debugging only + // c.insets = new Insets(5, 5, 5, 5); + for (int x = 0; x < 9; x++) { + c.gridx = x % 3; + c.gridy = x / 3; + mapTiles[x] = new AltosSiteMapTile(px_size); + layout.setConstraints(mapTiles[x], c); + comp.add(mapTiles[x]); + } + setViewportView(comp); + setPreferredSize(new Dimension(500,200)); + } } diff --git a/ao-tools/altosui/AltosSiteMapCache.java b/ao-tools/altosui/AltosSiteMapCache.java index dbdcbf65..e9dbf8e6 100644 --- a/ao-tools/altosui/AltosSiteMapCache.java +++ b/ao-tools/altosui/AltosSiteMapCache.java @@ -31,73 +31,73 @@ import java.net.URL; import java.net.URLConnection; public class AltosSiteMapCache extends JLabel { - public static boolean fetchMap(File file, String url) { - URL u; - try { - u = new URL(url); - } catch (java.net.MalformedURLException e) { - return false; - } + public static boolean fetchMap(File file, String url) { + URL u; + try { + u = new URL(url); + } catch (java.net.MalformedURLException e) { + return false; + } - byte[] data; - try { - URLConnection uc = u.openConnection(); - int contentLength = uc.getContentLength(); - InputStream in = new BufferedInputStream(uc.getInputStream()); - int bytesRead = 0; - int offset = 0; - data = new byte[contentLength]; - while (offset < contentLength) { - bytesRead = in.read(data, offset, data.length - offset); - if (bytesRead == -1) - break; - offset += bytesRead; - } - in.close(); + byte[] data; + try { + URLConnection uc = u.openConnection(); + int contentLength = uc.getContentLength(); + InputStream in = new BufferedInputStream(uc.getInputStream()); + int bytesRead = 0; + int offset = 0; + data = new byte[contentLength]; + while (offset < contentLength) { + bytesRead = in.read(data, offset, data.length - offset); + if (bytesRead == -1) + break; + offset += bytesRead; + } + in.close(); - if (offset != contentLength) { - return false; - } - } catch (IOException e) { - return false; - } - - try { - FileOutputStream out = new FileOutputStream(file); - out.write(data); - out.flush(); - out.close(); - } catch (FileNotFoundException e) { - return false; - } catch (IOException e) { - if (file.exists()) { - file.delete(); - } - return false; - } - return true; - } + if (offset != contentLength) { + return false; + } + } catch (IOException e) { + return false; + } - public static ImageIcon fetchAndLoadMap(File pngfile, String url) { - if (!pngfile.exists()) { - if (!fetchMap(pngfile, url)) { - return null; - } - } - return loadMap(pngfile, url); - } + try { + FileOutputStream out = new FileOutputStream(file); + out.write(data); + out.flush(); + out.close(); + } catch (FileNotFoundException e) { + return false; + } catch (IOException e) { + if (file.exists()) { + file.delete(); + } + return false; + } + return true; + } - public static ImageIcon loadMap(File pngfile, String url) { - if (!pngfile.exists()) { - return null; - } + public static ImageIcon fetchAndLoadMap(File pngfile, String url) { + if (!pngfile.exists()) { + if (!fetchMap(pngfile, url)) { + return null; + } + } + return loadMap(pngfile, url); + } - try { - return new ImageIcon(ImageIO.read(pngfile)); - } catch (IOException e) { - System.out.printf("# IO error trying to load %s\n", pngfile); - return null; - } - } + public static ImageIcon loadMap(File pngfile, String url) { + if (!pngfile.exists()) { + return null; + } + + try { + return new ImageIcon(ImageIO.read(pngfile)); + } catch (IOException e) { + System.out.printf("# IO error trying to load %s\n", pngfile); + return null; + } + } } diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index de28fc8b..8aee86c1 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -32,103 +32,103 @@ import java.awt.geom.Point2D; import java.awt.geom.Line2D; public class AltosSiteMapTile extends JLayeredPane { - Point2D.Double coord_pt; - Point2D.Double last_pt; - - JLabel mapLabel; - JLabel draw; - Graphics2D g2d; - - public void loadMap(ImageIcon icn) { - mapLabel.setIcon(icn); - } - - static Color stateColors[] = { - Color.WHITE, // startup - Color.WHITE, // idle - Color.WHITE, // pad - Color.RED, // boost - Color.PINK, // fast - Color.YELLOW, // coast - Color.CYAN, // drogue - Color.BLUE, // main - Color.BLACK // landed - }; - - boolean drawn_landed_circle = false; - boolean drawn_boost_circle = false; - public void show(AltosState state, int crc_errors, Point2D.Double pt) { - if (last_pt == null) { - // setLocation(state.pad_lat, state.pad_lon); - // loadMap(); - last_pt = pt; - } - - if (pt != last_pt) { - if (0 <= state.state && state.state < stateColors.length) { - g2d.setColor(stateColors[state.state]); - } - g2d.draw(new Line2D.Double(last_pt, pt)); - } - - int px_size = getWidth(); - if (0 <= pt.x && pt.x < px_size) { - if (0 <= pt.y && pt.y < px_size) { - int dx = 500, dy = 250; - if (state.state > 2) { - dx = Math.min(200, 20 + (int) Math.abs(last_pt.x - pt.x)); - dy = Math.min(100, 10 + (int) Math.abs(last_pt.y - pt.y)); - } - Rectangle r = new Rectangle((int)pt.x-dx, (int)pt.y-dy, - dx*2, dy*2); - scrollRectToVisible(r); - } - } - - if (state.state == 3 && !drawn_boost_circle) { - drawn_boost_circle = true; - g2d.setColor(Color.RED); - g2d.drawOval((int)last_pt.x-5, (int)last_pt.y-5, 10, 10); - g2d.drawOval((int)last_pt.x-20, (int)last_pt.y-20, 40, 40); - g2d.drawOval((int)last_pt.x-35, (int)last_pt.y-35, 70, 70); - } - if (state.state == 8 && !drawn_landed_circle) { - drawn_landed_circle = true; - g2d.setColor(Color.BLACK); - g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); - g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); - g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); - } - - last_pt = pt; - repaint(); - } - - public static Graphics2D fillLabel(JLabel l, Color c, int px_size) { - BufferedImage img = new BufferedImage(px_size, px_size, - BufferedImage.TYPE_INT_ARGB); - Graphics2D g = img.createGraphics(); - g.setColor(c); - g.fillRect(0, 0, px_size, px_size); - l.setIcon(new ImageIcon(img)); - return g; - } - - public AltosSiteMapTile(int px_size) { - setPreferredSize(new Dimension(px_size, px_size)); - - mapLabel = new JLabel(); - fillLabel(mapLabel, Color.GRAY, px_size); - mapLabel.setOpaque(true); - mapLabel.setBounds(0, 0, px_size, px_size); - add(mapLabel, new Integer(0)); - - draw = new JLabel(); - g2d = fillLabel(draw, new Color(127, 127, 127, 0), px_size); - draw.setBounds(0, 0, px_size, px_size); - draw.setOpaque(false); - - add(draw, new Integer(1)); - } + Point2D.Double coord_pt; + Point2D.Double last_pt; + + JLabel mapLabel; + JLabel draw; + Graphics2D g2d; + + public void loadMap(ImageIcon icn) { + mapLabel.setIcon(icn); + } + + static Color stateColors[] = { + Color.WHITE, // startup + Color.WHITE, // idle + Color.WHITE, // pad + Color.RED, // boost + Color.PINK, // fast + Color.YELLOW, // coast + Color.CYAN, // drogue + Color.BLUE, // main + Color.BLACK // landed + }; + + boolean drawn_landed_circle = false; + boolean drawn_boost_circle = false; + public void show(AltosState state, int crc_errors, Point2D.Double pt) { + if (last_pt == null) { + // setLocation(state.pad_lat, state.pad_lon); + // loadMap(); + last_pt = pt; + } + + if (pt != last_pt) { + if (0 <= state.state && state.state < stateColors.length) { + g2d.setColor(stateColors[state.state]); + } + g2d.draw(new Line2D.Double(last_pt, pt)); + } + + int px_size = getWidth(); + if (0 <= pt.x && pt.x < px_size) { + if (0 <= pt.y && pt.y < px_size) { + int dx = 500, dy = 250; + if (state.state > 2) { + dx = Math.min(200, 20 + (int) Math.abs(last_pt.x - pt.x)); + dy = Math.min(100, 10 + (int) Math.abs(last_pt.y - pt.y)); + } + Rectangle r = new Rectangle((int)pt.x-dx, (int)pt.y-dy, + dx*2, dy*2); + scrollRectToVisible(r); + } + } + + if (state.state == 3 && !drawn_boost_circle) { + drawn_boost_circle = true; + g2d.setColor(Color.RED); + g2d.drawOval((int)last_pt.x-5, (int)last_pt.y-5, 10, 10); + g2d.drawOval((int)last_pt.x-20, (int)last_pt.y-20, 40, 40); + g2d.drawOval((int)last_pt.x-35, (int)last_pt.y-35, 70, 70); + } + if (state.state == 8 && !drawn_landed_circle) { + drawn_landed_circle = true; + g2d.setColor(Color.BLACK); + g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); + g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); + g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); + } + + last_pt = pt; + repaint(); + } + + public static Graphics2D fillLabel(JLabel l, Color c, int px_size) { + BufferedImage img = new BufferedImage(px_size, px_size, + BufferedImage.TYPE_INT_ARGB); + Graphics2D g = img.createGraphics(); + g.setColor(c); + g.fillRect(0, 0, px_size, px_size); + l.setIcon(new ImageIcon(img)); + return g; + } + + public AltosSiteMapTile(int px_size) { + setPreferredSize(new Dimension(px_size, px_size)); + + mapLabel = new JLabel(); + fillLabel(mapLabel, Color.GRAY, px_size); + mapLabel.setOpaque(true); + mapLabel.setBounds(0, 0, px_size, px_size); + add(mapLabel, new Integer(0)); + + draw = new JLabel(); + g2d = fillLabel(draw, new Color(127, 127, 127, 0), px_size); + draw.setBounds(0, 0, px_size, px_size); + draw.setOpaque(false); + + add(draw, new Integer(1)); + } } -- cgit v1.2.3 From ece2c86e2641b2cd613791293526c492b1606aa1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Nov 2010 16:19:42 -0800 Subject: altosui: Rewrite info table to mix with scroll pane well. Fix startup size Using a single table for the info table means that the scroll pane automatically picks up the table headers and shows them above the scrollable view. This patch also fixes the application size at startup so that no scrollbar is required in the info table, and the window is < 800x600. Signed-off-by: Keith Packard --- ao-tools/altosui/Altos.java | 2 + ao-tools/altosui/AltosAscent.java | 8 +-- ao-tools/altosui/AltosDescent.java | 8 +-- ao-tools/altosui/AltosFlightInfoTableModel.java | 77 +++++++++++++------------ ao-tools/altosui/AltosFlightUI.java | 24 +++----- ao-tools/altosui/AltosInfoTable.java | 70 +++++++--------------- ao-tools/altosui/AltosLanded.java | 2 +- ao-tools/altosui/AltosPad.java | 4 +- 8 files changed, 83 insertions(+), 112 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java index 197e98db..8ee94e04 100644 --- a/ao-tools/altosui/Altos.java +++ b/ao-tools/altosui/Altos.java @@ -73,6 +73,8 @@ public class Altos { static final Font value_font = new Font("Monospaced", Font.PLAIN, 22); static final Font status_font = new Font("SansSerif", Font.BOLD, 24); + static final int text_width = 16; + static void initialize_map() { string_to_state.put("startup", ao_flight_startup); diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java index 2ceaa183..64bdcf30 100644 --- a/ao-tools/altosui/AltosAscent.java +++ b/ao-tools/altosui/AltosAscent.java @@ -65,7 +65,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(17); + value = new JTextField(Altos.text_width); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -102,7 +102,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(17); + value = new JTextField(Altos.text_width); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -151,7 +151,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(17); + value = new JTextField(Altos.text_width); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -161,7 +161,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(value, c); add(value); - max_value = new JTextField(17); + max_value = new JTextField(Altos.text_width); max_value.setFont(Altos.value_font); max_value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 3; c.gridy = y; diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java index abe64fdc..16ccd458 100644 --- a/ao-tools/altosui/AltosDescent.java +++ b/ao-tools/altosui/AltosDescent.java @@ -66,7 +66,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(17); + value = new JTextField(Altos.text_width); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 4; c.gridy = y; @@ -112,7 +112,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { c.weightx = 0; add(label, c); - value = new JTextField(17); + value = new JTextField(Altos.text_width); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = x + 2; c.gridy = y; @@ -159,7 +159,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value1 = new JTextField(17); + value1 = new JTextField(Altos.text_width); value1.setFont(Altos.value_font); value1.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = x + 2; c.gridy = y; @@ -169,7 +169,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { layout.setConstraints(value1, c); add(value1); - value2 = new JTextField(17); + value2 = new JTextField(Altos.text_width); value2.setFont(Altos.value_font); value2.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = x + 4; c.gridy = y; diff --git a/ao-tools/altosui/AltosFlightInfoTableModel.java b/ao-tools/altosui/AltosFlightInfoTableModel.java index 3355ff52..e23eff68 100644 --- a/ao-tools/altosui/AltosFlightInfoTableModel.java +++ b/ao-tools/altosui/AltosFlightInfoTableModel.java @@ -29,53 +29,56 @@ import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; public class AltosFlightInfoTableModel extends AbstractTableModel { - private String[] columnNames = {"Field", "Value"}; + final static private String[] columnNames = {"Field", "Value"}; - class InfoLine { - String name; - String value; + int rows; + int cols; + private String[][] data; - public InfoLine(String n, String v) { - name = n; - value = v; - } - } - - private ArrayList rows = new ArrayList(); - - public int getColumnCount() { return columnNames.length; } - public String getColumnName(int col) { return columnNames[col]; } - - public int getRowCount() { return 17; } - - int current_row = 0; - int prev_num_rows = 0; + public int getColumnCount() { return cols; } + public int getRowCount() { return rows; } + public String getColumnName(int col) { return columnNames[col & 1]; } public Object getValueAt(int row, int col) { - if (row >= rows.size()) + if (row >= rows || col >= cols) return ""; - if (col == 0) - return rows.get(row).name; - else - return rows.get(row).value; + return data[row][col]; } - public void resetRow() { - current_row = 0; + int[] current_row; + + public void reset() { + for (int i = 0; i < cols / 2; i++) + current_row[i] = 0; } - public void addRow(String name, String value) { - if (current_row >= rows.size()) - rows.add(current_row, new InfoLine(name, value)); - else - rows.set(current_row, new InfoLine(name, value)); - current_row++; + + public void clear() { + reset(); + for (int c = 0; c < cols; c++) + for (int r = 0; r < rows; r++) + data[r][c] = ""; + fireTableDataChanged(); + } + + public void addRow(int col, String name, String value) { + if (current_row[col] < rows) { + data[current_row[col]][col * 2] = name; + data[current_row[col]][col * 2 + 1] = value; + } + current_row[col]++; } + public void finish() { - if (current_row > prev_num_rows) - fireTableRowsInserted(prev_num_rows, current_row - 1); - while (rows.size() > current_row) - rows.remove(rows.size() - 1); - prev_num_rows = current_row; + for (int c = 0; c < cols / 2; c++) + while (current_row[c] < rows) + addRow(c, "", ""); fireTableDataChanged(); } + + public AltosFlightInfoTableModel (int in_rows, int in_cols) { + rows = in_rows; + cols = in_cols * 2; + data = new String[rows][cols]; + current_row = new int[in_cols]; + } } diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index ac88aa15..d5bcdb10 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -44,7 +44,6 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { AltosLanded landed; private AltosFlightStatus flightStatus; - private JScrollPane flightInfoPane; private AltosInfoTable flightInfo; static final int tab_pad = 1; @@ -66,14 +65,6 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { return tab_landed; } - public int width() { - return flightInfo.width(); - } - - public int height() { - return flightStatus.height() + flightInfo.height(); - } - void stop_display() { if (thread != null && thread.isAlive()) { thread.interrupt(); @@ -146,6 +137,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { setTitle(String.format("AltOS %s", reader.name)); + /* Stick channel selector at top of table for telemetry monitoring */ if (serial >= 0) { // Channel menu channels = new AltosChannelMenu(AltosPreferences.channel(serial)); @@ -162,6 +154,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { bag.add (channels, c); } + /* Flight status is always visible */ flightStatus = new AltosFlightStatus(); c.gridx = 0; c.gridy = 1; @@ -169,6 +162,9 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { c.weightx = 1; bag.add(flightStatus, c); + /* The rest of the window uses a tabbed pane to + * show one of the alternate data views + */ pane = new JTabbedPane(); pad = new AltosPad(); @@ -184,9 +180,9 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { pane.add("Landed", landed); flightInfo = new AltosInfoTable(); - flightInfoPane = new JScrollPane(flightInfo.box()); - pane.add("Table", flightInfoPane); + pane.add("Table", new JScrollPane(flightInfo)); + /* Make the tabbed pane use the rest of the window space */ c.gridx = 0; c.gridy = 2; c.fill = GridBagConstraints.BOTH; @@ -194,9 +190,6 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { c.weighty = 1; bag.add(pane, c); - this.setSize(this.getPreferredSize()); - this.validate(); - setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override @@ -209,7 +202,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { } }); - this.setVisible(true); + pack(); + setVisible(true); thread = new AltosDisplayThread(this, voice, this, reader); diff --git a/ao-tools/altosui/AltosInfoTable.java b/ao-tools/altosui/AltosInfoTable.java index 28924410..c571d5c9 100644 --- a/ao-tools/altosui/AltosInfoTable.java +++ b/ao-tools/altosui/AltosInfoTable.java @@ -28,11 +28,8 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -public class AltosInfoTable { - private Box box; - private JTable table[]; - private AltosFlightInfoTableModel model[]; - private Box ibox[]; +public class AltosInfoTable extends JTable { + private AltosFlightInfoTableModel model; private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 12); private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 12); @@ -40,58 +37,35 @@ public class AltosInfoTable { static final int info_columns = 3; static final int info_rows = 17; - public AltosInfoTable() { - box = Box.createHorizontalBox(); - model = new AltosFlightInfoTableModel[info_columns]; - table = new JTable[info_columns]; - ibox = new Box[info_columns]; - for (int i = 0; i < info_columns; i++) { - model[i] = new AltosFlightInfoTableModel(); - table[i] = new JTable(model[i]); - ibox[i] = box.createVerticalBox(); - - table[i].setFont(infoValueFont); - table[i].setRowHeight(rowHeight()); - table[i].setShowGrid(true); - ibox[i].add(table[i].getTableHeader()); - ibox[i].add(table[i]); - box.add(ibox[i]); - } - } - - public int rowHeight() { - FontMetrics infoValueMetrics = table[0].getFontMetrics(infoValueFont); - return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 20 / 10; - } - - public int columnWidth() { - FontMetrics infoValueMetrics = table[0].getFontMetrics(infoValueFont); - return infoValueMetrics.charWidth('0') * 20 * 2; + int desired_row_height() { + FontMetrics infoValueMetrics = getFontMetrics(infoValueFont); + return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10; } - public int height() { - return rowHeight() * info_rows; - } - - public int width() { - return columnWidth() * info_columns; + public AltosInfoTable() { + super(new AltosFlightInfoTableModel(info_rows, info_columns)); + model = (AltosFlightInfoTableModel) getModel(); + setFont(infoValueFont); + setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); + setShowGrid(true); + setRowHeight(desired_row_height()); + doLayout(); } - public Box box() { - return box; + public Dimension getPreferredScrollableViewportSize() { + return getPreferredSize(); } void info_reset() { - for (int i = 0; i < info_columns; i++) - model[i].resetRow(); + model.reset(); } void info_add_row(int col, String name, String value) { - model[col].addRow(name, value); + model.addRow(col, name, value); } void info_add_row(int col, String name, String format, Object... parameters) { - model[col].addRow(name, String.format(format, parameters)); + info_add_row (col, name, String.format(format, parameters)); } void info_add_deg(int col, String name, double v, int pos, int neg) { @@ -103,17 +77,15 @@ public class AltosInfoTable { double deg = Math.floor(v); double min = (v - deg) * 60; - model[col].addRow(name, String.format("%3.0f°%08.5f'", deg, min)); + info_add_row(col, name, String.format("%3.0f°%08.5f'", deg, min)); } void info_finish() { - for (int i = 0; i < info_columns; i++) - model[i].finish(); + model.finish(); } public void clear() { - info_reset(); - info_finish(); + model.clear(); } public void show(AltosState state, int crc_errors) { diff --git a/ao-tools/altosui/AltosLanded.java b/ao-tools/altosui/AltosLanded.java index 059dbb6d..d34efe6d 100644 --- a/ao-tools/altosui/AltosLanded.java +++ b/ao-tools/altosui/AltosLanded.java @@ -61,7 +61,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(17); + value = new JTextField(Altos.text_width); value.setFont(value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; diff --git a/ao-tools/altosui/AltosPad.java b/ao-tools/altosui/AltosPad.java index 480e4d79..66954347 100644 --- a/ao-tools/altosui/AltosPad.java +++ b/ao-tools/altosui/AltosPad.java @@ -65,7 +65,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(17); + value = new JTextField(Altos.text_width); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -101,7 +101,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { layout.setConstraints(label, c); add(label); - value = new JTextField(17); + value = new JTextField(Altos.text_width); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; -- cgit v1.2.3 From e5b1adae9b23b98a6321986f5cd67c9d3166b87f Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 10:34:39 +1000 Subject: AltosSiteMap: better gps check, lower zoom --- ao-tools/altosui/AltosSiteMap.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 5f5e30f0..72a65b15 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -34,7 +34,7 @@ import java.awt.geom.Line2D; public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { // max vertical step in a tile in naut. miles - static final double tile_size_nmi = 1.0; + static final double tile_size_nmi = 2.0; static final int px_size = 512; @@ -211,10 +211,10 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { boolean initialised = false; public void show(AltosState state, int crc_errors) { // if insufficient gps data, nothing to update - if (!state.gps_ready) { + if (!state.gps.locked) { if (state.pad_lat == 0 && state.pad_lon == 0) return; - if (state.ngps < 3) + if (state.gps.nsat < 4) return; } -- cgit v1.2.3 From 440a0f3f5130eb0c8e614691892be8c94e7fd3c3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Nov 2010 16:55:12 -0800 Subject: altosui: Set site map flight path lines to 6 pixels anti-aliased. Much more visible over the map. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSiteMapTile.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index 9d6f855d..fd4cf0bb 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -125,6 +125,9 @@ public class AltosSiteMapTile extends JLayeredPane { draw = new JLabel(); g2d = fillLabel(draw, new Color(127, 127, 127, 0), px_size); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); draw.setBounds(0, 0, px_size, px_size); draw.setOpaque(false); -- cgit v1.2.3 From 878913551a1e4e3c8f2b39fa4aeb234880735a1c Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 10:55:22 +1000 Subject: AltosSiteMap: explain tile size better --- ao-tools/altosui/AltosSiteMap.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 72a65b15..e222e2c8 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -33,8 +33,10 @@ import java.awt.geom.Point2D; import java.awt.geom.Line2D; public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { - // max vertical step in a tile in naut. miles - static final double tile_size_nmi = 2.0; + // preferred vertical step in a tile in naut. miles + // will actually choose a step size between x and 2x, where this + // is 1.5x + static final double tile_size_nmi = 1.5; static final int px_size = 512; @@ -117,7 +119,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { scale_x = 256/360.0 * Math.pow(2, zoom); scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); locn = pt(lat, lng); - north_step = pt(lat+tile_size_nmi/60.0, lng); + north_step = pt(lat+tile_size_nmi*4/3/60.0, lng); if (locn.y - north_step.y > px_size) break; } while (zoom < 22); -- cgit v1.2.3 From c3994dd82d489289ebc99ff9c5fa88f560c023ac Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 13:07:11 +1000 Subject: AltosSiteMap: extend map if rocket goes far away --- ao-tools/altosui/AltosSiteMap.java | 130 +++++++++++++++++++++++---------- ao-tools/altosui/AltosSiteMapTile.java | 22 ++---- 2 files changed, 98 insertions(+), 54 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 2c542061..25450e7e 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -36,7 +36,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { // preferred vertical step in a tile in naut. miles // will actually choose a step size between x and 2x, where this // is 1.5x - static final double tile_size_nmi = 1.5; + static final double tile_size_nmi = 0.75; static final int px_size = 512; @@ -106,8 +106,23 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { return latlng(pt, scale_x, scale_y); } - AltosSiteMapTile [] mapTiles = new AltosSiteMapTile[9]; - Point2D.Double [] tileOffset = new Point2D.Double[9]; + Vector mapTiles = new Vector(); + Point2D.Double centre; + + private Point tileOffset(AltosSiteMapTile tile) { + GridBagConstraints c = layout.getConstraints(tile); + return new Point(c.gridx - 100, c.gridy - 100); + } + private Point2D.Double tileCoordOffset(AltosSiteMapTile tile) { + Point p = tileOffset(tile); + return new Point2D.Double(centre.x - p.x*px_size, + centre.y - p.y * px_size); + } + + private Point tileOffset(Point2D.Double p) { + return new Point((int)Math.floor((centre.x+p.x)/px_size), + (int)Math.floor((centre.y+p.y)/px_size)); + } private Point2D.Double getBaseLocation(double lat, double lng) { Point2D.Double locn, north_step; @@ -132,15 +147,16 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { // nothing } - private void bgLoadMap(final int i, + private void bgLoadMap(final AltosSiteMapTile tile, final File pngfile, final String pngurl) { + //System.out.printf("Loading/fetching map %s\n", pngfile); Thread thread = new Thread() { public void run() { ImageIcon res; res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl); if (res != null) { - mapTiles[i].loadMap(res); + tile.loadMap(res); } else { System.out.printf("# Failed to fetch file %s\n", pngfile); System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); @@ -154,15 +170,16 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { AltosPreferences.init(null); AltosSiteMap asm = new AltosSiteMap(true); - Point2D.Double c = asm.getBaseLocation(lat, lng); + asm.centre = asm.getBaseLocation(lat, lng); + Point2D.Double p = new Point2D.Double(); Point2D.Double p2; int dx = -w/2, dy = -h/2; for (int y = dy; y < h+dy; y++) { for (int x = dx; x < w+dx; x++) { LatLng map_latlng = asm.latlng( - -c.x + x*px_size + px_size/2, - -c.y + y*px_size + px_size/2); + -asm.centre.x + x*px_size + px_size/2, + -asm.centre.y + y*px_size + px_size/2); File pngfile = asm.MapFile(map_latlng.lat, map_latlng.lng); String pngurl = asm.MapURL(map_latlng.lat, map_latlng.lng); if (pngfile.exists()) { @@ -177,22 +194,21 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } } - private void initMaps(double lat, double lng) { - Point2D.Double c = getBaseLocation(lat, lng); - Point2D.Double p = new Point2D.Double(); + private void initMap(AltosSiteMapTile tile) { + Point2D.Double offset = tileCoordOffset(tile); - for (int i = 0; i < 9; i++) { - int x = i%3 - 1, y = i/3 - 1; + LatLng map_latlng = latlng(px_size/2-offset.x, px_size/2-offset.y); - tileOffset[i] = new Point2D.Double( - c.x - x*px_size, p.y = c.y - y*px_size); - LatLng map_latlng = latlng( - -tileOffset[i].x+px_size/2, - -tileOffset[i].y+px_size/2); + File pngfile = MapFile(map_latlng.lat, map_latlng.lng); + String pngurl = MapURL(map_latlng.lat, map_latlng.lng); + bgLoadMap(tile, pngfile, pngurl); + } + + private void initMaps(double lat, double lng) { + centre = getBaseLocation(lat, lng); - File pngfile = MapFile(map_latlng.lat, map_latlng.lng); - String pngurl = MapURL(map_latlng.lat, map_latlng.lng); - bgLoadMap(i, pngfile, pngurl); + for (AltosSiteMapTile tile : mapTiles) { + initMap(tile); } } @@ -211,6 +227,8 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } boolean initialised = false; + Point2D.Double last_pt = null; + int last_state = -1; public void show(AltosState state, int crc_errors) { // if insufficient gps data, nothing to update if (state.gps == null) @@ -228,10 +246,51 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } Point2D.Double pt = pt(state.gps.lat, state.gps.lon); - for (int x = 0; x < mapTiles.length; x++) { - mapTiles[x].show(state, crc_errors, - translatePoint(pt, tileOffset[x])); + if (last_pt == pt && last_state == state.state) + return; + + if (last_pt == null) { + last_pt = pt; + } + boolean in_any = false; + for (AltosSiteMapTile tile : mapTiles) { + Point2D.Double ref, lref; + ref = translatePoint(pt, tileCoordOffset(tile)); + lref = translatePoint(last_pt, tileCoordOffset(tile)); + tile.show(state, crc_errors, lref, ref); + if (0 <= ref.x && ref.x < px_size) + if (0 <= ref.y && ref.y < px_size) + in_any = true; } + if (!in_any) { + AltosSiteMapTile tile = addTileAt(tileOffset(pt)); + Point2D.Double ref, lref; + ref = translatePoint(pt, tileCoordOffset(tile)); + lref = translatePoint(last_pt, tileCoordOffset(tile)); + initMap(tile); + setViewportView(comp); + tile.show(state, crc_errors, lref, ref); + } + last_pt = pt; + last_state = state.state; + } + + private AltosSiteMapTile addTileAt(Point offset) { + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.BOTH; + + // put some space between the map tiles, debugging only + // c.insets = new Insets(5, 5, 5, 5); + // + AltosSiteMapTile t = new AltosSiteMapTile(px_size); + mapTiles.add(t); + c.gridx = offset.x + 100; + c.gridy = offset.y + 100; + layout.setConstraints(t, c); + comp.add(t); + + return t; } private AltosSiteMap(boolean knowWhatYouAreDoing) { @@ -240,8 +299,11 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } } + JComponent comp; + private GridBagLayout layout; + public AltosSiteMap() { - JComponent comp = new JComponent() { + comp = new JComponent() { GrabNDrag scroller = new GrabNDrag(this); { addMouseMotionListener(scroller); @@ -250,21 +312,13 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } }; - GridBagLayout layout = new GridBagLayout(); + layout = new GridBagLayout(); comp.setLayout(layout); - GridBagConstraints c = new GridBagConstraints(); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.BOTH; - - // put some space between the map tiles, debugging only - // c.insets = new Insets(5, 5, 5, 5); - for (int x = 0; x < 9; x++) { - c.gridx = x % 3; - c.gridy = x / 3; - mapTiles[x] = new AltosSiteMapTile(px_size); - layout.setConstraints(mapTiles[x], c); - comp.add(mapTiles[x]); + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + addTileAt(new Point(x, y)); + } } setViewportView(comp); setPreferredSize(new Dimension(500,200)); diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index fd4cf0bb..ea8c8bd9 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -32,9 +32,6 @@ import java.awt.geom.Point2D; import java.awt.geom.Line2D; public class AltosSiteMapTile extends JLayeredPane { - Point2D.Double coord_pt; - Point2D.Double last_pt; - JLabel mapLabel; JLabel draw; Graphics2D g2d; @@ -57,19 +54,13 @@ public class AltosSiteMapTile extends JLayeredPane { boolean drawn_landed_circle = false; boolean drawn_boost_circle = false; - public void show(AltosState state, int crc_errors, Point2D.Double pt) { - if (last_pt == null) { - // setLocation(state.pad_lat, state.pad_lon); - // loadMap(); - last_pt = pt; - } - - if (pt != last_pt) { - if (0 <= state.state && state.state < stateColors.length) { - g2d.setColor(stateColors[state.state]); - } - g2d.draw(new Line2D.Double(last_pt, pt)); + public void show(AltosState state, int crc_errors, + Point2D.Double last_pt, Point2D.Double pt) + { + if (0 <= state.state && state.state < stateColors.length) { + g2d.setColor(stateColors[state.state]); } + g2d.draw(new Line2D.Double(last_pt, pt)); int px_size = getWidth(); if (0 <= pt.x && pt.x < px_size) { @@ -100,7 +91,6 @@ public class AltosSiteMapTile extends JLayeredPane { g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); } - last_pt = pt; repaint(); } -- cgit v1.2.3 From c040bcd06679484175542208fb564d0271a7fc1b Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 13:19:36 +1000 Subject: AltosSiteMap: try to get new tile construction right --- ao-tools/altosui/AltosSiteMap.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 25450e7e..dd99ad48 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -264,12 +264,14 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } if (!in_any) { AltosSiteMapTile tile = addTileAt(tileOffset(pt)); + setViewportView(comp); + Point2D.Double ref, lref; ref = translatePoint(pt, tileCoordOffset(tile)); lref = translatePoint(last_pt, tileCoordOffset(tile)); - initMap(tile); - setViewportView(comp); tile.show(state, crc_errors, lref, ref); + + initMap(tile); } last_pt = pt; last_state = state.state; -- cgit v1.2.3 From 71e487344395a8efc9cd279aad92f601ff4c6d3d Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 14:05:00 +1000 Subject: AltosSiteMap: thread safe tile addition --- ao-tools/altosui/AltosSiteMap.java | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index dd99ad48..df5207bf 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -229,7 +229,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { boolean initialised = false; Point2D.Double last_pt = null; int last_state = -1; - public void show(AltosState state, int crc_errors) { + public void show(final AltosState state, final int crc_errors) { // if insufficient gps data, nothing to update if (state.gps == null) return; @@ -245,7 +245,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { initialised = true; } - Point2D.Double pt = pt(state.gps.lat, state.gps.lon); + final Point2D.Double pt = pt(state.gps.lat, state.gps.lon); if (last_pt == pt && last_state == state.state) return; @@ -263,15 +263,23 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { in_any = true; } if (!in_any) { - AltosSiteMapTile tile = addTileAt(tileOffset(pt)); - setViewportView(comp); - - Point2D.Double ref, lref; - ref = translatePoint(pt, tileCoordOffset(tile)); - lref = translatePoint(last_pt, tileCoordOffset(tile)); - tile.show(state, crc_errors, lref, ref); - - initMap(tile); + try { + SwingUtilities.invokeAndWait( new Runnable() { + public void run() { + AltosSiteMapTile tile = addTileAt(tileOffset(pt)); + setViewportView(comp); + + Point2D.Double ref, lref; + ref = translatePoint(pt, tileCoordOffset(tile)); + lref = translatePoint(last_pt, tileCoordOffset(tile)); + tile.show(state, crc_errors, lref, ref); + + initMap(tile); + } + } ); + } catch (Exception e) { + // pray + } } last_pt = pt; last_state = state.state; -- cgit v1.2.3 From 84e570d8a8a52e0d358582135ec1b3a12be94c26 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 14:45:10 +1000 Subject: AltosSiteMap: refactor tile collection --- ao-tools/altosui/AltosSiteMap.java | 75 ++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 40 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index df5207bf..5e34dd49 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -106,15 +106,10 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { return latlng(pt, scale_x, scale_y); } - Vector mapTiles = new Vector(); + HashMap mapTiles = new HashMap(); Point2D.Double centre; - private Point tileOffset(AltosSiteMapTile tile) { - GridBagConstraints c = layout.getConstraints(tile); - return new Point(c.gridx - 100, c.gridy - 100); - } - private Point2D.Double tileCoordOffset(AltosSiteMapTile tile) { - Point p = tileOffset(tile); + private Point2D.Double tileCoordOffset(Point p) { return new Point2D.Double(centre.x - p.x*px_size, centre.y - p.y * px_size); } @@ -194,10 +189,10 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } } - private void initMap(AltosSiteMapTile tile) { - Point2D.Double offset = tileCoordOffset(tile); + private void initMap(AltosSiteMapTile tile, Point offset) { + Point2D.Double coord = tileCoordOffset(offset); - LatLng map_latlng = latlng(px_size/2-offset.x, px_size/2-offset.y); + LatLng map_latlng = latlng(px_size/2-coord.x, px_size/2-coord.y); File pngfile = MapFile(map_latlng.lat, map_latlng.lng); String pngurl = MapURL(map_latlng.lat, map_latlng.lng); @@ -207,8 +202,8 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { private void initMaps(double lat, double lng) { centre = getBaseLocation(lat, lng); - for (AltosSiteMapTile tile : mapTiles) { - initMap(tile); + for (Point k : mapTiles.keySet()) { + initMap(mapTiles.get(k), k); } } @@ -253,39 +248,40 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { last_pt = pt; } boolean in_any = false; - for (AltosSiteMapTile tile : mapTiles) { + for (Point offset : mapTiles.keySet()) { + AltosSiteMapTile tile = mapTiles.get(offset); Point2D.Double ref, lref; - ref = translatePoint(pt, tileCoordOffset(tile)); - lref = translatePoint(last_pt, tileCoordOffset(tile)); + ref = translatePoint(pt, tileCoordOffset(offset)); + lref = translatePoint(last_pt, tileCoordOffset(offset)); tile.show(state, crc_errors, lref, ref); if (0 <= ref.x && ref.x < px_size) if (0 <= ref.y && ref.y < px_size) in_any = true; } if (!in_any) { - try { - SwingUtilities.invokeAndWait( new Runnable() { - public void run() { - AltosSiteMapTile tile = addTileAt(tileOffset(pt)); - setViewportView(comp); - - Point2D.Double ref, lref; - ref = translatePoint(pt, tileCoordOffset(tile)); - lref = translatePoint(last_pt, tileCoordOffset(tile)); - tile.show(state, crc_errors, lref, ref); - - initMap(tile); - } - } ); - } catch (Exception e) { - // pray - } + final AltosSiteMapTile tile = new AltosSiteMapTile(px_size); + final Point offset = tileOffset(pt); + mapTiles.put(offset, tile); + + Point2D.Double ref, lref; + ref = translatePoint(pt, tileCoordOffset(offset)); + lref = translatePoint(last_pt, tileCoordOffset(offset)); + tile.show(state, crc_errors, lref, ref); + + initMap(tile, offset); + + SwingUtilities.invokeLater( new Runnable() { + public void run() { + addTileAt(tile, offset); + setViewportView(comp); + } + } ); } last_pt = pt; last_state = state.state; } - private AltosSiteMapTile addTileAt(Point offset) { + private void addTileAt(AltosSiteMapTile tile, Point offset) { GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.BOTH; @@ -293,14 +289,10 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { // put some space between the map tiles, debugging only // c.insets = new Insets(5, 5, 5, 5); // - AltosSiteMapTile t = new AltosSiteMapTile(px_size); - mapTiles.add(t); c.gridx = offset.x + 100; c.gridy = offset.y + 100; - layout.setConstraints(t, c); - comp.add(t); - - return t; + layout.setConstraints(tile, c); + comp.add(tile); } private AltosSiteMap(boolean knowWhatYouAreDoing) { @@ -327,7 +319,10 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { - addTileAt(new Point(x, y)); + AltosSiteMapTile t = new AltosSiteMapTile(px_size); + Point offset = new Point(x, y); + mapTiles.put(offset, t); + addTileAt(t, offset); } } setViewportView(comp); -- cgit v1.2.3 From a08b2a6363c194195db92029743f6612676373ce Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 15:03:21 +1000 Subject: AltosSiteMap: never accept 0,0 as lat/long --- ao-tools/altosui/AltosSiteMap.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 5e34dd49..0375128e 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -228,9 +228,9 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { // if insufficient gps data, nothing to update if (state.gps == null) return; + if (state.pad_lat == 0 && state.pad_lon == 0) + return; if (!state.gps.locked) { - if (state.pad_lat == 0 && state.pad_lon == 0) - return; if (state.gps.nsat < 4) return; } -- cgit v1.2.3 From 0393830f85da5efc96bbdf0d9769b66019c34b33 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 15:13:35 +1000 Subject: AltosSiteMap: limit nr of tiles to 200x200 --- ao-tools/altosui/AltosSiteMap.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 0375128e..b2d79043 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -40,6 +40,8 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { static final int px_size = 512; + static final int MAX_TILE_DELTA = 100; + private static Point2D.Double translatePoint(Point2D.Double p, Point2D.Double d) { @@ -282,15 +284,22 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } private void addTileAt(AltosSiteMapTile tile, Point offset) { + if (Math.abs(offset.x) >= MAX_TILE_DELTA || + Math.abs(offset.y) >= MAX_TILE_DELTA) + { + System.out.printf("Rocket too far away from pad (tile %d,%d)\n", + offset.x, offset.y); + return; + } + GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.BOTH; - // put some space between the map tiles, debugging only // c.insets = new Insets(5, 5, 5, 5); - // - c.gridx = offset.x + 100; - c.gridy = offset.y + 100; + + c.gridx = offset.x + MAX_TILE_DELTA; + c.gridy = offset.y + MAX_TILE_DELTA; layout.setConstraints(tile, c); comp.add(tile); } -- cgit v1.2.3 From e7954c820763f80e993f9f822e837725cf36af84 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Nov 2010 22:03:26 -0800 Subject: altosui: When fixing eeprom gps time information, make GPS data valid Eeprom files may be missing the GPS time (due to a firmware bug). Working around this involves finding the next valid GPS time and using that to create a fake GPS time entry. However, that next GPS time may not be locked or may have few sats as it is from the boost stage of the flight. Fix this by simply forcing the fake time packet to have 4 sats and be locked. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromIterable.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromIterable.java b/ao-tools/altosui/AltosEepromIterable.java index fc683321..f8e6d7e5 100644 --- a/ao-tools/altosui/AltosEepromIterable.java +++ b/ao-tools/altosui/AltosEepromIterable.java @@ -309,6 +309,12 @@ public class AltosEepromIterable extends AltosRecordIterable { int flags = (good.b >> 8); int seconds = hour * 3600 + minute * 60 + second; + /* Make sure this looks like a good GPS value */ + if ((flags & Altos.AO_GPS_NUM_SAT_MASK) >> Altos.AO_GPS_NUM_SAT_SHIFT < 4) + flags = (flags & ~Altos.AO_GPS_NUM_SAT_MASK) | (4 << Altos.AO_GPS_NUM_SAT_SHIFT); + flags |= Altos.AO_GPS_RUNNING; + flags |= Altos.AO_GPS_VALID; + int new_seconds = seconds + diff; if (new_seconds < 0) new_seconds += 24 * 3600; -- cgit v1.2.3 From 4a9ded5b39ed08e13abc2cddba8b712f62b983f2 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 17:39:50 +1000 Subject: AltosSiteMap: ensure buffer around active tile --- ao-tools/altosui/AltosSiteMap.java | 53 ++++++++++++++++++++++++++-------- ao-tools/altosui/AltosSiteMapTile.java | 17 +++++++---- 2 files changed, 53 insertions(+), 17 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index b2d79043..802eb68c 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -260,29 +260,57 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { if (0 <= ref.y && ref.y < px_size) in_any = true; } - if (!in_any) { - final AltosSiteMapTile tile = new AltosSiteMapTile(px_size); - final Point offset = tileOffset(pt); - mapTiles.put(offset, tile); + Point offset = tileOffset(pt); + if (!in_any) { Point2D.Double ref, lref; ref = translatePoint(pt, tileCoordOffset(offset)); lref = translatePoint(last_pt, tileCoordOffset(offset)); - tile.show(state, crc_errors, lref, ref); + AltosSiteMapTile tile = createTile(offset); + tile.show(state, crc_errors, lref, ref); initMap(tile, offset); + finishTileLater(tile, offset); + } - SwingUtilities.invokeLater( new Runnable() { - public void run() { - addTileAt(tile, offset); - setViewportView(comp); - } - } ); + if (offset != tileOffset(last_pt)) { + ensureTilesAround(offset); } + last_pt = pt; last_state = state.state; } + private AltosSiteMapTile createTile(final Point offset) { + final AltosSiteMapTile tile = new AltosSiteMapTile(px_size); + mapTiles.put(offset, tile); + return tile; + } + private void finishTileLater(final AltosSiteMapTile tile, + final Point offset) + { + SwingUtilities.invokeLater( new Runnable() { + public void run() { + addTileAt(tile, offset); + tile.setScrollable(); + } + } ); + } + + private void ensureTilesAround(Point base_offset) { + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + Point offset = new Point(base_offset.x + x, base_offset.y + y); + if (mapTiles.containsKey(offset)) + continue; + AltosSiteMapTile tile = createTile(offset); + initMap(tile, offset); + finishTileLater(tile, offset); + } + } + } + + private void addTileAt(AltosSiteMapTile tile, Point offset) { if (Math.abs(offset.x) >= MAX_TILE_DELTA || Math.abs(offset.y) >= MAX_TILE_DELTA) @@ -328,10 +356,11 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { - AltosSiteMapTile t = new AltosSiteMapTile(px_size); Point offset = new Point(x, y); + AltosSiteMapTile t = new AltosSiteMapTile(px_size); mapTiles.put(offset, t); addTileAt(t, offset); + t.setScrollable(); } } setViewportView(comp); diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index ea8c8bd9..e0942986 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -52,10 +52,17 @@ public class AltosSiteMapTile extends JLayeredPane { Color.BLACK // landed }; - boolean drawn_landed_circle = false; - boolean drawn_boost_circle = false; - public void show(AltosState state, int crc_errors, - Point2D.Double last_pt, Point2D.Double pt) + private boolean drawn_landed_circle = false; + private boolean drawn_boost_circle = false; + private boolean scrollable = false; + public synchronized void setScrollable() { + scrollable = true; + } + public synchronized boolean isScrollable() { + return scrollable; + } + public synchronized void show(AltosState state, int crc_errors, + Point2D.Double last_pt, Point2D.Double pt) { if (0 <= state.state && state.state < stateColors.length) { g2d.setColor(stateColors[state.state]); @@ -63,7 +70,7 @@ public class AltosSiteMapTile extends JLayeredPane { g2d.draw(new Line2D.Double(last_pt, pt)); int px_size = getWidth(); - if (0 <= pt.x && pt.x < px_size) { + if (isScrollable() && 0 <= pt.x && pt.x < px_size) { if (0 <= pt.y && pt.y < px_size) { int dx = 500, dy = 250; if (state.state > 2) { -- cgit v1.2.3 From b85df38b5611e45cb9296df07b720badf74ac26e Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Mon, 22 Nov 2010 05:22:17 +1000 Subject: altosui: improve sitemap scrolling behaviour --- ao-tools/altosui/AltosSiteMap.java | 53 +++++++++++++++++++++++----------- ao-tools/altosui/AltosSiteMapTile.java | 21 -------------- ao-tools/altosui/GrabNDrag.java | 35 ++++++++++++---------- 3 files changed, 55 insertions(+), 54 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 802eb68c..2477e4f8 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -273,6 +273,8 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { finishTileLater(tile, offset); } + scrollRocketToVisible(pt); + if (offset != tileOffset(last_pt)) { ensureTilesAround(offset); } @@ -281,8 +283,8 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { last_state = state.state; } - private AltosSiteMapTile createTile(final Point offset) { - final AltosSiteMapTile tile = new AltosSiteMapTile(px_size); + private AltosSiteMapTile createTile(Point offset) { + AltosSiteMapTile tile = new AltosSiteMapTile(px_size); mapTiles.put(offset, tile); return tile; } @@ -292,7 +294,6 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { SwingUtilities.invokeLater( new Runnable() { public void run() { addTileAt(tile, offset); - tile.setScrollable(); } } ); } @@ -310,6 +311,18 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } } + private Point topleft = new Point(0,0); + private void scrollRocketToVisible(Point2D.Double pt) { + Rectangle r = comp.getVisibleRect(); + Point2D.Double copt = translatePoint(pt, tileCoordOffset(topleft)); + int dx = (int)copt.x - r.width/2 - r.x; + int dy = (int)copt.y - r.height/2 - r.y; + if (Math.abs(dx) > r.width/3 || Math.abs(dy) > r.height/3) { + r.x += dx; + r.y += dy; + comp.scrollRectToVisible(r); + } + } private void addTileAt(AltosSiteMapTile tile, Point offset) { if (Math.abs(offset.x) >= MAX_TILE_DELTA || @@ -320,6 +333,18 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { return; } + boolean review = false; + Rectangle r = comp.getVisibleRect(); + if (offset.x < topleft.x) { + r.x += (topleft.x - offset.x) * px_size; + topleft.x = offset.x; + review = true; + } + if (offset.y < topleft.y) { + r.y += (topleft.y - offset.y) * px_size; + topleft.y = offset.y; + review = true; + } GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.BOTH; @@ -329,7 +354,11 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { c.gridx = offset.x + MAX_TILE_DELTA; c.gridy = offset.y + MAX_TILE_DELTA; layout.setConstraints(tile, c); + comp.add(tile); + if (review) { + comp.scrollRectToVisible(r); + } } private AltosSiteMap(boolean knowWhatYouAreDoing) { @@ -338,29 +367,19 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { } } - JComponent comp; - private GridBagLayout layout; + JComponent comp = new JComponent() { }; + private GridBagLayout layout = new GridBagLayout(); public AltosSiteMap() { - comp = new JComponent() { - GrabNDrag scroller = new GrabNDrag(this); - { - addMouseMotionListener(scroller); - addMouseListener(scroller); - setAutoscrolls(true); - } - }; + GrabNDrag scroller = new GrabNDrag(comp); - layout = new GridBagLayout(); comp.setLayout(layout); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { Point offset = new Point(x, y); - AltosSiteMapTile t = new AltosSiteMapTile(px_size); - mapTiles.put(offset, t); + AltosSiteMapTile t = createTile(offset); addTileAt(t, offset); - t.setScrollable(); } } setViewportView(comp); diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index e0942986..8301f42b 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -54,13 +54,6 @@ public class AltosSiteMapTile extends JLayeredPane { private boolean drawn_landed_circle = false; private boolean drawn_boost_circle = false; - private boolean scrollable = false; - public synchronized void setScrollable() { - scrollable = true; - } - public synchronized boolean isScrollable() { - return scrollable; - } public synchronized void show(AltosState state, int crc_errors, Point2D.Double last_pt, Point2D.Double pt) { @@ -69,20 +62,6 @@ public class AltosSiteMapTile extends JLayeredPane { } g2d.draw(new Line2D.Double(last_pt, pt)); - int px_size = getWidth(); - if (isScrollable() && 0 <= pt.x && pt.x < px_size) { - if (0 <= pt.y && pt.y < px_size) { - int dx = 500, dy = 250; - if (state.state > 2) { - dx = Math.min(200, 20 + (int) Math.abs(last_pt.x - pt.x)); - dy = Math.min(100, 10 + (int) Math.abs(last_pt.y - pt.y)); - } - Rectangle r = new Rectangle((int)pt.x-dx, (int)pt.y-dy, - dx*2, dy*2); - scrollRectToVisible(r); - } - } - if (state.state == 3 && !drawn_boost_circle) { drawn_boost_circle = true; g2d.setColor(Color.RED); diff --git a/ao-tools/altosui/GrabNDrag.java b/ao-tools/altosui/GrabNDrag.java index b44f3fe2..e6b87b58 100644 --- a/ao-tools/altosui/GrabNDrag.java +++ b/ao-tools/altosui/GrabNDrag.java @@ -29,23 +29,26 @@ import java.util.*; import java.text.*; class GrabNDrag extends MouseInputAdapter { - private JComponent scroll; - private Point startPt = new Point(); + private JComponent scroll; + private Point startPt = new Point(); - public GrabNDrag(JComponent parent) { - scroll = parent; - } + public GrabNDrag(JComponent scroll) { + this.scroll = scroll; + scroll.addMouseMotionListener(this); + scroll.addMouseListener(this); + scroll.setAutoscrolls(true); + } - public void mousePressed(MouseEvent e) { - startPt.setLocation(e.getPoint()); - } - public void mouseDragged(MouseEvent e) { - int xd = e.getX() - startPt.x; - int yd = e.getY() - startPt.y; + public void mousePressed(MouseEvent e) { + startPt.setLocation(e.getPoint()); + } + public void mouseDragged(MouseEvent e) { + int xd = e.getX() - startPt.x; + int yd = e.getY() - startPt.y; - Rectangle r = scroll.getVisibleRect(); - r.x -= xd; - r.y -= yd; - scroll.scrollRectToVisible(r); - } + Rectangle r = scroll.getVisibleRect(); + r.x -= xd; + r.y -= yd; + scroll.scrollRectToVisible(r); + } } -- cgit v1.2.3 From 902735ffbfdd97672d52b09f17cdcd619193fd05 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Mon, 22 Nov 2010 05:29:26 +1000 Subject: altosui: keep sitemap more centred on rocket --- ao-tools/altosui/AltosSiteMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index 2477e4f8..80970605 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -317,7 +317,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { Point2D.Double copt = translatePoint(pt, tileCoordOffset(topleft)); int dx = (int)copt.x - r.width/2 - r.x; int dy = (int)copt.y - r.height/2 - r.y; - if (Math.abs(dx) > r.width/3 || Math.abs(dy) > r.height/3) { + if (Math.abs(dx) > r.width/4 || Math.abs(dy) > r.height/4) { r.x += dx; r.y += dy; comp.scrollRectToVisible(r); -- cgit v1.2.3 From 68323cbb222f1f33198a42abaa0550af22f75a93 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 22 Nov 2010 15:53:27 -0800 Subject: altosui: Close serial port when debug link fails If the debug connection isn't working, close down the serial port when reporting the failure. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlash.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index fa2465d3..3af25c23 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -336,7 +336,9 @@ public class AltosFlash { debug = new AltosDebug(in_debug_dongle); input = new FileInputStream(file); image = new AltosHexfile(input); - if (!debug.check_connection()) + if (!debug.check_connection()) { + debug.close(); throw new IOException("Debug port not connected"); + } } } \ No newline at end of file -- cgit v1.2.3 From 5523e7d55ecc8d310e495fa4f5115f7483c42d65 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Mon, 22 Nov 2010 21:07:10 -0700 Subject: add a rudimentary --help for command line use --- ao-tools/altosui/AltosUI.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 93a5e0d8..94c4dd2a 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -353,7 +353,14 @@ public class AltosUI extends JFrame { public static void main(final String[] args) { int process = 0; /* Handle batch-mode */ - if (args.length == 3 && args[0].equals("--fetchmaps")) { + if (args.length == 1 && args[0].equals("--help")) { + System.out.printf("Usage: altosui [OPTION]... [FILE]...\n"); + System.out.printf(" Options:\n"); + System.out.printf(" --fetchmaps \tpre-fetch maps for site map view\n"); + System.out.printf(" --replay \t\trelive the glory of past flights \n"); + System.out.printf(" --csv\tgenerate comma separated output for spreadsheets, etc\n"); + System.out.printf(" --kml\tgenerate KML output for use with Google Earth\n"); + } else if (args.length == 3 && args[0].equals("--fetchmaps")) { double lat = Double.parseDouble(args[1]); double lon = Double.parseDouble(args[2]); AltosSiteMap.prefetchMaps(lat, lon, 5, 5); -- cgit v1.2.3 From ed7cf7d262fcf7c0c677c2fb981582b571de9e5e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 19:04:55 -0800 Subject: altosui: Make AltosSerial.flush_input keep reading while non-empty Flushing the input buffer can take a while, especially over the packet link. Keep reading while stuff is appearing on the reply queue. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index ab74486b..8a6ad05e 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -114,16 +114,20 @@ public class AltosSerial implements Runnable { public void flush_input() { flush_output(); - try { - Thread.sleep(200); - } catch (InterruptedException ie) { - } - synchronized(this) { - if (!"VERSION".startsWith(line) && - !line.startsWith("VERSION")) - line = ""; - reply_queue.clear(); - } + boolean got_some; + do { + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + } + got_some = !reply_queue.isEmpty(); + synchronized(this) { + if (!"VERSION".startsWith(line) && + !line.startsWith("VERSION")) + line = ""; + reply_queue.clear(); + } + } while (got_some); } public String get_reply() throws InterruptedException { -- cgit v1.2.3 From 6cd9be22f06f21d12ee2f668989d83d3c61d14c0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 19:08:07 -0800 Subject: altosui: New AltosSerial.set_radio function sets channel/call Use this anytime you need to set the device radio channel and call sign, either for telemetry reception or packet mode origination. This uses the saved callsign and per-device radio channel number. Do not use this when opening a telemetrum as there won't be a saved channel number. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 7 +++---- ao-tools/altosui/AltosEepromDownload.java | 7 +++---- ao-tools/altosui/AltosFlightUI.java | 1 - ao-tools/altosui/AltosIgnite.java | 7 +++---- ao-tools/altosui/AltosSerial.java | 9 +++++++-- ao-tools/altosui/AltosTelemetryReader.java | 6 ++---- 6 files changed, 18 insertions(+), 19 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 6bda20d8..52dbfd79 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -109,9 +109,8 @@ public class AltosConfig implements Runnable, ActionListener { void start_serial() throws InterruptedException { if (remote) { - serial_line.set_channel(AltosPreferences.channel(device.getSerial())); - serial_line.set_callsign(AltosPreferences.callsign()); - serial_line.printf("p\n"); + serial_line.set_radio(); + serial_line.printf("p\nE 0\n"); serial_line.flush_input(); } } @@ -128,7 +127,7 @@ public class AltosConfig implements Runnable, ActionListener { start_serial(); serial_line.printf("c s\nv\n"); for (;;) { - String line = serial_line.get_reply(1000); + String line = serial_line.get_reply(5000); if (line == null) throw new TimeoutException(); get_int(line, "serial-number", serial); diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index fb5dcfc0..02fc36f2 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -97,7 +97,7 @@ public class AltosEepromDownload implements Runnable { /* Pull the serial number out of the version information */ for (;;) { - String line = serial_line.get_reply(1000); + String line = serial_line.get_reply(5000); if (line == null) throw new TimeoutException(); @@ -127,7 +127,7 @@ public class AltosEepromDownload implements Runnable { any_valid = false; monitor.set_value(state_names[state], state, block - state_block); for (addr = 0; addr < 0x100;) { - String line = serial_line.get_reply(1000); + String line = serial_line.get_reply(5000); if (line == null) throw new TimeoutException(); int[] values = ParseHex(line); @@ -216,8 +216,7 @@ public class AltosEepromDownload implements Runnable { public void run () { if (remote) { - serial_line.set_channel(AltosPreferences.channel(device.getSerial())); - serial_line.set_callsign(AltosPreferences.callsign()); + serial_line.set_radio(); serial_line.printf("p\nE 0\n"); serial_line.flush_input(); } diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 732f7395..24d25bd7 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -148,7 +148,6 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { public void actionPerformed(ActionEvent e) { int channel = channels.getSelectedIndex(); reader.set_channel(channel); - AltosPreferences.set_channel(serial, channel); } }); c.gridx = 0; diff --git a/ao-tools/altosui/AltosIgnite.java b/ao-tools/altosui/AltosIgnite.java index 8e92ec1b..75c0a17a 100644 --- a/ao-tools/altosui/AltosIgnite.java +++ b/ao-tools/altosui/AltosIgnite.java @@ -35,9 +35,8 @@ public class AltosIgnite { private void start_serial() throws InterruptedException { if (remote) { - serial.set_channel(AltosPreferences.channel(device.getSerial())); - serial.set_callsign(AltosPreferences.callsign()); - serial.printf("~\np\n"); + serial.set_radio(); + serial.printf("p\nE 0\n"); serial.flush_input(); } } @@ -100,7 +99,7 @@ public class AltosIgnite { start_serial(); serial.printf("t\n"); for (;;) { - String line = serial.get_reply(1000); + String line = serial.get_reply(5000); if (line == null) throw new TimeoutException(); if (get_string(line, "Igniter: drogue Status: ", status_name)) diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 8a6ad05e..b19143e5 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -198,13 +198,18 @@ public class AltosSerial implements Runnable { devices_opened.add(device.getPath()); } altos = libaltos.altos_open(device); - if (altos == null) + if (altos == null) { + close(); throw new FileNotFoundException(device.toShortString()); + } input_thread = new Thread(this); input_thread.start(); print("~\nE 0\n"); + set_monitor(false); flush_output(); - set_monitor(monitor_mode); + } + + public void set_radio() { set_channel(AltosPreferences.channel(device.getSerial())); set_callsign(AltosPreferences.callsign()); } diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index de5f50e9..6c5a9397 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -44,10 +44,7 @@ class AltosTelemetryReader extends AltosFlightReader { void set_channel(int channel) { serial.set_channel(channel); - } - - void set_callsign(String callsign) { - serial.set_callsign(callsign); + AltosPreferences.set_channel(device.getSerial(), channel); } public AltosTelemetryReader (AltosDevice in_device) @@ -58,6 +55,7 @@ class AltosTelemetryReader extends AltosFlightReader { name = device.toShortString(); telem = new LinkedBlockingQueue(); + serial.set_radio(); serial.add_monitor(telem); } } -- cgit v1.2.3 From f3233985a132e1d660e6df12d0056b6729f16faf Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 19:09:31 -0800 Subject: altosui: Disable radio configation over packet link. Attempting to configure the radio over the packet link will only end up confusing the user, so disable it. This also works around a bug in older TM code which would lock up when trying to do this. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 8 +++++--- ao-tools/altosui/AltosConfigUI.java | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 52dbfd79..b1acd410 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -149,7 +149,7 @@ public class AltosConfig implements Runnable, ActionListener { } void init_ui () throws InterruptedException, TimeoutException { - config_ui = new AltosConfigUI(owner); + config_ui = new AltosConfigUI(owner, remote); config_ui.addActionListener(this); set_ui(); } @@ -191,8 +191,10 @@ public class AltosConfig implements Runnable, ActionListener { start_serial(); serial_line.printf("c m %d\n", main_deploy.get()); serial_line.printf("c d %d\n", apogee_delay.get()); - serial_line.printf("c r %d\n", radio_channel.get()); - serial_line.printf("c f %d\n", radio_calibration.get()); + if (!remote) { + serial_line.printf("c r %d\n", radio_channel.get()); + serial_line.printf("c f %d\n", radio_calibration.get()); + } serial_line.printf("c c %s\n", callsign.get()); serial_line.printf("c w\n"); } catch (InterruptedException ie) { diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index ca89f58d..cfa5d7b9 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -98,7 +98,7 @@ public class AltosConfigUI } /* Build the UI using a grid bag */ - public AltosConfigUI(JFrame in_owner) { + public AltosConfigUI(JFrame in_owner, boolean remote) { super (in_owner, "Configure TeleMetrum", false); owner = in_owner; @@ -244,6 +244,8 @@ public class AltosConfigUI radio_channel_value = new JComboBox(radio_channel_values); radio_channel_value.setEditable(false); radio_channel_value.addItemListener(this); + if (remote) + radio_channel_value.setEnabled(false); pane.add(radio_channel_value, c); /* Radio Calibration */ @@ -267,6 +269,8 @@ public class AltosConfigUI c.ipady = 5; radio_calibration_value = new JTextField(String.format("%d", 1186611)); radio_calibration_value.getDocument().addDocumentListener(this); + if (remote) + radio_calibration_value.setEnabled(false); pane.add(radio_calibration_value, c); /* Callsign */ -- cgit v1.2.3 From 7d90e2f6009e060fb59c519f7e564483a7ca6872 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 20:17:44 -0800 Subject: altosui: Let people fire igniters that don't read as 'ready' This provides for igniter testing with LEDs or other materials that don't look like regular igniters. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosIgniteUI.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosIgniteUI.java b/ao-tools/altosui/AltosIgniteUI.java index 0207e39f..d542729c 100644 --- a/ao-tools/altosui/AltosIgniteUI.java +++ b/ao-tools/altosui/AltosIgniteUI.java @@ -145,13 +145,11 @@ public class AltosIgniteUI if (cmd.equals("apogee") && apogee.isSelected()) { main.setSelected(false); - if (apogee_status == AltosIgnite.Ready) - arm.setEnabled(true); + arm.setEnabled(true); } if (cmd.equals("main") && main.isSelected()) { apogee.setSelected(false); - if (main_status == AltosIgnite.Ready) - arm.setEnabled(true); + arm.setEnabled(true); } if (cmd.equals("arm")) { -- cgit v1.2.3 From 7a50837ea0d92db3f469f197ec8210aee22aa143 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 24 Nov 2010 10:55:18 -0800 Subject: altosui: Make sure packet mode is turned off when the connection fails When the packet connection times out, turn packet mode off when closing the serial port. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 10 +++++++++- ao-tools/altosui/AltosIgnite.java | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index b1acd410..1c42870f 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -74,7 +74,7 @@ public class AltosConfig implements Runnable, ActionListener { string_ref product; string_ref callsign; AltosConfigUI config_ui; - + boolean serial_started; boolean get_int(String line, String label, int_ref x) { if (line.startsWith(label)) { @@ -108,6 +108,7 @@ public class AltosConfig implements Runnable, ActionListener { } void start_serial() throws InterruptedException { + serial_started = true; if (remote) { serial_line.set_radio(); serial_line.printf("p\nE 0\n"); @@ -116,6 +117,9 @@ public class AltosConfig implements Runnable, ActionListener { } void stop_serial() throws InterruptedException { + if (!serial_started) + return; + serial_started = false; if (remote) { serial_line.printf("~"); serial_line.flush_output(); @@ -160,6 +164,10 @@ public class AltosConfig implements Runnable, ActionListener { device.toShortString()), "Connection Failed", JOptionPane.ERROR_MESSAGE); + try { + stop_serial(); + } catch (InterruptedException ie) { + } serial_line.close(); serial_line = null; } diff --git a/ao-tools/altosui/AltosIgnite.java b/ao-tools/altosui/AltosIgnite.java index 75c0a17a..3cbd8a75 100644 --- a/ao-tools/altosui/AltosIgnite.java +++ b/ao-tools/altosui/AltosIgnite.java @@ -24,6 +24,7 @@ public class AltosIgnite { AltosDevice device; AltosSerial serial; boolean remote; + boolean serial_started; final static int None = 0; final static int Apogee = 1; final static int Main = 2; @@ -34,6 +35,7 @@ public class AltosIgnite { final static int Open = 3; private void start_serial() throws InterruptedException { + serial_started = true; if (remote) { serial.set_radio(); serial.printf("p\nE 0\n"); @@ -42,6 +44,9 @@ public class AltosIgnite { } private void stop_serial() throws InterruptedException { + if (!serial_started) + return; + serial_started = false; if (serial == null) return; if (remote) { @@ -148,6 +153,10 @@ public class AltosIgnite { } public void close() { + try { + stop_serial(); + } catch (InterruptedException ie) { + } serial.close(); serial = null; } -- cgit v1.2.3 From 3fbefb3eea981d34a09496cf8abf0119de2e35bf Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 24 Nov 2010 14:57:57 -0800 Subject: Move altosui to the top level, placing libaltos inside it. Signed-off-by: Keith Packard --- altosui/.gitignore | 19 + .../01altosui-contents.xml | 1 + .../01altosui.xml | 1 + .../AltOS Package Configuration.pmdoc/index.xml | 1 + altosui/Altos.java | 218 +++++ altosui/AltosAscent.java | 335 +++++++ altosui/AltosCRCException.java | 26 + altosui/AltosCSV.java | 252 +++++ altosui/AltosCSVUI.java | 108 ++ altosui/AltosChannelMenu.java | 44 + altosui/AltosConfig.java | 295 ++++++ altosui/AltosConfigUI.java | 466 +++++++++ altosui/AltosConfigureUI.java | 187 ++++ altosui/AltosConvert.java | 192 ++++ altosui/AltosDataChooser.java | 79 ++ altosui/AltosDataPoint.java | 29 + altosui/AltosDataPointReader.java | 72 ++ altosui/AltosDebug.java | 267 +++++ altosui/AltosDescent.java | 353 +++++++ altosui/AltosDevice.java | 170 ++++ altosui/AltosDeviceDialog.java | 164 ++++ altosui/AltosDisplayThread.java | 249 +++++ altosui/AltosEepromDownload.java | 285 ++++++ altosui/AltosEepromIterable.java | 423 ++++++++ altosui/AltosEepromMonitor.java | 176 ++++ altosui/AltosEepromRecord.java | 115 +++ altosui/AltosFile.java | 44 + altosui/AltosFlash.java | 344 +++++++ altosui/AltosFlashUI.java | 218 +++++ altosui/AltosFlightDisplay.java | 24 + altosui/AltosFlightInfoTableModel.java | 84 ++ altosui/AltosFlightReader.java | 38 + altosui/AltosFlightStatus.java | 154 +++ altosui/AltosFlightStatusTableModel.java | 61 ++ altosui/AltosFlightUI.java | 221 +++++ altosui/AltosGPS.java | 215 ++++ altosui/AltosGraph.java | 25 + altosui/AltosGraphTime.java | 233 +++++ altosui/AltosGraphUI.java | 274 ++++++ altosui/AltosGreatCircle.java | 100 ++ altosui/AltosHexfile.java | 252 +++++ altosui/AltosIgnite.java | 173 ++++ altosui/AltosIgniteUI.java | 317 ++++++ altosui/AltosInfoTable.java | 190 ++++ altosui/AltosKML.java | 169 ++++ altosui/AltosLanded.java | 212 ++++ altosui/AltosLed.java | 54 + altosui/AltosLights.java | 73 ++ altosui/AltosLine.java | 30 + altosui/AltosLog.java | 115 +++ altosui/AltosPad.java | 269 +++++ altosui/AltosParse.java | 79 ++ altosui/AltosPreferences.java | 205 ++++ altosui/AltosReader.java | 28 + altosui/AltosRecord.java | 219 +++++ altosui/AltosRecordIterable.java | 34 + altosui/AltosReplayReader.java | 57 ++ altosui/AltosRomconfig.java | 147 +++ altosui/AltosRomconfigUI.java | 186 ++++ altosui/AltosSerial.java | 253 +++++ altosui/AltosSerialInUseException.java | 28 + altosui/AltosSerialMonitor.java | 22 + altosui/AltosSiteMap.java | 388 ++++++++ altosui/AltosSiteMapCache.java | 103 ++ altosui/AltosSiteMapTile.java | 112 +++ altosui/AltosState.java | 197 ++++ altosui/AltosTelemetry.java | 143 +++ altosui/AltosTelemetryIterable.java | 82 ++ altosui/AltosTelemetryReader.java | 61 ++ altosui/AltosUI.app/Contents/Info.plist | 38 + .../AltosUI.app/Contents/MacOS/JavaApplicationStub | Bin 0 -> 61296 bytes altosui/AltosUI.app/Contents/PkgInfo | 1 + .../Contents/Resources/AltosUIIcon.icns | Bin 0 -> 129010 bytes altosui/AltosUI.java | 405 ++++++++ altosui/AltosVoice.java | 95 ++ altosui/AltosWriter.java | 32 + altosui/GrabNDrag.java | 54 + altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi | 84 ++ .../Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe | Bin 0 -> 51831 bytes altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c | 704 ++++++++++++++ altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp | 110 +++ altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw | 29 + altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt | 141 +++ altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf | 137 +++ altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys | Bin 0 -> 30464 bytes altosui/Instdrv/NSIS/Plugins/InstDrv.dll | Bin 0 -> 6656 bytes altosui/Makefile-standalone | 184 ++++ altosui/Makefile.am | 272 ++++++ altosui/altos-windows.nsi | 113 +++ altosui/altosui-fat | 4 + altosui/altosui.1 | 46 + altosui/altusmetrum.jpg | Bin 0 -> 72868 bytes altosui/libaltos/.gitignore | 12 + altosui/libaltos/Makefile-standalone | 126 +++ altosui/libaltos/Makefile.am | 41 + altosui/libaltos/altos.dll | Bin 0 -> 31765 bytes altosui/libaltos/cjnitest.c | 43 + altosui/libaltos/libaltos.c | 1028 ++++++++++++++++++++ altosui/libaltos/libaltos.dylib | Bin 0 -> 54176 bytes altosui/libaltos/libaltos.h | 102 ++ altosui/libaltos/libaltos.i0 | 5 + ao-tools/Makefile.am | 2 +- ao-tools/altosui/.gitignore | 19 - .../01altosui-contents.xml | 1 - .../01altosui.xml | 1 - .../AltOS Package Configuration.pmdoc/index.xml | 1 - ao-tools/altosui/Altos.java | 218 ----- ao-tools/altosui/AltosAscent.java | 335 ------- ao-tools/altosui/AltosCRCException.java | 26 - ao-tools/altosui/AltosCSV.java | 252 ----- ao-tools/altosui/AltosCSVUI.java | 108 -- ao-tools/altosui/AltosChannelMenu.java | 44 - ao-tools/altosui/AltosConfig.java | 295 ------ ao-tools/altosui/AltosConfigUI.java | 466 --------- ao-tools/altosui/AltosConfigureUI.java | 187 ---- ao-tools/altosui/AltosConvert.java | 192 ---- ao-tools/altosui/AltosDataChooser.java | 79 -- ao-tools/altosui/AltosDataPoint.java | 29 - ao-tools/altosui/AltosDataPointReader.java | 72 -- ao-tools/altosui/AltosDebug.java | 267 ----- ao-tools/altosui/AltosDescent.java | 353 ------- ao-tools/altosui/AltosDevice.java | 170 ---- ao-tools/altosui/AltosDeviceDialog.java | 164 ---- ao-tools/altosui/AltosDisplayThread.java | 249 ----- ao-tools/altosui/AltosEepromDownload.java | 285 ------ ao-tools/altosui/AltosEepromIterable.java | 423 -------- ao-tools/altosui/AltosEepromMonitor.java | 176 ---- ao-tools/altosui/AltosEepromRecord.java | 115 --- ao-tools/altosui/AltosFile.java | 44 - ao-tools/altosui/AltosFlash.java | 344 ------- ao-tools/altosui/AltosFlashUI.java | 218 ----- ao-tools/altosui/AltosFlightDisplay.java | 24 - ao-tools/altosui/AltosFlightInfoTableModel.java | 84 -- ao-tools/altosui/AltosFlightReader.java | 38 - ao-tools/altosui/AltosFlightStatus.java | 154 --- ao-tools/altosui/AltosFlightStatusTableModel.java | 61 -- ao-tools/altosui/AltosFlightUI.java | 221 ----- ao-tools/altosui/AltosGPS.java | 215 ---- ao-tools/altosui/AltosGraph.java | 25 - ao-tools/altosui/AltosGraphTime.java | 233 ----- ao-tools/altosui/AltosGraphUI.java | 274 ------ ao-tools/altosui/AltosGreatCircle.java | 100 -- ao-tools/altosui/AltosHexfile.java | 252 ----- ao-tools/altosui/AltosIgnite.java | 173 ---- ao-tools/altosui/AltosIgniteUI.java | 317 ------ ao-tools/altosui/AltosInfoTable.java | 190 ---- ao-tools/altosui/AltosKML.java | 169 ---- ao-tools/altosui/AltosLanded.java | 212 ---- ao-tools/altosui/AltosLed.java | 54 - ao-tools/altosui/AltosLights.java | 73 -- ao-tools/altosui/AltosLine.java | 30 - ao-tools/altosui/AltosLog.java | 115 --- ao-tools/altosui/AltosPad.java | 269 ----- ao-tools/altosui/AltosParse.java | 79 -- ao-tools/altosui/AltosPreferences.java | 205 ---- ao-tools/altosui/AltosReader.java | 28 - ao-tools/altosui/AltosRecord.java | 219 ----- ao-tools/altosui/AltosRecordIterable.java | 34 - ao-tools/altosui/AltosReplayReader.java | 57 -- ao-tools/altosui/AltosRomconfig.java | 147 --- ao-tools/altosui/AltosRomconfigUI.java | 186 ---- ao-tools/altosui/AltosSerial.java | 253 ----- ao-tools/altosui/AltosSerialInUseException.java | 28 - ao-tools/altosui/AltosSerialMonitor.java | 22 - ao-tools/altosui/AltosSiteMap.java | 388 -------- ao-tools/altosui/AltosSiteMapCache.java | 103 -- ao-tools/altosui/AltosSiteMapTile.java | 112 --- ao-tools/altosui/AltosState.java | 197 ---- ao-tools/altosui/AltosTelemetry.java | 143 --- ao-tools/altosui/AltosTelemetryIterable.java | 82 -- ao-tools/altosui/AltosTelemetryReader.java | 61 -- ao-tools/altosui/AltosUI.app/Contents/Info.plist | 38 - .../AltosUI.app/Contents/MacOS/JavaApplicationStub | Bin 61296 -> 0 bytes ao-tools/altosui/AltosUI.app/Contents/PkgInfo | 1 - .../Contents/Resources/AltosUIIcon.icns | Bin 129010 -> 0 bytes ao-tools/altosui/AltosUI.java | 405 -------- ao-tools/altosui/AltosVoice.java | 95 -- ao-tools/altosui/AltosWriter.java | 32 - ao-tools/altosui/GrabNDrag.java | 54 - .../Instdrv/NSIS/Contrib/InstDrv/Example.nsi | 84 -- .../Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe | Bin 51831 -> 0 bytes .../altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c | 704 -------------- .../Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp | 110 --- .../Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw | 29 - .../Instdrv/NSIS/Contrib/InstDrv/Readme.txt | 141 --- .../Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf | 137 --- .../Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys | Bin 30464 -> 0 bytes ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll | Bin 6656 -> 0 bytes ao-tools/altosui/Makefile-standalone | 184 ---- ao-tools/altosui/Makefile.am | 271 ------ ao-tools/altosui/altos-windows.nsi | 113 --- ao-tools/altosui/altosui-fat | 4 - ao-tools/altosui/altosui.1 | 46 - ao-tools/altosui/altusmetrum.jpg | Bin 72868 -> 0 bytes ao-tools/libaltos/.gitignore | 12 - ao-tools/libaltos/Makefile-standalone | 126 --- ao-tools/libaltos/Makefile.am | 41 - ao-tools/libaltos/altos.dll | Bin 31765 -> 0 bytes ao-tools/libaltos/cjnitest.c | 43 - ao-tools/libaltos/libaltos.c | 1028 -------------------- ao-tools/libaltos/libaltos.dylib | Bin 54176 -> 0 bytes ao-tools/libaltos/libaltos.h | 102 -- ao-tools/libaltos/libaltos.i0 | 5 - configure.ac | 4 +- 204 files changed, 14569 insertions(+), 14568 deletions(-) create mode 100644 altosui/.gitignore create mode 100644 altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml create mode 100644 altosui/AltOS Package Configuration.pmdoc/01altosui.xml create mode 100644 altosui/AltOS Package Configuration.pmdoc/index.xml create mode 100644 altosui/Altos.java create mode 100644 altosui/AltosAscent.java create mode 100644 altosui/AltosCRCException.java create mode 100644 altosui/AltosCSV.java create mode 100644 altosui/AltosCSVUI.java create mode 100644 altosui/AltosChannelMenu.java create mode 100644 altosui/AltosConfig.java create mode 100644 altosui/AltosConfigUI.java create mode 100644 altosui/AltosConfigureUI.java create mode 100644 altosui/AltosConvert.java create mode 100644 altosui/AltosDataChooser.java create mode 100644 altosui/AltosDataPoint.java create mode 100644 altosui/AltosDataPointReader.java create mode 100644 altosui/AltosDebug.java create mode 100644 altosui/AltosDescent.java create mode 100644 altosui/AltosDevice.java create mode 100644 altosui/AltosDeviceDialog.java create mode 100644 altosui/AltosDisplayThread.java create mode 100644 altosui/AltosEepromDownload.java create mode 100644 altosui/AltosEepromIterable.java create mode 100644 altosui/AltosEepromMonitor.java create mode 100644 altosui/AltosEepromRecord.java create mode 100644 altosui/AltosFile.java create mode 100644 altosui/AltosFlash.java create mode 100644 altosui/AltosFlashUI.java create mode 100644 altosui/AltosFlightDisplay.java create mode 100644 altosui/AltosFlightInfoTableModel.java create mode 100644 altosui/AltosFlightReader.java create mode 100644 altosui/AltosFlightStatus.java create mode 100644 altosui/AltosFlightStatusTableModel.java create mode 100644 altosui/AltosFlightUI.java create mode 100644 altosui/AltosGPS.java create mode 100644 altosui/AltosGraph.java create mode 100644 altosui/AltosGraphTime.java create mode 100644 altosui/AltosGraphUI.java create mode 100644 altosui/AltosGreatCircle.java create mode 100644 altosui/AltosHexfile.java create mode 100644 altosui/AltosIgnite.java create mode 100644 altosui/AltosIgniteUI.java create mode 100644 altosui/AltosInfoTable.java create mode 100644 altosui/AltosKML.java create mode 100644 altosui/AltosLanded.java create mode 100644 altosui/AltosLed.java create mode 100644 altosui/AltosLights.java create mode 100644 altosui/AltosLine.java create mode 100644 altosui/AltosLog.java create mode 100644 altosui/AltosPad.java create mode 100644 altosui/AltosParse.java create mode 100644 altosui/AltosPreferences.java create mode 100644 altosui/AltosReader.java create mode 100644 altosui/AltosRecord.java create mode 100644 altosui/AltosRecordIterable.java create mode 100644 altosui/AltosReplayReader.java create mode 100644 altosui/AltosRomconfig.java create mode 100644 altosui/AltosRomconfigUI.java create mode 100644 altosui/AltosSerial.java create mode 100644 altosui/AltosSerialInUseException.java create mode 100644 altosui/AltosSerialMonitor.java create mode 100644 altosui/AltosSiteMap.java create mode 100644 altosui/AltosSiteMapCache.java create mode 100644 altosui/AltosSiteMapTile.java create mode 100644 altosui/AltosState.java create mode 100644 altosui/AltosTelemetry.java create mode 100644 altosui/AltosTelemetryIterable.java create mode 100644 altosui/AltosTelemetryReader.java create mode 100644 altosui/AltosUI.app/Contents/Info.plist create mode 100755 altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub create mode 100644 altosui/AltosUI.app/Contents/PkgInfo create mode 100644 altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns create mode 100644 altosui/AltosUI.java create mode 100644 altosui/AltosVoice.java create mode 100644 altosui/AltosWriter.java create mode 100644 altosui/GrabNDrag.java create mode 100644 altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi create mode 100644 altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe create mode 100644 altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c create mode 100644 altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp create mode 100644 altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw create mode 100644 altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt create mode 100644 altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf create mode 100644 altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys create mode 100644 altosui/Instdrv/NSIS/Plugins/InstDrv.dll create mode 100644 altosui/Makefile-standalone create mode 100644 altosui/Makefile.am create mode 100644 altosui/altos-windows.nsi create mode 100755 altosui/altosui-fat create mode 100644 altosui/altosui.1 create mode 100644 altosui/altusmetrum.jpg create mode 100644 altosui/libaltos/.gitignore create mode 100644 altosui/libaltos/Makefile-standalone create mode 100644 altosui/libaltos/Makefile.am create mode 100755 altosui/libaltos/altos.dll create mode 100644 altosui/libaltos/cjnitest.c create mode 100644 altosui/libaltos/libaltos.c create mode 100755 altosui/libaltos/libaltos.dylib create mode 100644 altosui/libaltos/libaltos.h create mode 100644 altosui/libaltos/libaltos.i0 delete mode 100644 ao-tools/altosui/.gitignore delete mode 100644 ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml delete mode 100644 ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml delete mode 100644 ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml delete mode 100644 ao-tools/altosui/Altos.java delete mode 100644 ao-tools/altosui/AltosAscent.java delete mode 100644 ao-tools/altosui/AltosCRCException.java delete mode 100644 ao-tools/altosui/AltosCSV.java delete mode 100644 ao-tools/altosui/AltosCSVUI.java delete mode 100644 ao-tools/altosui/AltosChannelMenu.java delete mode 100644 ao-tools/altosui/AltosConfig.java delete mode 100644 ao-tools/altosui/AltosConfigUI.java delete mode 100644 ao-tools/altosui/AltosConfigureUI.java delete mode 100644 ao-tools/altosui/AltosConvert.java delete mode 100644 ao-tools/altosui/AltosDataChooser.java delete mode 100644 ao-tools/altosui/AltosDataPoint.java delete mode 100644 ao-tools/altosui/AltosDataPointReader.java delete mode 100644 ao-tools/altosui/AltosDebug.java delete mode 100644 ao-tools/altosui/AltosDescent.java delete mode 100644 ao-tools/altosui/AltosDevice.java delete mode 100644 ao-tools/altosui/AltosDeviceDialog.java delete mode 100644 ao-tools/altosui/AltosDisplayThread.java delete mode 100644 ao-tools/altosui/AltosEepromDownload.java delete mode 100644 ao-tools/altosui/AltosEepromIterable.java delete mode 100644 ao-tools/altosui/AltosEepromMonitor.java delete mode 100644 ao-tools/altosui/AltosEepromRecord.java delete mode 100644 ao-tools/altosui/AltosFile.java delete mode 100644 ao-tools/altosui/AltosFlash.java delete mode 100644 ao-tools/altosui/AltosFlashUI.java delete mode 100644 ao-tools/altosui/AltosFlightDisplay.java delete mode 100644 ao-tools/altosui/AltosFlightInfoTableModel.java delete mode 100644 ao-tools/altosui/AltosFlightReader.java delete mode 100644 ao-tools/altosui/AltosFlightStatus.java delete mode 100644 ao-tools/altosui/AltosFlightStatusTableModel.java delete mode 100644 ao-tools/altosui/AltosFlightUI.java delete mode 100644 ao-tools/altosui/AltosGPS.java delete mode 100644 ao-tools/altosui/AltosGraph.java delete mode 100644 ao-tools/altosui/AltosGraphTime.java delete mode 100644 ao-tools/altosui/AltosGraphUI.java delete mode 100644 ao-tools/altosui/AltosGreatCircle.java delete mode 100644 ao-tools/altosui/AltosHexfile.java delete mode 100644 ao-tools/altosui/AltosIgnite.java delete mode 100644 ao-tools/altosui/AltosIgniteUI.java delete mode 100644 ao-tools/altosui/AltosInfoTable.java delete mode 100644 ao-tools/altosui/AltosKML.java delete mode 100644 ao-tools/altosui/AltosLanded.java delete mode 100644 ao-tools/altosui/AltosLed.java delete mode 100644 ao-tools/altosui/AltosLights.java delete mode 100644 ao-tools/altosui/AltosLine.java delete mode 100644 ao-tools/altosui/AltosLog.java delete mode 100644 ao-tools/altosui/AltosPad.java delete mode 100644 ao-tools/altosui/AltosParse.java delete mode 100644 ao-tools/altosui/AltosPreferences.java delete mode 100644 ao-tools/altosui/AltosReader.java delete mode 100644 ao-tools/altosui/AltosRecord.java delete mode 100644 ao-tools/altosui/AltosRecordIterable.java delete mode 100644 ao-tools/altosui/AltosReplayReader.java delete mode 100644 ao-tools/altosui/AltosRomconfig.java delete mode 100644 ao-tools/altosui/AltosRomconfigUI.java delete mode 100644 ao-tools/altosui/AltosSerial.java delete mode 100644 ao-tools/altosui/AltosSerialInUseException.java delete mode 100644 ao-tools/altosui/AltosSerialMonitor.java delete mode 100644 ao-tools/altosui/AltosSiteMap.java delete mode 100644 ao-tools/altosui/AltosSiteMapCache.java delete mode 100644 ao-tools/altosui/AltosSiteMapTile.java delete mode 100644 ao-tools/altosui/AltosState.java delete mode 100644 ao-tools/altosui/AltosTelemetry.java delete mode 100644 ao-tools/altosui/AltosTelemetryIterable.java delete mode 100644 ao-tools/altosui/AltosTelemetryReader.java delete mode 100644 ao-tools/altosui/AltosUI.app/Contents/Info.plist delete mode 100755 ao-tools/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub delete mode 100644 ao-tools/altosui/AltosUI.app/Contents/PkgInfo delete mode 100644 ao-tools/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns delete mode 100644 ao-tools/altosui/AltosUI.java delete mode 100644 ao-tools/altosui/AltosVoice.java delete mode 100644 ao-tools/altosui/AltosWriter.java delete mode 100644 ao-tools/altosui/GrabNDrag.java delete mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi delete mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe delete mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c delete mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp delete mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw delete mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt delete mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf delete mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys delete mode 100644 ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll delete mode 100644 ao-tools/altosui/Makefile-standalone delete mode 100644 ao-tools/altosui/Makefile.am delete mode 100644 ao-tools/altosui/altos-windows.nsi delete mode 100755 ao-tools/altosui/altosui-fat delete mode 100644 ao-tools/altosui/altosui.1 delete mode 100644 ao-tools/altosui/altusmetrum.jpg delete mode 100644 ao-tools/libaltos/.gitignore delete mode 100644 ao-tools/libaltos/Makefile-standalone delete mode 100644 ao-tools/libaltos/Makefile.am delete mode 100755 ao-tools/libaltos/altos.dll delete mode 100644 ao-tools/libaltos/cjnitest.c delete mode 100644 ao-tools/libaltos/libaltos.c delete mode 100755 ao-tools/libaltos/libaltos.dylib delete mode 100644 ao-tools/libaltos/libaltos.h delete mode 100644 ao-tools/libaltos/libaltos.i0 (limited to 'ao-tools') diff --git a/altosui/.gitignore b/altosui/.gitignore new file mode 100644 index 00000000..89be1d53 --- /dev/null +++ b/altosui/.gitignore @@ -0,0 +1,19 @@ +windows/ +linux/ +macosx/ +fat/ +Manifest.txt +Manifest-fat.txt +libaltosJNI +classes +altosui +altosui-test +classaltosui.stamp +Altos-Linux-*.tar.bz2 +Altos-Mac-*.zip +Altos-Windows-*.exe +*.dll +*.dylib +*.so +*.jar +*.class diff --git a/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml b/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml new file mode 100644 index 00000000..18e00fe4 --- /dev/null +++ b/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/altosui/AltOS Package Configuration.pmdoc/01altosui.xml b/altosui/AltOS Package Configuration.pmdoc/01altosui.xml new file mode 100644 index 00000000..6170931b --- /dev/null +++ b/altosui/AltOS Package Configuration.pmdoc/01altosui.xml @@ -0,0 +1 @@ +org.altusmetrum.altosUi.AltosUI.pkg0.7AltosUI.app/Applications/AltosUI.appinstallTo.pathinstallFrom.isRelativeTypeversionparentrequireAuthorizationinstallTo01altosui-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ \ No newline at end of file diff --git a/altosui/AltOS Package Configuration.pmdoc/index.xml b/altosui/AltOS Package Configuration.pmdoc/index.xml new file mode 100644 index 00000000..fabe54a6 --- /dev/null +++ b/altosui/AltOS Package Configuration.pmdoc/index.xml @@ -0,0 +1 @@ +AltOS UI/Users/keithp/altos/ao-tools/altosui/AltosUI.pkgorg.altusmetrumInstall AltOS User Interfacealtusmetrum.jpg01altosui.xmlproperties.anywhereDomainproperties.titleproperties.customizeOptiondescriptionproperties.userDomainproperties.systemDomain \ No newline at end of file diff --git a/altosui/Altos.java b/altosui/Altos.java new file mode 100644 index 00000000..8ee94e04 --- /dev/null +++ b/altosui/Altos.java @@ -0,0 +1,218 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.util.*; +import java.text.*; + +public class Altos { + /* EEProm command letters */ + static final int AO_LOG_FLIGHT = 'F'; + static final int AO_LOG_SENSOR = 'A'; + static final int AO_LOG_TEMP_VOLT = 'T'; + static final int AO_LOG_DEPLOY = 'D'; + static final int AO_LOG_STATE = 'S'; + static final int AO_LOG_GPS_TIME = 'G'; + static final int AO_LOG_GPS_LAT = 'N'; + static final int AO_LOG_GPS_LON = 'W'; + static final int AO_LOG_GPS_ALT = 'H'; + static final int AO_LOG_GPS_SAT = 'V'; + static final int AO_LOG_GPS_DATE = 'Y'; + + /* Added for header fields in eeprom files */ + static final int AO_LOG_CONFIG_VERSION = 1000; + static final int AO_LOG_MAIN_DEPLOY = 1001; + static final int AO_LOG_APOGEE_DELAY = 1002; + static final int AO_LOG_RADIO_CHANNEL = 1003; + static final int AO_LOG_CALLSIGN = 1004; + static final int AO_LOG_ACCEL_CAL = 1005; + static final int AO_LOG_RADIO_CAL = 1006; + static final int AO_LOG_MANUFACTURER = 1007; + static final int AO_LOG_PRODUCT = 1008; + static final int AO_LOG_SERIAL_NUMBER = 1009; + static final int AO_LOG_SOFTWARE_VERSION = 1010; + + /* Added to flag invalid records */ + static final int AO_LOG_INVALID = -1; + + /* Flight state numbers and names */ + static final int ao_flight_startup = 0; + static final int ao_flight_idle = 1; + static final int ao_flight_pad = 2; + static final int ao_flight_boost = 3; + static final int ao_flight_fast = 4; + static final int ao_flight_coast = 5; + static final int ao_flight_drogue = 6; + static final int ao_flight_main = 7; + static final int ao_flight_landed = 8; + static final int ao_flight_invalid = 9; + + static HashMap string_to_state = new HashMap(); + + static boolean map_initialized = false; + + static final int tab_elt_pad = 5; + + static final Font label_font = new Font("Dialog", Font.PLAIN, 22); + static final Font value_font = new Font("Monospaced", Font.PLAIN, 22); + static final Font status_font = new Font("SansSerif", Font.BOLD, 24); + + static final int text_width = 16; + + static void initialize_map() + { + string_to_state.put("startup", ao_flight_startup); + string_to_state.put("idle", ao_flight_idle); + string_to_state.put("pad", ao_flight_pad); + string_to_state.put("boost", ao_flight_boost); + string_to_state.put("fast", ao_flight_fast); + string_to_state.put("coast", ao_flight_coast); + string_to_state.put("drogue", ao_flight_drogue); + string_to_state.put("main", ao_flight_main); + string_to_state.put("landed", ao_flight_landed); + string_to_state.put("invalid", ao_flight_invalid); + map_initialized = true; + } + + static String[] state_to_string = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid", + }; + + static public int state(String state) { + if (!map_initialized) + initialize_map(); + if (string_to_state.containsKey(state)) + return string_to_state.get(state); + return ao_flight_invalid; + } + + static public String state_name(int state) { + if (state < 0 || state_to_string.length <= state) + return "invalid"; + return state_to_string[state]; + } + + 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_NUM_SAT_SHIFT = 0; + static final int AO_GPS_NUM_SAT_MASK = 0xf; + + static boolean isspace(int c) { + switch (c) { + case ' ': + case '\t': + return true; + } + return false; + } + + static boolean ishex(int c) { + if ('0' <= c && c <= '9') + return true; + if ('a' <= c && c <= 'f') + return true; + if ('A' <= c && c <= 'F') + return true; + return false; + } + + static boolean ishex(String s) { + for (int i = 0; i < s.length(); i++) + if (!ishex(s.charAt(i))) + return false; + return true; + } + + static int fromhex(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - 'a' + 10; + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + return -1; + } + + static int fromhex(String s) throws NumberFormatException { + int c, v = 0; + for (int i = 0; i < s.length(); i++) { + c = s.charAt(i); + if (!ishex(c)) { + if (i == 0) + throw new NumberFormatException(String.format("invalid hex \"%s\"", s)); + return v; + } + v = v * 16 + fromhex(c); + } + return v; + } + + static boolean isdec(int c) { + if ('0' <= c && c <= '9') + return true; + return false; + } + + static boolean isdec(String s) { + for (int i = 0; i < s.length(); i++) + if (!isdec(s.charAt(i))) + return false; + return true; + } + + static int fromdec(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + return -1; + } + + static int fromdec(String s) throws NumberFormatException { + int c, v = 0; + int sign = 1; + for (int i = 0; i < s.length(); i++) { + c = s.charAt(i); + if (i == 0 && c == '-') { + sign = -1; + } else if (!isdec(c)) { + if (i == 0) + throw new NumberFormatException(String.format("invalid number \"%s\"", s)); + return v; + } else + v = v * 10 + fromdec(c); + } + return v * sign; + } + + static String replace_extension(String input, String extension) { + int dot = input.lastIndexOf("."); + if (dot > 0) + input = input.substring(0,dot); + return input.concat(extension); + } +} diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java new file mode 100644 index 00000000..64bdcf30 --- /dev/null +++ b/altosui/AltosAscent.java @@ -0,0 +1,335 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosAscent extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + + public class AscentStatus { + JLabel label; + JTextField value; + AltosLights lights; + + void show(AltosState state, int crc_errors) {} + void reset() { + value.setText(""); + lights.set(false); + } + + public AscentStatus (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + lights = new AltosLights(); + c.gridx = 0; c.gridy = y; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(lights, c); + add(lights); + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(Altos.text_width); + value.setFont(Altos.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.gridwidth = 2; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + + } + } + + public class AscentValue { + JLabel label; + JTextField value; + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + } + public AscentValue (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(Altos.text_width); + value.setFont(Altos.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.gridwidth = 2; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + } + } + + public class AscentValueHold { + JLabel label; + JTextField value; + JTextField max_value; + double max; + + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + max_value.setText(""); + max = 0; + } + + void show(String format, double v) { + value.setText(String.format(format, v)); + if (v > max) { + max_value.setText(String.format(format, v)); + max = v; + } + } + public AscentValueHold (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(Altos.text_width); + value.setFont(Altos.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + + max_value = new JTextField(Altos.text_width); + max_value.setFont(Altos.value_font); + max_value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 3; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(max_value, c); + add(max_value); + } + } + + + class Height extends AscentValueHold { + void show (AltosState state, int crc_errors) { + show("%6.0f m", state.height); + } + public Height (GridBagLayout layout, int y) { + super (layout, y, "Height"); + } + } + + Height height; + + class Speed extends AscentValueHold { + void show (AltosState state, int crc_errors) { + double speed = state.speed; + if (!state.ascent) + speed = state.baro_speed; + show("%6.0f m/s", speed); + } + public Speed (GridBagLayout layout, int y) { + super (layout, y, "Speed"); + } + } + + Speed speed; + + class Accel extends AscentValueHold { + void show (AltosState state, int crc_errors) { + show("%6.0f m/s²", state.acceleration); + } + public Accel (GridBagLayout layout, int y) { + super (layout, y, "Acceleration"); + } + } + + Accel accel; + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } + + class Apogee extends AscentStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.drogue_sense)); + lights.set(state.drogue_sense > 3.2); + } + public Apogee (GridBagLayout layout, int y) { + super(layout, y, "Apogee Igniter Voltage"); + } + } + + Apogee apogee; + + class Main extends AscentStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.main_sense)); + lights.set(state.main_sense > 3.2); + } + public Main (GridBagLayout layout, int y) { + super(layout, y, "Main Igniter Voltage"); + } + } + + Main main; + + class Lat extends AscentValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lat,"N", "S")); + else + value.setText("???"); + } + public Lat (GridBagLayout layout, int y) { + super (layout, y, "Latitude"); + } + } + + Lat lat; + + class Lon extends AscentValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lon,"E", "W")); + else + value.setText("???"); + } + public Lon (GridBagLayout layout, int y) { + super (layout, y, "Longitude"); + } + } + + Lon lon; + + public void reset() { + lat.reset(); + lon.reset(); + main.reset(); + apogee.reset(); + height.reset(); + speed.reset(); + accel.reset(); + } + + public void show(AltosState state, int crc_errors) { + lat.show(state, crc_errors); + lon.show(state, crc_errors); + height.show(state, crc_errors); + main.show(state, crc_errors); + apogee.show(state, crc_errors); + speed.show(state, crc_errors); + accel.show(state, crc_errors); + } + + public void labels(GridBagLayout layout, int y) { + GridBagConstraints c; + JLabel cur, max; + + cur = new JLabel("Current"); + cur.setFont(Altos.label_font); + c = new GridBagConstraints(); + c.gridx = 2; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + layout.setConstraints(cur, c); + add(cur); + + max = new JLabel("Maximum"); + max.setFont(Altos.label_font); + c.gridx = 3; c.gridy = y; + layout.setConstraints(max, c); + add(max); + } + + public AltosAscent() { + layout = new GridBagLayout(); + + setLayout(layout); + + /* Elements in ascent display: + * + * lat + * lon + * height + */ + labels(layout, 0); + height = new Height(layout, 1); + speed = new Speed(layout, 2); + accel = new Accel(layout, 3); + lat = new Lat(layout, 4); + lon = new Lon(layout, 5); + apogee = new Apogee(layout, 6); + main = new Main(layout, 7); + } +} diff --git a/altosui/AltosCRCException.java b/altosui/AltosCRCException.java new file mode 100644 index 00000000..4a529bcf --- /dev/null +++ b/altosui/AltosCRCException.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +public class AltosCRCException extends Exception { + public int rssi; + + public AltosCRCException (int in_rssi) { + rssi = in_rssi; + } +} diff --git a/altosui/AltosCSV.java b/altosui/AltosCSV.java new file mode 100644 index 00000000..df98b2b4 --- /dev/null +++ b/altosui/AltosCSV.java @@ -0,0 +1,252 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.text.*; +import java.util.*; + +public class AltosCSV implements AltosWriter { + File name; + PrintStream out; + boolean header_written; + boolean seen_boost; + int boost_tick; + LinkedList pad_records; + AltosState state; + + static final int ALTOS_CSV_VERSION = 2; + + /* Version 2 format: + * + * General info + * version number + * serial number + * flight number + * callsign + * time (seconds since boost) + * rssi + * link quality + * + * Flight status + * state + * state name + * + * Basic sensors + * acceleration (m/s²) + * pressure (mBar) + * altitude (m) + * height (m) + * accelerometer speed (m/s) + * barometer speed (m/s) + * temp (°C) + * battery (V) + * drogue (V) + * main (V) + * + * GPS data + * connected (1/0) + * locked (1/0) + * nsat (used for solution) + * latitude (°) + * longitude (°) + * altitude (m) + * year (e.g. 2010) + * month (1-12) + * day (1-31) + * hour (0-23) + * minute (0-59) + * second (0-59) + * from_pad_dist (m) + * from_pad_azimuth (deg true) + * from_pad_range (m) + * from_pad_elevation (deg from horizon) + * hdop + * + * GPS Sat data + * C/N0 data for all 32 valid SDIDs + */ + + void write_general_header() { + out.printf("version,serial,flight,call,time,rssi,lqi"); + } + + void write_general(AltosRecord record) { + out.printf("%s, %d, %d, %s, %8.2f, %4d, %3d", + ALTOS_CSV_VERSION, record.serial, record.flight, record.callsign, + (double) record.time, + record.rssi, + record.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_basic_header() { + out.printf("acceleration,pressure,altitude,height,accel_speed,baro_speed,temperature,battery_voltage,drogue_voltage,main_voltage"); + } + + void write_basic(AltosRecord record) { + 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.raw_pressure(), + record.raw_altitude(), + record.raw_height(), + record.accel_speed(), + state.baro_speed, + record.temperature(), + record.battery_voltage(), + record.drogue_voltage(), + record.main_voltage()); + } + + void write_gps_header() { + out.printf("connected,locked,nsat,latitude,longitude,altitude,year,month,day,hour,minute,second,pad_dist,pad_range,pad_az,pad_el,hdop"); + } + + void write_gps(AltosRecord record) { + AltosGPS gps = record.gps; + if (gps == null) + gps = new AltosGPS(); + + AltosGreatCircle from_pad = state.from_pad; + 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", + gps.connected?1:0, + gps.locked?1:0, + gps.nsat, + gps.lat, + gps.lon, + gps.alt, + gps.year, + gps.month, + gps.day, + gps.hour, + gps.minute, + gps.second, + from_pad.distance, + state.range, + from_pad.bearing, + state.elevation, + gps.hdop); + } + + void write_gps_sat_header() { + for(int i = 1; i <= 32; i++) { + out.printf("sat%02d", i); + if (i != 32) + out.printf(","); + } + } + + void write_gps_sat(AltosRecord record) { + AltosGPS gps = record.gps; + for(int i = 1; i <= 32; i++) { + int c_n0 = 0; + if (gps != null && gps.cc_gps_sat != null) { + for(int j = 0; j < gps.cc_gps_sat.length; j++) + if (gps.cc_gps_sat[j].svid == i) { + c_n0 = gps.cc_gps_sat[j].c_n0; + break; + } + } + out.printf ("%3d", c_n0); + if (i != 32) + out.printf(","); + } + } + + void write_header() { + out.printf("#"); write_general_header(); + out.printf(","); write_flight_header(); + out.printf(","); write_basic_header(); + out.printf(","); write_gps_header(); + out.printf(","); write_gps_sat_header(); + 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(","); + write_gps(record); out.printf(","); + write_gps_sat(record); + out.printf ("\n"); + } + + void flush_pad() { + while (!pad_records.isEmpty()) { + write_one (pad_records.remove()); + } + } + + public void write(AltosRecord record) { + if (!header_written) { + write_header(); + header_written = true; + } + if (!seen_boost) { + if (record.state >= Altos.ao_flight_boost) { + seen_boost = true; + boost_tick = record.tick; + flush_pad(); + } + } + if (seen_boost) + write_one(record); + else + pad_records.add(record); + } + + public PrintStream out() { + return out; + } + + public void close() { + if (!pad_records.isEmpty()) { + boost_tick = pad_records.element().tick; + flush_pad(); + } + out.close(); + } + + public void write(AltosRecordIterable iterable) { + iterable.write_comments(out()); + for (AltosRecord r : iterable) + write(r); + } + + public AltosCSV(File in_name) throws FileNotFoundException { + name = in_name; + out = new PrintStream(name); + pad_records = new LinkedList(); + } + + public AltosCSV(String in_string) throws FileNotFoundException { + this(new File(in_string)); + } +} diff --git a/altosui/AltosCSVUI.java b/altosui/AltosCSVUI.java new file mode 100644 index 00000000..e1b6002d --- /dev/null +++ b/altosui/AltosCSVUI.java @@ -0,0 +1,108 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosCSVUI + extends JDialog + implements ActionListener +{ + JFileChooser csv_chooser; + JPanel accessory; + JComboBox combo_box; + AltosRecordIterable iterable; + AltosWriter writer; + + static String[] combo_box_items = { "Comma Separated Values (.CSV)", "Googleearth Data (.KML)" }; + + void set_default_file() { + File current = csv_chooser.getSelectedFile(); + String current_name = current.getName(); + String new_name = null; + String selected = (String) combo_box.getSelectedItem(); + + if (selected.contains("CSV")) + new_name = Altos.replace_extension(current_name, ".csv"); + else if (selected.contains("KML")) + new_name = Altos.replace_extension(current_name, ".kml"); + if (new_name != null) + csv_chooser.setSelectedFile(new File(new_name)); + } + + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("comboBoxChanged")) + set_default_file(); + } + + public AltosCSVUI(JFrame frame, AltosRecordIterable in_iterable, File source_file) { + iterable = in_iterable; + csv_chooser = new JFileChooser(source_file); + + accessory = new JPanel(); + accessory.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.weightx = 1; + c.weighty = 0; + c.insets = new Insets (4, 4, 4, 4); + + JLabel accessory_label = new JLabel("Export File Type"); + c.gridx = 0; + c.gridy = 0; + accessory.add(accessory_label, c); + + combo_box = new JComboBox(combo_box_items); + combo_box.addActionListener(this); + c.gridx = 0; + c.gridy = 1; + accessory.add(combo_box, c); + + csv_chooser.setAccessory(accessory); + csv_chooser.setSelectedFile(source_file); + set_default_file(); + int ret = csv_chooser.showSaveDialog(frame); + if (ret == JFileChooser.APPROVE_OPTION) { + File file = csv_chooser.getSelectedFile(); + String type = (String) combo_box.getSelectedItem(); + try { + if (type.contains("CSV")) + writer = new AltosCSV(file); + else + writer = new AltosKML(file); + writer.write(iterable); + writer.close(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + file.getName(), + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + } + } +} diff --git a/altosui/AltosChannelMenu.java b/altosui/AltosChannelMenu.java new file mode 100644 index 00000000..abbb86f4 --- /dev/null +++ b/altosui/AltosChannelMenu.java @@ -0,0 +1,44 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosChannelMenu extends JComboBox implements ActionListener { + int channel; + + public AltosChannelMenu(int current_channel) { + + channel = current_channel; + + for (int c = 0; c <= 9; c++) + addItem(String.format("Channel %1d (%7.3fMHz)", c, 434.550 + c * 0.1)); + setSelectedIndex(channel); + setMaximumRowCount(10); + } + +} diff --git a/altosui/AltosConfig.java b/altosui/AltosConfig.java new file mode 100644 index 00000000..1c42870f --- /dev/null +++ b/altosui/AltosConfig.java @@ -0,0 +1,295 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.*; + +import libaltosJNI.*; + +public class AltosConfig implements Runnable, ActionListener { + + class int_ref { + int value; + + public int get() { + return value; + } + public void set(int i) { + value = i; + } + public int_ref(int i) { + value = i; + } + } + + class string_ref { + String value; + + public String get() { + return value; + } + public void set(String i) { + value = i; + } + public string_ref(String i) { + value = i; + } + } + + JFrame owner; + AltosDevice device; + AltosSerial serial_line; + boolean remote; + Thread config_thread; + int_ref serial; + int_ref main_deploy; + int_ref apogee_delay; + int_ref radio_channel; + int_ref radio_calibration; + string_ref version; + string_ref product; + string_ref callsign; + AltosConfigUI config_ui; + boolean serial_started; + + boolean get_int(String line, String label, int_ref x) { + if (line.startsWith(label)) { + try { + String tail = line.substring(label.length()).trim(); + String[] tokens = tail.split("\\s+"); + if (tokens.length > 0) { + int i = Integer.parseInt(tokens[0]); + x.set(i); + return true; + } + } catch (NumberFormatException ne) { + } + } + return false; + } + + boolean get_string(String line, String label, string_ref s) { + if (line.startsWith(label)) { + String quoted = line.substring(label.length()).trim(); + + if (quoted.startsWith("\"")) + quoted = quoted.substring(1); + if (quoted.endsWith("\"")) + quoted = quoted.substring(0,quoted.length()-1); + s.set(quoted); + return true; + } else { + return false; + } + } + + void start_serial() throws InterruptedException { + serial_started = true; + if (remote) { + serial_line.set_radio(); + serial_line.printf("p\nE 0\n"); + serial_line.flush_input(); + } + } + + void stop_serial() throws InterruptedException { + if (!serial_started) + return; + serial_started = false; + if (remote) { + serial_line.printf("~"); + serial_line.flush_output(); + } + } + + void get_data() throws InterruptedException, TimeoutException { + try { + start_serial(); + serial_line.printf("c s\nv\n"); + for (;;) { + String line = serial_line.get_reply(5000); + if (line == null) + throw new TimeoutException(); + get_int(line, "serial-number", serial); + get_int(line, "Main deploy:", main_deploy); + get_int(line, "Apogee delay:", apogee_delay); + get_int(line, "Radio channel:", radio_channel); + get_int(line, "Radio cal:", radio_calibration); + get_string(line, "Callsign:", callsign); + get_string(line,"software-version", version); + get_string(line,"product", product); + + /* signals the end of the version info */ + if (line.startsWith("software-version")) + break; + } + } finally { + stop_serial(); + } + } + + void init_ui () throws InterruptedException, TimeoutException { + config_ui = new AltosConfigUI(owner, remote); + config_ui.addActionListener(this); + set_ui(); + } + + void abort() { + JOptionPane.showMessageDialog(owner, + String.format("Connection to \"%s\" failed", + device.toShortString()), + "Connection Failed", + JOptionPane.ERROR_MESSAGE); + try { + stop_serial(); + } catch (InterruptedException ie) { + } + serial_line.close(); + serial_line = null; + } + + void set_ui() throws InterruptedException, TimeoutException { + if (serial_line != null) + get_data(); + config_ui.set_serial(serial.get()); + config_ui.set_product(product.get()); + config_ui.set_version(version.get()); + config_ui.set_main_deploy(main_deploy.get()); + config_ui.set_apogee_delay(apogee_delay.get()); + config_ui.set_radio_channel(radio_channel.get()); + config_ui.set_radio_calibration(radio_calibration.get()); + config_ui.set_callsign(callsign.get()); + config_ui.set_clean(); + } + + void run_dialog() { + } + + void save_data() { + main_deploy.set(config_ui.main_deploy()); + apogee_delay.set(config_ui.apogee_delay()); + radio_channel.set(config_ui.radio_channel()); + radio_calibration.set(config_ui.radio_calibration()); + callsign.set(config_ui.callsign()); + try { + start_serial(); + serial_line.printf("c m %d\n", main_deploy.get()); + serial_line.printf("c d %d\n", apogee_delay.get()); + if (!remote) { + serial_line.printf("c r %d\n", radio_channel.get()); + serial_line.printf("c f %d\n", radio_calibration.get()); + } + serial_line.printf("c c %s\n", callsign.get()); + serial_line.printf("c w\n"); + } catch (InterruptedException ie) { + } finally { + try { + stop_serial(); + } catch (InterruptedException ie) { + } + } + } + + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + try { + if (cmd.equals("Save")) { + save_data(); + set_ui(); + } else if (cmd.equals("Reset")) { + set_ui(); + } else if (cmd.equals("Reboot")) { + if (serial_line != null) { + start_serial(); + serial_line.printf("r eboot\n"); + serial_line.flush_output(); + stop_serial(); + serial_line.close(); + } + } else if (cmd.equals("Close")) { + if (serial_line != null) + serial_line.close(); + } + } catch (InterruptedException ie) { + abort(); + } catch (TimeoutException te) { + abort(); + } + } + + public void run () { + try { + init_ui(); + config_ui.make_visible(); + } catch (InterruptedException ie) { + abort(); + } catch (TimeoutException te) { + abort(); + } + } + + public AltosConfig(JFrame given_owner) { + owner = given_owner; + + serial = new int_ref(0); + main_deploy = new int_ref(250); + apogee_delay = new int_ref(0); + radio_channel = new int_ref(0); + radio_calibration = new int_ref(1186611); + callsign = new string_ref("N0CALL"); + version = new string_ref("unknown"); + product = new string_ref("unknown"); + + device = AltosDeviceDialog.show(owner, AltosDevice.product_any); + if (device != null) { + try { + serial_line = new AltosSerial(device); + if (!device.matchProduct(AltosDevice.product_telemetrum)) + remote = true; + config_thread = new Thread(this); + config_thread.start(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(owner, + String.format("Cannot open device \"%s\"", + device.toShortString()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(owner, + String.format("Device \"%s\" already in use", + device.toShortString()), + "Device in use", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(owner, + device.toShortString(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } + } + } +} \ No newline at end of file diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java new file mode 100644 index 00000000..cfa5d7b9 --- /dev/null +++ b/altosui/AltosConfigUI.java @@ -0,0 +1,466 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import javax.swing.event.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import libaltosJNI.*; + +public class AltosConfigUI + extends JDialog + implements ActionListener, ItemListener, DocumentListener +{ + + Container pane; + Box box; + JLabel product_label; + JLabel version_label; + JLabel serial_label; + JLabel main_deploy_label; + JLabel apogee_delay_label; + JLabel radio_channel_label; + JLabel radio_calibration_label; + JLabel callsign_label; + + public boolean dirty; + + JFrame owner; + JLabel product_value; + JLabel version_value; + JLabel serial_value; + JComboBox main_deploy_value; + JComboBox apogee_delay_value; + JComboBox radio_channel_value; + JTextField radio_calibration_value; + JTextField callsign_value; + + JButton save; + JButton reset; + JButton reboot; + JButton close; + + ActionListener listener; + + static String[] main_deploy_values = { + "100", "150", "200", "250", "300", "350", + "400", "450", "500" + }; + + static String[] apogee_delay_values = { + "0", "1", "2", "3", "4", "5" + }; + + static String[] radio_channel_values = new String[10]; + { + for (int i = 0; i <= 9; i++) + radio_channel_values[i] = String.format("Channel %1d (%7.3fMHz)", + i, 434.550 + i * 0.1); + } + + /* A window listener to catch closing events and tell the config code */ + class ConfigListener extends WindowAdapter { + AltosConfigUI ui; + + public ConfigListener(AltosConfigUI this_ui) { + ui = this_ui; + } + + public void windowClosing(WindowEvent e) { + ui.actionPerformed(new ActionEvent(e.getSource(), + ActionEvent.ACTION_PERFORMED, + "Close")); + } + } + + /* Build the UI using a grid bag */ + public AltosConfigUI(JFrame in_owner, boolean remote) { + super (in_owner, "Configure TeleMetrum", false); + + owner = in_owner; + GridBagConstraints c; + + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + /* Product */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + product_label = new JLabel("Product:"); + pane.add(product_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 0; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + product_value = new JLabel(""); + pane.add(product_value, c); + + /* Version */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 1; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + version_label = new JLabel("Software version:"); + pane.add(version_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 1; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + version_value = new JLabel(""); + pane.add(version_value, c); + + /* Serial */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 2; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 2; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + serial_value = new JLabel(""); + pane.add(serial_value, c); + + /* Main deploy */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 3; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + main_deploy_label = new JLabel("Main Deploy Altitude(m):"); + pane.add(main_deploy_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 3; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + main_deploy_value = new JComboBox(main_deploy_values); + main_deploy_value.setEditable(true); + main_deploy_value.addItemListener(this); + pane.add(main_deploy_value, c); + + /* Apogee delay */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 4; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + apogee_delay_label = new JLabel("Apogee Delay(s):"); + pane.add(apogee_delay_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 4; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + apogee_delay_value = new JComboBox(apogee_delay_values); + apogee_delay_value.setEditable(true); + apogee_delay_value.addItemListener(this); + pane.add(apogee_delay_value, c); + + /* Radio channel */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 5; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_channel_label = new JLabel("Radio Channel:"); + pane.add(radio_channel_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 5; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_channel_value = new JComboBox(radio_channel_values); + radio_channel_value.setEditable(false); + radio_channel_value.addItemListener(this); + if (remote) + radio_channel_value.setEnabled(false); + pane.add(radio_channel_value, c); + + /* Radio Calibration */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 6; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_calibration_label = new JLabel("RF Calibration:"); + pane.add(radio_calibration_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 6; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_calibration_value = new JTextField(String.format("%d", 1186611)); + radio_calibration_value.getDocument().addDocumentListener(this); + if (remote) + radio_calibration_value.setEnabled(false); + pane.add(radio_calibration_value, c); + + /* Callsign */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 7; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + callsign_label = new JLabel("Callsign:"); + pane.add(callsign_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 7; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + callsign_value = new JTextField(AltosPreferences.callsign()); + callsign_value.getDocument().addDocumentListener(this); + pane.add(callsign_value, c); + + /* Buttons */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 8; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + save = new JButton("Save"); + pane.add(save, c); + save.addActionListener(this); + save.setActionCommand("Save"); + + c = new GridBagConstraints(); + c.gridx = 2; c.gridy = 8; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + reset = new JButton("Reset"); + pane.add(reset, c); + reset.addActionListener(this); + reset.setActionCommand("Reset"); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = 8; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + reboot = new JButton("Reboot"); + pane.add(reboot, c); + reboot.addActionListener(this); + reboot.setActionCommand("Reboot"); + + c = new GridBagConstraints(); + c.gridx = 6; c.gridy = 8; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_END; + c.insets = il; + close = new JButton("Close"); + pane.add(close, c); + close.addActionListener(this); + close.setActionCommand("Close"); + + addWindowListener(new ConfigListener(this)); + } + + /* Once the initial values are set, the config code will show the dialog */ + public void make_visible() { + pack(); + setLocationRelativeTo(owner); + setVisible(true); + } + + /* If any values have been changed, confirm before closing */ + public boolean check_dirty(String operation) { + if (dirty) { + Object[] options = { String.format("%s anyway", operation), "Keep editing" }; + int i; + i = JOptionPane.showOptionDialog(this, + String.format("Configuration modified. %s anyway?", operation), + "Configuration Modified", + JOptionPane.DEFAULT_OPTION, + JOptionPane.WARNING_MESSAGE, + null, options, options[1]); + if (i != 0) + return false; + } + return true; + } + + /* Listen for events from our buttons */ + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + + if (cmd.equals("Close") || cmd.equals("Reboot")) + if (!check_dirty(cmd)) + return; + listener.actionPerformed(e); + if (cmd.equals("Close") || cmd.equals("Reboot")) { + setVisible(false); + dispose(); + } + dirty = false; + } + + /* ItemListener interface method */ + public void itemStateChanged(ItemEvent e) { + dirty = true; + } + + /* DocumentListener interface methods */ + public void changedUpdate(DocumentEvent e) { + dirty = true; + } + + public void insertUpdate(DocumentEvent e) { + dirty = true; + } + + public void removeUpdate(DocumentEvent e) { + dirty = true; + } + + /* Let the config code hook on a listener */ + public void addActionListener(ActionListener l) { + listener = l; + } + + /* set and get all of the dialog values */ + public void set_product(String product) { + product_value.setText(product); + } + + public void set_version(String version) { + version_value.setText(version); + } + + public void set_serial(int serial) { + serial_value.setText(String.format("%d", serial)); + } + + public void set_main_deploy(int new_main_deploy) { + main_deploy_value.setSelectedItem(Integer.toString(new_main_deploy)); + } + + public int main_deploy() { + return Integer.parseInt(main_deploy_value.getSelectedItem().toString()); + } + + public void set_apogee_delay(int new_apogee_delay) { + apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay)); + } + + public int apogee_delay() { + return Integer.parseInt(apogee_delay_value.getSelectedItem().toString()); + } + + public void set_radio_channel(int new_radio_channel) { + radio_channel_value.setSelectedIndex(new_radio_channel); + } + + public int radio_channel() { + return radio_channel_value.getSelectedIndex(); + } + + public void set_radio_calibration(int new_radio_calibration) { + radio_calibration_value.setText(String.format("%d", new_radio_calibration)); + } + + public int radio_calibration() { + return Integer.parseInt(radio_calibration_value.getText()); + } + + public void set_callsign(String new_callsign) { + callsign_value.setText(new_callsign); + } + + public String callsign() { + return callsign_value.getText(); + } + + public void set_clean() { + dirty = false; + } + + } \ No newline at end of file diff --git a/altosui/AltosConfigureUI.java b/altosui/AltosConfigureUI.java new file mode 100644 index 00000000..153c59fd --- /dev/null +++ b/altosui/AltosConfigureUI.java @@ -0,0 +1,187 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import javax.swing.event.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosConfigureUI + extends JDialog + implements DocumentListener +{ + JFrame owner; + AltosVoice voice; + Container pane; + + JRadioButton enable_voice; + JButton test_voice; + JButton close; + + JButton configure_log; + JTextField log_directory; + + JLabel callsign_label; + JTextField callsign_value; + + /* DocumentListener interface methods */ + public void changedUpdate(DocumentEvent e) { + AltosPreferences.set_callsign(callsign_value.getText()); + } + + public void insertUpdate(DocumentEvent e) { + changedUpdate(e); + } + + public void removeUpdate(DocumentEvent e) { + changedUpdate(e); + } + + public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) { + super(in_owner, "Configure AltosUI", false); + + GridBagConstraints c; + + Insets insets = new Insets(4, 4, 4, 4); + + owner = in_owner; + voice = in_voice; + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + c = new GridBagConstraints(); + c.insets = insets; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + + /* Nice label at the top */ + c.gridx = 0; + c.gridy = 0; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + pane.add(new JLabel ("Configure AltOS UI"), c); + + /* Voice settings */ + c.gridx = 0; + c.gridy = 1; + c.gridwidth = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + pane.add(new JLabel("Voice"), c); + + enable_voice = new JRadioButton("Enable", AltosPreferences.voice()); + enable_voice.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JRadioButton item = (JRadioButton) e.getSource(); + boolean enabled = item.isSelected(); + AltosPreferences.set_voice(enabled); + if (enabled) + voice.speak_always("Enable voice."); + else + voice.speak_always("Disable voice."); + } + }); + c.gridx = 1; + c.gridy = 1; + c.gridwidth = 1; + c.weightx = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + pane.add(enable_voice, c); + + c.gridx = 2; + c.gridy = 1; + c.gridwidth = 1; + c.weightx = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.EAST; + test_voice = new JButton("Test Voice"); + test_voice.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + voice.speak("That's one small step for man; one giant leap for mankind."); + } + }); + pane.add(test_voice, c); + + /* Log directory settings */ + c.gridx = 0; + c.gridy = 2; + c.gridwidth = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + pane.add(new JLabel("Log Directory"), c); + + configure_log = new JButton(AltosPreferences.logdir().getPath()); + configure_log.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + AltosPreferences.ConfigureLog(); + configure_log.setText(AltosPreferences.logdir().getPath()); + } + }); + c.gridx = 1; + c.gridy = 2; + c.gridwidth = 2; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.WEST; + pane.add(configure_log, c); + + /* Callsign setting */ + c.gridx = 0; + c.gridy = 3; + c.gridwidth = 1; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + pane.add(new JLabel("Callsign"), c); + + callsign_value = new JTextField(AltosPreferences.callsign()); + callsign_value.getDocument().addDocumentListener(this); + c.gridx = 1; + c.gridy = 3; + c.gridwidth = 2; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.WEST; + pane.add(callsign_value, c); + + /* And a close button at the bottom */ + close = new JButton("Close"); + close.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + setVisible(false); + } + }); + c.gridx = 0; + c.gridy = 4; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + pane.add(close, c); + + pack(); + setLocationRelativeTo(owner); + setVisible(true); + } +} diff --git a/altosui/AltosConvert.java b/altosui/AltosConvert.java new file mode 100644 index 00000000..8cc1df27 --- /dev/null +++ b/altosui/AltosConvert.java @@ -0,0 +1,192 @@ +/* + * Copyright © 2010 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. + */ + +/* + * Sensor data conversion functions + */ +package altosui; + +public class AltosConvert { + /* + * Pressure Sensor Model, version 1.1 + * + * written by Holly Grimes + * + * Uses the International Standard Atmosphere as described in + * "A Quick Derivation relating altitude to air pressure" (version 1.03) + * from the Portland State Aerospace Society, except that the atmosphere + * is divided into layers with each layer having a different lapse rate. + * + * Lapse rate data for each layer was obtained from Wikipedia on Sept. 1, 2007 + * at site MAXIMUM_ALTITUDE) /* FIX ME: use sensor data to improve model */ + return 0; + + /* calculate the base temperature and pressure for the atmospheric layer + associated with the inputted altitude */ + for(layer_number = 0; layer_number < NUMBER_OF_LAYERS - 1 && altitude > base_altitude[layer_number + 1]; layer_number++) { + delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number]; + if (lapse_rate[layer_number] == 0.0) { + exponent = GRAVITATIONAL_ACCELERATION * delta_z + / AIR_GAS_CONSTANT / base_temperature; + base_pressure *= Math.exp(exponent); + } + else { + base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; + exponent = GRAVITATIONAL_ACCELERATION / + (AIR_GAS_CONSTANT * lapse_rate[layer_number]); + base_pressure *= Math.pow(base, exponent); + } + base_temperature += delta_z * lapse_rate[layer_number]; + } + + /* calculate the pressure at the inputted altitude */ + delta_z = altitude - base_altitude[layer_number]; + if (lapse_rate[layer_number] == 0.0) { + exponent = GRAVITATIONAL_ACCELERATION * delta_z + / AIR_GAS_CONSTANT / base_temperature; + pressure = base_pressure * Math.exp(exponent); + } + else { + base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; + exponent = GRAVITATIONAL_ACCELERATION / + (AIR_GAS_CONSTANT * lapse_rate[layer_number]); + pressure = base_pressure * Math.pow(base, exponent); + } + + return pressure; + } + + +/* outputs the altitude associated with the given pressure. the altitude + returned is measured with respect to the mean sea level */ + static double + pressure_to_altitude(double pressure) + { + + double next_base_temperature = LAYER0_BASE_TEMPERATURE; + double next_base_pressure = LAYER0_BASE_PRESSURE; + + double altitude; + double base_pressure; + double base_temperature; + double base; /* base for function to determine base pressure of next layer */ + double exponent; /* exponent for function to determine base pressure + of next layer */ + double coefficient; + int layer_number; /* identifies layer in the atmosphere */ + int delta_z; /* difference between two altitudes */ + + if (pressure < 0) /* illegal pressure */ + return -1; + if (pressure < MINIMUM_PRESSURE) /* FIX ME: use sensor data to improve model */ + return MAXIMUM_ALTITUDE; + + /* calculate the base temperature and pressure for the atmospheric layer + associated with the inputted pressure. */ + layer_number = -1; + do { + layer_number++; + base_pressure = next_base_pressure; + base_temperature = next_base_temperature; + delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number]; + if (lapse_rate[layer_number] == 0.0) { + exponent = GRAVITATIONAL_ACCELERATION * delta_z + / AIR_GAS_CONSTANT / base_temperature; + next_base_pressure *= Math.exp(exponent); + } + else { + base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; + exponent = GRAVITATIONAL_ACCELERATION / + (AIR_GAS_CONSTANT * lapse_rate[layer_number]); + next_base_pressure *= Math.pow(base, exponent); + } + next_base_temperature += delta_z * lapse_rate[layer_number]; + } + while(layer_number < NUMBER_OF_LAYERS - 1 && pressure < next_base_pressure); + + /* calculate the altitude associated with the inputted pressure */ + if (lapse_rate[layer_number] == 0.0) { + coefficient = (AIR_GAS_CONSTANT / GRAVITATIONAL_ACCELERATION) + * base_temperature; + altitude = base_altitude[layer_number] + + coefficient * Math.log(pressure / base_pressure); + } + else { + base = pressure / base_pressure; + exponent = AIR_GAS_CONSTANT * lapse_rate[layer_number] + / GRAVITATIONAL_ACCELERATION; + coefficient = base_temperature / lapse_rate[layer_number]; + altitude = base_altitude[layer_number] + + coefficient * (Math.pow(base, exponent) - 1); + } + + return altitude; + } + + static double + cc_battery_to_voltage(double battery) + { + return battery / 32767.0 * 5.0; + } + + static double + cc_ignitor_to_voltage(double ignite) + { + return ignite / 32767 * 15.0; + } +} diff --git a/altosui/AltosDataChooser.java b/altosui/AltosDataChooser.java new file mode 100644 index 00000000..15de05c2 --- /dev/null +++ b/altosui/AltosDataChooser.java @@ -0,0 +1,79 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; + +public class AltosDataChooser extends JFileChooser { + JFrame frame; + String filename; + File file; + + public String filename() { + return filename; + } + + public File file() { + return file; + } + + public AltosRecordIterable runDialog() { + int ret; + + ret = showOpenDialog(frame); + if (ret == APPROVE_OPTION) { + file = getSelectedFile(); + if (file == null) + return null; + filename = file.getName(); + try { + if (filename.endsWith("eeprom")) { + FileInputStream in = new FileInputStream(file); + return new AltosEepromIterable(in); + } else if (filename.endsWith("telem")) { + FileInputStream in = new FileInputStream(file); + return new AltosTelemetryIterable(in); + } else { + throw new FileNotFoundException(); + } + } catch (FileNotFoundException fe) { + JOptionPane.showMessageDialog(frame, + filename, + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + } + return null; + } + + public AltosDataChooser(JFrame in_frame) { + frame = in_frame; + setDialogTitle("Select Flight Record File"); + setFileFilter(new FileNameExtensionFilter("Flight data file", + "telem", "eeprom")); + setCurrentDirectory(AltosPreferences.logdir()); + } +} diff --git a/altosui/AltosDataPoint.java b/altosui/AltosDataPoint.java new file mode 100644 index 00000000..66313e03 --- /dev/null +++ b/altosui/AltosDataPoint.java @@ -0,0 +1,29 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +interface AltosDataPoint { + int version(); + int serial(); + int flight(); + String callsign(); + double time(); + double rssi(); + + int state(); + String state_name(); + + double acceleration(); + double pressure(); + double altitude(); + double height(); + double accel_speed(); + double baro_speed(); + double temperature(); + double battery_voltage(); + double drogue_voltage(); + double main_voltage(); +} + diff --git a/altosui/AltosDataPointReader.java b/altosui/AltosDataPointReader.java new file mode 100644 index 00000000..7704310b --- /dev/null +++ b/altosui/AltosDataPointReader.java @@ -0,0 +1,72 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.io.IOException; +import java.text.ParseException; +import java.lang.UnsupportedOperationException; +import java.util.NoSuchElementException; +import java.util.Iterator; + +class AltosDataPointReader implements Iterable { + Iterator iter; + AltosState state; + AltosRecord record; + + public AltosDataPointReader(Iterable reader) { + this.iter = reader.iterator(); + this.state = null; + } + + private void read_next_record() + throws NoSuchElementException + { + record = iter.next(); + state = new AltosState(record, state); + } + + private AltosDataPoint current_dp() { + assert this.record != null; + + return new AltosDataPoint() { + public int version() { return record.version; } + public int serial() { return record.serial; } + public int flight() { return record.flight; } + public String callsign() { return record.callsign; } + public double time() { return record.time; } + public double rssi() { return record.rssi; } + + public int state() { return record.state; } + public String state_name() { return record.state(); } + + public double acceleration() { return record.acceleration(); } + public double pressure() { return record.raw_pressure(); } + public double altitude() { return record.raw_altitude(); } + public double height() { return record.raw_height(); } + public double accel_speed() { return record.accel_speed(); } + public double baro_speed() { return state.baro_speed; } + public double temperature() { return record.temperature(); } + public double battery_voltage() { return record.battery_voltage(); } + public double drogue_voltage() { return record.drogue_voltage(); } + public double main_voltage() { return record.main_voltage(); } + }; + } + + public Iterator iterator() { + return new Iterator() { + public void remove() { + throw new UnsupportedOperationException(); + } + public boolean hasNext() { + return iter.hasNext(); + } + public AltosDataPoint next() { + read_next_record(); + return current_dp(); + } + }; + } +} + diff --git a/altosui/AltosDebug.java b/altosui/AltosDebug.java new file mode 100644 index 00000000..8d435b66 --- /dev/null +++ b/altosui/AltosDebug.java @@ -0,0 +1,267 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.util.concurrent.*; +import java.util.*; + +import libaltosJNI.*; + +public class AltosDebug extends AltosSerial { + + public static final byte WR_CONFIG = 0x1d; + public static final byte RD_CONFIG = 0x24; + public static final byte CONFIG_TIMERS_OFF = (1 << 3); + public static final byte CONFIG_DMA_PAUSE = (1 << 2); + public static final byte CONFIG_TIMER_SUSPEND = (1 << 1); + public static final byte SET_FLASH_INFO_PAGE = (1 << 0); + + public static final byte GET_PC = 0x28; + public static final byte READ_STATUS = 0x34; + public static final byte STATUS_CHIP_ERASE_DONE = (byte) (1 << 7); + public static final byte STATUS_PCON_IDLE = (1 << 6); + public static final byte STATUS_CPU_HALTED = (1 << 5); + public static final byte STATUS_POWER_MODE_0 = (1 << 4); + public static final byte STATUS_HALT_STATUS = (1 << 3); + public static final byte STATUS_DEBUG_LOCKED = (1 << 2); + public static final byte STATUS_OSCILLATOR_STABLE = (1 << 1); + public static final byte STATUS_STACK_OVERFLOW = (1 << 0); + + public static final byte SET_HW_BRKPNT = 0x3b; + public static byte HW_BRKPNT_N(byte n) { return (byte) ((n) << 3); } + public static final byte HW_BRKPNT_N_MASK = (0x3 << 3); + public static final byte HW_BRKPNT_ENABLE = (1 << 2); + + public static final byte HALT = 0x44; + public static final byte RESUME = 0x4c; + public static byte DEBUG_INSTR(byte n) { return (byte) (0x54|(n)); } + public static final byte STEP_INSTR = 0x5c; + public static byte STEP_REPLACE(byte n) { return (byte) (0x64|(n)); } + public static final byte GET_CHIP_ID = 0x68; + + + boolean debug_mode; + + void ensure_debug_mode() { + if (!debug_mode) { + printf("D\n"); + flush_input(); + debug_mode = true; + } + } + + void dump_memory(String header, int address, byte[] bytes, int start, int len) { + System.out.printf("%s\n", header); + for (int j = 0; j < len; j++) { + if ((j & 15) == 0) { + if (j != 0) + System.out.printf("\n"); + System.out.printf ("%04x:", address + j); + } + System.out.printf(" %02x", bytes[start + j]); + } + System.out.printf("\n"); + } + + /* + * Write target memory + */ + public void write_memory(int address, byte[] bytes, int start, int len) { + ensure_debug_mode(); +// dump_memory("write_memory", address, bytes, start, len); + printf("O %x %x\n", len, address); + for (int i = 0; i < len; i++) + printf("%02x", bytes[start + i]); + } + + public void write_memory(int address, byte[] bytes) { + write_memory(address, bytes, 0, bytes.length); + } + + /* + * Read target memory + */ + public byte[] read_memory(int address, int length) + throws IOException, InterruptedException { + byte[] data = new byte[length]; + + flush_input(); + ensure_debug_mode(); + printf("I %x %x\n", length, address); + int i = 0; + int start = 0; + while (i < length) { + String line = get_reply().trim(); + if (!Altos.ishex(line) || line.length() % 2 != 0) + throw new IOException( + String.format + ("Invalid reply \"%s\"", line)); + int this_time = line.length() / 2; + for (int j = 0; j < this_time; j++) + data[start + j] = (byte) ((Altos.fromhex(line.charAt(j*2)) << 4) + + Altos.fromhex(line.charAt(j*2+1))); + start += this_time; + i += this_time; + } +// dump_memory("read_memory", address, data, 0, length); + + return data; + } + + /* + * Write raw bytes to the debug link using the 'P' command + */ + public void write_bytes(byte[] bytes) throws IOException { + int i = 0; + ensure_debug_mode(); + while (i < bytes.length) { + int this_time = bytes.length - i; + if (this_time > 8) + this_time = 0; + printf("P"); + for (int j = 0; j < this_time; j++) + printf(" %02x", bytes[i+j]); + printf("\n"); + i += this_time; + } + } + + public void write_byte(byte b) throws IOException { + byte[] bytes = { b }; + write_bytes(bytes); + } + + /* + * Read raw bytes from the debug link using the 'G' command + */ + public byte[] read_bytes(int length) + throws IOException, InterruptedException { + + flush_input(); + ensure_debug_mode(); + printf("G %x\n", length); + int i = 0; + byte[] data = new byte[length]; + while (i < length) { + String line = get_reply().trim(); + String tokens[] = line.split("\\s+"); + for (int j = 0; j < tokens.length; j++) { + if (!Altos.ishex(tokens[j]) || + tokens[j].length() != 2) + throw new IOException( + String.format + ("Invalid read_bytes reply \"%s\"", line)); + try { + data[i + j] = (byte) Integer.parseInt(tokens[j], 16); + } catch (NumberFormatException ne) { + throw new IOException( + String.format + ("Invalid read_bytes reply \"%s\"", line)); + } + } + i += tokens.length; + } + return data; + } + + public byte read_byte() throws IOException, InterruptedException { + return read_bytes(1)[0]; + } + + public byte debug_instr(byte[] instruction) throws IOException, InterruptedException { + byte[] command = new byte[1 + instruction.length]; + command[0] = DEBUG_INSTR((byte) instruction.length); + for (int i = 0; i < instruction.length; i++) + command[i+1] = instruction[i]; + write_bytes(command); + return read_byte(); + } + + public byte resume() throws IOException, InterruptedException { + write_byte(RESUME); + return read_byte(); + } + + public int read_uint16() throws IOException, InterruptedException { + byte[] d = read_bytes(2); + return ((int) (d[0] & 0xff) << 8) | (d[1] & 0xff); + } + + public int read_uint8() throws IOException, InterruptedException { + byte[] d = read_bytes(1); + return (int) (d[0] & 0xff); + } + + public int get_chip_id() throws IOException, InterruptedException { + write_byte(GET_CHIP_ID); + return read_uint16(); + } + + public int get_pc() throws IOException, InterruptedException { + write_byte(GET_PC); + return read_uint16(); + } + + public byte read_status() throws IOException, InterruptedException { + write_byte(READ_STATUS); + return read_byte(); + } + + static final byte LJMP = 0x02; + + public void set_pc(int pc) throws IOException, InterruptedException { + byte high = (byte) (pc >> 8); + byte low = (byte) pc; + byte[] jump_mem = { LJMP, high, low }; + debug_instr(jump_mem); + } + + public boolean check_connection() throws IOException, InterruptedException { + byte reply = read_status(); + if ((reply & STATUS_CHIP_ERASE_DONE) == 0) + return false; + if ((reply & STATUS_PCON_IDLE) != 0) + return false; + if ((reply & STATUS_POWER_MODE_0) == 0) + return false; + return true; + } + + public AltosRomconfig romconfig() { + try { + byte[] bytes = read_memory(0xa0, 10); + return new AltosRomconfig(bytes, 0); + } catch (IOException ie) { + } catch (InterruptedException ie) { + } + return new AltosRomconfig(); + } + + /* + * Reset target + */ + public void reset() { + printf ("R\n"); + } + + public AltosDebug (AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { + super(in_device); + } +} \ No newline at end of file diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java new file mode 100644 index 00000000..16ccd458 --- /dev/null +++ b/altosui/AltosDescent.java @@ -0,0 +1,353 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosDescent extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + + public abstract class DescentStatus { + JLabel label; + JTextField value; + AltosLights lights; + + abstract void show(AltosState state, int crc_errors); + void reset() { + value.setText(""); + lights.set(false); + } + + public DescentStatus (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + lights = new AltosLights(); + c.gridx = 0; c.gridy = y; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(lights, c); + add(lights); + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.gridwidth = 3; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(Altos.text_width); + value.setFont(Altos.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 4; c.gridy = y; + c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + + } + } + + public abstract class DescentValue { + JLabel label; + JTextField value; + + void reset() { + value.setText(""); + } + + abstract void show(AltosState state, int crc_errors); + + void show(String format, double v) { + value.setText(String.format(format, v)); + } + + void show(String v) { + value.setText(v); + } + + public DescentValue (GridBagLayout layout, int x, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = x + 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + add(label, c); + + value = new JTextField(Altos.text_width); + value.setFont(Altos.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = x + 2; c.gridy = y; + c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + add(value, c); + } + } + + public abstract class DescentDualValue { + JLabel label; + JTextField value1; + JTextField value2; + + void reset() { + value1.setText(""); + value2.setText(""); + } + + abstract void show(AltosState state, int crc_errors); + void show(String v1, String v2) { + value1.setText(v1); + value2.setText(v2); + } + void show(String f1, double v1, String f2, double v2) { + value1.setText(String.format(f1, v1)); + value2.setText(String.format(f2, v2)); + } + + public DescentDualValue (GridBagLayout layout, int x, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = x + 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value1 = new JTextField(Altos.text_width); + value1.setFont(Altos.value_font); + value1.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = x + 2; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value1, c); + add(value1); + + value2 = new JTextField(Altos.text_width); + value2.setFont(Altos.value_font); + value2.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = x + 4; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + c.gridwidth = 1; + layout.setConstraints(value2, c); + add(value2); + } + } + + class Height extends DescentValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m", state.height); + } + public Height (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Height"); + } + } + + Height height; + + class Speed extends DescentValue { + void show (AltosState state, int crc_errors) { + double speed = state.speed; + if (!state.ascent) + speed = state.baro_speed; + show("%6.0f m/s", speed); + } + public Speed (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Speed"); + } + } + + Speed speed; + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %d° %9.6f", h, deg, min); + } + + class Lat extends DescentValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + show(pos(state.gps.lat,"N", "S")); + else + show("???"); + } + public Lat (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Latitude"); + } + } + + Lat lat; + + class Lon extends DescentValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + show(pos(state.gps.lon,"W", "E")); + else + show("???"); + } + public Lon (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Longitude"); + } + } + + Lon lon; + + class Apogee extends DescentStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.drogue_sense)); + lights.set(state.drogue_sense > 3.2); + } + public Apogee (GridBagLayout layout, int y) { + super(layout, y, "Apogee Igniter Voltage"); + } + } + + Apogee apogee; + + class Main extends DescentStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.main_sense)); + lights.set(state.main_sense > 3.2); + } + public Main (GridBagLayout layout, int y) { + super(layout, y, "Main Igniter Voltage"); + } + } + + Main main; + + class Bearing extends DescentDualValue { + void show (AltosState state, int crc_errors) { + if (state.from_pad != null) { + show( String.format("%3.0f°", state.from_pad.bearing), + state.from_pad.bearing_words( + AltosGreatCircle.BEARING_LONG)); + } else { + show("???", "???"); + } + } + public Bearing (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Bearing"); + } + } + + Bearing bearing; + + class Range extends DescentValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m", state.range); + } + public Range (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Range"); + } + } + + Range range; + + class Elevation extends DescentValue { + void show (AltosState state, int crc_errors) { + show("%3.0f°", state.elevation); + } + public Elevation (GridBagLayout layout, int x, int y) { + super (layout, x, y, "Elevation"); + } + } + + Elevation elevation; + + public void reset() { + lat.reset(); + lon.reset(); + height.reset(); + speed.reset(); + bearing.reset(); + range.reset(); + elevation.reset(); + main.reset(); + apogee.reset(); + } + + public void show(AltosState state, int crc_errors) { + height.show(state, crc_errors); + speed.show(state, crc_errors); + bearing.show(state, crc_errors); + range.show(state, crc_errors); + elevation.show(state, crc_errors); + lat.show(state, crc_errors); + lon.show(state, crc_errors); + main.show(state, crc_errors); + apogee.show(state, crc_errors); + } + + public AltosDescent() { + layout = new GridBagLayout(); + + setLayout(layout); + + /* Elements in descent display */ + speed = new Speed(layout, 0, 0); + height = new Height(layout, 2, 0); + elevation = new Elevation(layout, 0, 1); + range = new Range(layout, 2, 1); + bearing = new Bearing(layout, 0, 2); + lat = new Lat(layout, 0, 3); + lon = new Lon(layout, 2, 3); + + apogee = new Apogee(layout, 4); + main = new Main(layout, 5); + } +} diff --git a/altosui/AltosDevice.java b/altosui/AltosDevice.java new file mode 100644 index 00000000..f0fda57b --- /dev/null +++ b/altosui/AltosDevice.java @@ -0,0 +1,170 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; +import java.lang.*; +import java.util.*; +import libaltosJNI.*; + +public class AltosDevice extends altos_device { + + static public boolean initialized = false; + static public boolean loaded_library = false; + + public static boolean load_library() { + if (!initialized) { + try { + System.loadLibrary("altos"); + libaltos.altos_init(); + loaded_library = true; + } catch (UnsatisfiedLinkError e) { + loaded_library = false; + } + initialized = true; + } + return loaded_library; + } + + static int usb_vendor_altusmetrum() { + if (load_library()) + return libaltosConstants.USB_VENDOR_ALTUSMETRUM; + return 0x000a; + } + + static int usb_product_altusmetrum() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_ALTUSMETRUM; + return 0x000a; + } + + static int usb_product_altusmetrum_min() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MIN; + return 0x000a; + } + + static int usb_product_altusmetrum_max() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MAX; + return 0x000d; + } + + static int usb_product_telemetrum() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_TELEMETRUM; + return 0x000b; + } + + static int usb_product_teledongle() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_TELEDONGLE; + return 0x000c; + } + + static int usb_product_teleterra() { + if (load_library()) + return libaltosConstants.USB_PRODUCT_TELETERRA; + return 0x000d; + } + + public final static int vendor_altusmetrum = usb_vendor_altusmetrum(); + public final static int product_altusmetrum = usb_product_altusmetrum(); + public final static int product_telemetrum = usb_product_telemetrum(); + public final static int product_teledongle = usb_product_teledongle(); + public final static int product_teleterra = usb_product_teleterra(); + public final static int product_altusmetrum_min = usb_product_altusmetrum_min(); + public final static int product_altusmetrum_max = usb_product_altusmetrum_max(); + + + public final static int product_any = 0x10000; + public final static int product_basestation = 0x10000 + 1; + + public String toString() { + String name = getName(); + if (name == null) + name = "Altus Metrum"; + return String.format("%-20.20s %4d %s", + getName(), getSerial(), getPath()); + } + + public String toShortString() { + String name = getName(); + if (name == null) + name = "Altus Metrum"; + return String.format("%s %d %s", + name, getSerial(), getPath()); + + } + + public boolean isAltusMetrum() { + if (getVendor() != vendor_altusmetrum) + return false; + if (getProduct() < product_altusmetrum_min) + return false; + if (getProduct() > product_altusmetrum_max) + return false; + return true; + } + + public boolean matchProduct(int want_product) { + + if (!isAltusMetrum()) + return false; + + if (want_product == product_any) + return true; + + if (want_product == product_basestation) + return matchProduct(product_teledongle) || matchProduct(product_teleterra); + + int have_product = getProduct(); + + if (have_product == product_altusmetrum) /* old devices match any request */ + return true; + + if (want_product == have_product) + return true; + + return false; + } + + static AltosDevice[] list(int product) { + if (!load_library()) + return null; + + SWIGTYPE_p_altos_list list = libaltos.altos_list_start(); + + ArrayList device_list = new ArrayList(); + if (list != null) { + SWIGTYPE_p_altos_file file; + + for (;;) { + AltosDevice device = new AltosDevice(); + if (libaltos.altos_list_next(list, device) == 0) + break; + if (device.matchProduct(product)) + device_list.add(device); + } + libaltos.altos_list_finish(list); + } + + AltosDevice[] devices = new AltosDevice[device_list.size()]; + for (int i = 0; i < device_list.size(); i++) + devices[i] = device_list.get(i); + return devices; + } +} \ No newline at end of file diff --git a/altosui/AltosDeviceDialog.java b/altosui/AltosDeviceDialog.java new file mode 100644 index 00000000..2966ad1e --- /dev/null +++ b/altosui/AltosDeviceDialog.java @@ -0,0 +1,164 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import libaltosJNI.libaltos; +import libaltosJNI.altos_device; +import libaltosJNI.SWIGTYPE_p_altos_file; +import libaltosJNI.SWIGTYPE_p_altos_list; + +public class AltosDeviceDialog extends JDialog implements ActionListener { + + private static AltosDeviceDialog dialog; + private static AltosDevice value = null; + private JList list; + + public static AltosDevice show (Component frameComp, int product) { + + Frame frame = JOptionPane.getFrameForComponent(frameComp); + AltosDevice[] devices; + devices = AltosDevice.list(product); + + if (devices != null && devices.length > 0) { + value = null; + dialog = new AltosDeviceDialog(frame, frameComp, + devices, + devices[0]); + + dialog.setVisible(true); + return value; + } else { + /* check for missing altos JNI library, which + * will put up its own error dialog + */ + if (AltosUI.load_library(frame)) { + JOptionPane.showMessageDialog(frame, + "No AltOS devices available", + "No AltOS devices", + JOptionPane.ERROR_MESSAGE); + } + return null; + } + } + + private AltosDeviceDialog (Frame frame, Component location, + AltosDevice[] devices, + AltosDevice initial) { + super(frame, "Device Selection", true); + + value = null; + + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(this); + + final JButton selectButton = new JButton("Select"); + selectButton.setActionCommand("select"); + selectButton.addActionListener(this); + getRootPane().setDefaultButton(selectButton); + + list = new JList(devices) { + //Subclass JList to workaround bug 4832765, which can cause the + //scroll pane to not let the user easily scroll up to the beginning + //of the list. An alternative would be to set the unitIncrement + //of the JScrollBar to a fixed value. You wouldn't get the nice + //aligned scrolling, but it should work. + public int getScrollableUnitIncrement(Rectangle visibleRect, + int orientation, + int direction) { + int row; + if (orientation == SwingConstants.VERTICAL && + direction < 0 && (row = getFirstVisibleIndex()) != -1) { + Rectangle r = getCellBounds(row, row); + if ((r.y == visibleRect.y) && (row != 0)) { + Point loc = r.getLocation(); + loc.y--; + int prevIndex = locationToIndex(loc); + Rectangle prevR = getCellBounds(prevIndex, prevIndex); + + if (prevR == null || prevR.y >= r.y) { + return 0; + } + return prevR.height; + } + } + return super.getScrollableUnitIncrement( + visibleRect, orientation, direction); + } + }; + + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.setLayoutOrientation(JList.HORIZONTAL_WRAP); + list.setVisibleRowCount(-1); + list.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + selectButton.doClick(); //emulate button click + } + } + }); + JScrollPane listScroller = new JScrollPane(list); + listScroller.setPreferredSize(new Dimension(400, 80)); + listScroller.setAlignmentX(LEFT_ALIGNMENT); + + //Create a container so that we can add a title around + //the scroll pane. Can't add a title directly to the + //scroll pane because its background would be white. + //Lay out the label and scroll pane from top to bottom. + JPanel listPane = new JPanel(); + listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); + + JLabel label = new JLabel("Select Device"); + label.setLabelFor(list); + listPane.add(label); + listPane.add(Box.createRigidArea(new Dimension(0,5))); + listPane.add(listScroller); + listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); + + //Lay out the buttons from left to right. + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.add(cancelButton); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + buttonPane.add(selectButton); + + //Put everything together, using the content pane's BorderLayout. + Container contentPane = getContentPane(); + contentPane.add(listPane, BorderLayout.CENTER); + contentPane.add(buttonPane, BorderLayout.PAGE_END); + + //Initialize values. + list.setSelectedValue(initial, true); + pack(); + setLocationRelativeTo(location); + } + + //Handle clicks on the Set and Cancel buttons. + public void actionPerformed(ActionEvent e) { + if ("select".equals(e.getActionCommand())) + AltosDeviceDialog.value = (AltosDevice)(list.getSelectedValue()); + AltosDeviceDialog.dialog.setVisible(false); + } + +} diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java new file mode 100644 index 00000000..3e719130 --- /dev/null +++ b/altosui/AltosDisplayThread.java @@ -0,0 +1,249 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosDisplayThread extends Thread { + + Frame parent; + IdleThread idle_thread; + AltosVoice voice; + String name; + AltosFlightReader reader; + int crc_errors; + AltosFlightDisplay display; + + synchronized void show(AltosState state, int crc_errors) { + if (state != null) + display.show(state, crc_errors); + } + + 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 < Altos.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 (Altos.ao_flight_drogue <= state.state && + state.state < Altos.ao_flight_landed && + state.range >= 0) + { + voice.speak("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 > Altos.ao_flight_pad) { + voice.speak("%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 >= Altos.ao_flight_drogue && + (last || + System.currentTimeMillis() - state.report_time >= 15000 || + state.state == Altos.ao_flight_landed)) + { + if (Math.abs(state.baro_speed) < 20 && state.height < 100) + voice.speak("rocket landed safely"); + else + voice.speak("rocket may have crashed"); + if (state.from_pad != null) + voice.speak("Bearing %d degrees, range %d meters.", + (int) (state.from_pad.bearing + 0.5), + (int) (state.from_pad.distance + 0.5)); + ++reported_landing; + if (state.state != Altos.ao_flight_landed) { + state.state = Altos.ao_flight_landed; + show(state, 0); + } + } + } + + long now () { + return System.currentTimeMillis(); + } + + void set_report_time() { + report_time = now() + report_interval; + } + + public void run () { + try { + for (;;) { + set_report_time(); + for (;;) { + voice.drain(); + synchronized (this) { + long sleep_time = report_time - now(); + if (sleep_time <= 0) + break; + wait(sleep_time); + } + } + report(false); + } + } catch (InterruptedException ie) { + try { + voice.drain(); + } catch (InterruptedException iie) { } + } + } + + public synchronized void notice(AltosState new_state, boolean spoken) { + AltosState old_state = state; + state = new_state; + if (!started && state.state > Altos.ao_flight_pad) { + started = true; + start(); + } + + if (state.state < Altos.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; + } + } + + boolean tell(AltosState state, AltosState old_state) { + boolean ret = false; + if (old_state == null || old_state.state != state.state) { + voice.speak(state.data.state()); + if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && + state.state > Altos.ao_flight_boost) { + voice.speak("max speed: %d meters per second.", + (int) (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: %d meters.", + (int) (state.max_height + 0.5)); + ret = true; + } + } + if (old_state == null || old_state.gps_ready != state.gps_ready) { + if (state.gps_ready) { + voice.speak("GPS ready"); + ret = true; + } + else if (old_state != null) { + voice.speak("GPS lost"); + ret = true; + } + } + old_state = state; + return ret; + } + + public void run() { + boolean interrupted = false; + String line; + AltosState state = null; + AltosState old_state = null; + boolean told; + + idle_thread = new IdleThread(); + + display.reset(); + try { + for (;;) { + try { + AltosRecord record = reader.read(); + if (record == null) + break; + old_state = state; + state = new AltosState(record, state); + reader.update(state); + show(state, crc_errors); + told = tell(state, old_state); + idle_thread.notice(state, told); + } catch (ParseException pp) { + System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); + } catch (AltosCRCException ce) { + ++crc_errors; + show(state, crc_errors); + } + } + } catch (InterruptedException ee) { + interrupted = true; + } catch (IOException ie) { + JOptionPane.showMessageDialog(parent, + String.format("Error reading from \"%s\"", name), + "Telemetry Read Error", + JOptionPane.ERROR_MESSAGE); + } finally { + if (!interrupted) + idle_thread.report(true); + reader.close(interrupted); + idle_thread.interrupt(); + try { + idle_thread.join(); + } catch (InterruptedException ie) {} + } + } + + public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosFlightDisplay in_display, AltosFlightReader in_reader) { + parent = in_parent; + voice = in_voice; + display = in_display; + reader = in_reader; + } +} diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java new file mode 100644 index 00000000..02fc36f2 --- /dev/null +++ b/altosui/AltosEepromDownload.java @@ -0,0 +1,285 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.*; + +import libaltosJNI.*; + +public class AltosEepromDownload implements Runnable { + + static final String[] state_names = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid", + }; + + int[] ParseHex(String line) { + String[] tokens = line.split("\\s+"); + int[] array = new int[tokens.length]; + + for (int i = 0; i < tokens.length; i++) + try { + array[i] = Integer.parseInt(tokens[i], 16); + } catch (NumberFormatException ne) { + return null; + } + return array; + } + + int checksum(int[] line) { + int csum = 0x5a; + for (int i = 1; i < line.length; i++) + csum += line[i]; + return csum & 0xff; + } + + void FlushPending(FileWriter file, LinkedList pending) throws IOException { + while (!pending.isEmpty()) { + file.write(pending.remove()); + } + } + + JFrame frame; + AltosDevice device; + AltosSerial serial_line; + boolean remote; + Thread eeprom_thread; + AltosEepromMonitor monitor; + + void CaptureLog() throws IOException, InterruptedException, TimeoutException { + int serial = 0; + int block, state_block = 0; + int addr; + int flight = 0; + int year = 0, month = 0, day = 0; + int state = 0; + boolean done = false; + boolean want_file = false; + boolean any_valid; + FileWriter eeprom_file = null; + AltosFile eeprom_name; + LinkedList eeprom_pending = new LinkedList(); + + serial_line.printf("\nc s\nv\n"); + + /* Pull the serial number out of the version information */ + + for (;;) { + String line = serial_line.get_reply(5000); + + if (line == null) + throw new TimeoutException(); + if (line.startsWith("serial-number")) { + try { + serial = Integer.parseInt(line.substring(13).trim()); + } catch (NumberFormatException ne) { + serial = 0; + } + } + + eeprom_pending.add(String.format("%s\n", line)); + + /* signals the end of the version info */ + if (line.startsWith("software-version")) + break; + } + if (serial == 0) + throw new IOException("no serial number found"); + + monitor.set_serial(serial); + /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */ + + state = 0; state_block = 0; + for (block = 0; !done && block < 511; block++) { + serial_line.printf("e %x\n", block); + any_valid = false; + monitor.set_value(state_names[state], state, block - state_block); + for (addr = 0; addr < 0x100;) { + String line = serial_line.get_reply(5000); + if (line == null) + throw new TimeoutException(); + int[] values = ParseHex(line); + + if (values == null) { + System.out.printf("invalid line: %s\n", line); + continue; + } else if (values[0] != addr) { + System.out.printf("data address out of sync at 0x%x\n", + block * 256 + values[0]); + } else if (checksum(values) != 0) { + System.out.printf("invalid checksum at 0x%x\n", + block * 256 + values[0]); + } else { + any_valid = true; + int cmd = values[1]; + int tick = values[3] + (values[4] << 8); + int a = values[5] + (values[6] << 8); + int b = values[7] + (values[8] << 8); + + if (cmd == Altos.AO_LOG_FLIGHT) { + flight = b; + monitor.set_flight(flight); + } + + /* Monitor state transitions to update display */ + if (cmd == Altos.AO_LOG_STATE && a <= Altos.ao_flight_landed) { + if (a > Altos.ao_flight_pad) + want_file = true; + if (a > state) + state_block = block; + state = a; + } + + if (cmd == Altos.AO_LOG_GPS_DATE) { + year = 2000 + (a & 0xff); + month = (a >> 8) & 0xff; + day = (b & 0xff); + want_file = true; + } + + if (eeprom_file == null) { + if (serial != 0 && flight != 0 && want_file) { + if (year != 0 && month != 0 && day != 0) + eeprom_name = new AltosFile(year, month, day, serial, flight, "eeprom"); + else + eeprom_name = new AltosFile(serial, flight, "eeprom"); + + monitor.set_file(eeprom_name.getName()); + eeprom_file = new FileWriter(eeprom_name); + if (eeprom_file != null) { + FlushPending(eeprom_file, eeprom_pending); + eeprom_pending = null; + } + } + } + + String log_line = String.format("%c %4x %4x %4x\n", + cmd, tick, a, b); + if (eeprom_file != null) + eeprom_file.write(log_line); + else + eeprom_pending.add(log_line); + + if (cmd == Altos.AO_LOG_STATE && a == Altos.ao_flight_landed) { + done = true; + } + } + addr += 8; + } + if (!any_valid) + done = true; + } + if (eeprom_file == null) { + eeprom_name = new AltosFile(serial,flight,"eeprom"); + eeprom_file = new FileWriter(eeprom_name); + if (eeprom_file != null) { + FlushPending(eeprom_file, eeprom_pending); + } + } + if (eeprom_file != null) { + eeprom_file.flush(); + eeprom_file.close(); + } + } + + public void run () { + if (remote) { + serial_line.set_radio(); + serial_line.printf("p\nE 0\n"); + serial_line.flush_input(); + } + + monitor = new AltosEepromMonitor(frame, Altos.ao_flight_boost, Altos.ao_flight_landed); + monitor.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + eeprom_thread.interrupt(); + } + }); + try { + CaptureLog(); + } catch (IOException ee) { + JOptionPane.showMessageDialog(frame, + device.toShortString(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } catch (InterruptedException ie) { + } catch (TimeoutException te) { + JOptionPane.showMessageDialog(frame, + String.format("Connection to \"%s\" failed", + device.toShortString()), + "Connection Failed", + JOptionPane.ERROR_MESSAGE); + } + if (remote) + serial_line.printf("~"); + monitor.done(); + serial_line.flush_output(); + serial_line.close(); + } + + public AltosEepromDownload(JFrame given_frame) { + frame = given_frame; + device = AltosDeviceDialog.show(frame, AltosDevice.product_any); + + remote = false; + + if (device != null) { + try { + serial_line = new AltosSerial(device); + if (!device.matchProduct(AltosDevice.product_telemetrum)) + remote = true; + eeprom_thread = new Thread(this); + eeprom_thread.start(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + String.format("Cannot open device \"%s\"", + device.toShortString()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(frame, + String.format("Device \"%s\" already in use", + device.toShortString()), + "Device in use", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(frame, + device.toShortString(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } + } + } +} diff --git a/altosui/AltosEepromIterable.java b/altosui/AltosEepromIterable.java new file mode 100644 index 00000000..f8e6d7e5 --- /dev/null +++ b/altosui/AltosEepromIterable.java @@ -0,0 +1,423 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +/* + * 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 { + + 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 int compareTo(AltosOrderedRecord o) { + int tick_diff = tick - o.tick; + if (tick_diff != 0) + return tick_diff; + return index - o.index; + } +} + +public class AltosEepromIterable 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|seen_temp_volt|seen_deploy; + + AltosEepromRecord flight_record; + AltosEepromRecord gps_date_record; + + TreeSet records; + + LinkedList list; + + class EepromState { + int seen; + int n_pad_samples; + double ground_pres; + int gps_tick; + int boost_tick; + + EepromState() { + seen = 0; + n_pad_samples = 0; + ground_pres = 0.0; + gps_tick = 0; + } + } + + void update_state(AltosRecord state, AltosEepromRecord record, EepromState eeprom) { + state.tick = record.tick; + switch (record.cmd) { + case Altos.AO_LOG_FLIGHT: + eeprom.seen |= seen_flight; + state.ground_accel = record.a; + state.flight_accel = record.a; + state.flight = record.b; + eeprom.boost_tick = record.tick; + break; + case Altos.AO_LOG_SENSOR: + state.accel = record.a; + state.pres = record.b; + if (state.state < Altos.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; + state.flight_vel += (state.accel_plus_g - state.accel); + } + eeprom.seen |= seen_sensor; + break; + case Altos.AO_LOG_TEMP_VOLT: + state.temp = record.a; + state.batt = record.b; + eeprom.seen |= seen_temp_volt; + break; + case Altos.AO_LOG_DEPLOY: + state.drogue = record.a; + state.main = record.b; + eeprom.seen |= seen_deploy; + break; + case Altos.AO_LOG_STATE: + state.state = record.a; + break; + case Altos.AO_LOG_GPS_TIME: + eeprom.gps_tick = state.tick; + AltosGPS old = state.gps; + state.gps = new AltosGPS(); + + /* 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); + + int flags = (record.b >> 8); + state.gps.connected = (flags & Altos.AO_GPS_RUNNING) != 0; + state.gps.locked = (flags & Altos.AO_GPS_VALID) != 0; + state.gps.date_valid = (flags & Altos.AO_GPS_DATE_VALID) != 0; + state.gps.nsat = (flags & Altos.AO_GPS_NUM_SAT_MASK) >> + Altos.AO_GPS_NUM_SAT_SHIFT; + break; + case Altos.AO_LOG_GPS_LAT: + int lat32 = record.a | (record.b << 16); + state.gps.lat = (double) lat32 / 1e7; + break; + case Altos.AO_LOG_GPS_LON: + int lon32 = record.a | (record.b << 16); + state.gps.lon = (double) lon32 / 1e7; + break; + case Altos.AO_LOG_GPS_ALT: + state.gps.alt = record.a; + break; + case Altos.AO_LOG_GPS_SAT: + if (state.tick == eeprom.gps_tick) { + int svid = record.a; + int c_n0 = record.b >> 8; + state.gps.add_sat(svid, c_n0); + } + break; + case Altos.AO_LOG_GPS_DATE: + state.gps.year = (record.a & 0xff) + 2000; + state.gps.month = record.a >> 8; + state.gps.day = record.b & 0xff; + break; + + case Altos.AO_LOG_CONFIG_VERSION: + break; + case Altos.AO_LOG_MAIN_DEPLOY: + break; + case Altos.AO_LOG_APOGEE_DELAY: + break; + case Altos.AO_LOG_RADIO_CHANNEL: + break; + case Altos.AO_LOG_CALLSIGN: + state.callsign = record.data; + break; + case Altos.AO_LOG_ACCEL_CAL: + state.accel_plus_g = record.a; + state.accel_minus_g = record.b; + break; + case Altos.AO_LOG_RADIO_CAL: + break; + case Altos.AO_LOG_MANUFACTURER: + break; + case Altos.AO_LOG_PRODUCT: + break; + case Altos.AO_LOG_SERIAL_NUMBER: + state.serial = record.a; + break; + case Altos.AO_LOG_SOFTWARE_VERSION: + break; + } + } + + LinkedList make_list() { + LinkedList list = new LinkedList(); + Iterator iterator = records.iterator(); + AltosOrderedRecord record = null; + AltosRecord state = new AltosRecord(); + boolean last_reported = false; + EepromState eeprom = new EepromState(); + + state.state = Altos.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) { + AltosRecord r = new AltosRecord(state); + r.time = (r.tick - eeprom.boost_tick) / 100.0; + list.add(r); + } + update_state(state, record, eeprom); + } + AltosRecord r = new AltosRecord(state); + r.time = (r.tick - eeprom.boost_tick) / 100.0; + list.add(r); + return list; + } + + public Iterator iterator() { + if (list == null) + list = make_list(); + return list.iterator(); + } + + public void write_comments(PrintStream out) { + Iterator iterator = records.iterator(); + out.printf("# Comments\n"); + while (iterator.hasNext()) { + AltosOrderedRecord record = iterator.next(); + switch (record.cmd) { + case Altos.AO_LOG_CONFIG_VERSION: + out.printf("# Config version: %s\n", record.data); + break; + case Altos.AO_LOG_MAIN_DEPLOY: + out.printf("# Main deploy: %s\n", record.a); + break; + case Altos.AO_LOG_APOGEE_DELAY: + out.printf("# Apogee delay: %s\n", record.a); + break; + case Altos.AO_LOG_RADIO_CHANNEL: + out.printf("# Radio channel: %s\n", record.a); + break; + case Altos.AO_LOG_CALLSIGN: + out.printf("# Callsign: %s\n", record.data); + break; + case Altos.AO_LOG_ACCEL_CAL: + out.printf ("# Accel cal: %d %d\n", record.a, record.b); + break; + case Altos.AO_LOG_RADIO_CAL: + out.printf ("# Radio cal: %d\n", record.a); + break; + case Altos.AO_LOG_MANUFACTURER: + out.printf ("# Manufacturer: %s\n", record.data); + break; + case Altos.AO_LOG_PRODUCT: + out.printf ("# Product: %s\n", record.data); + break; + case Altos.AO_LOG_SERIAL_NUMBER: + out.printf ("# Serial number: %d\n", record.a); + break; + case Altos.AO_LOG_SOFTWARE_VERSION: + out.printf ("# Software version: %s\n", record.data); + break; + } + } + } + + /* + * 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 & Altos.AO_GPS_NUM_SAT_MASK) >> Altos.AO_GPS_NUM_SAT_SHIFT < 4) + flags = (flags & ~Altos.AO_GPS_NUM_SAT_MASK) | (4 << Altos.AO_GPS_NUM_SAT_SHIFT); + flags |= Altos.AO_GPS_RUNNING; + flags |= Altos.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); + } + + /* + * 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 last_gps_time = null; + + int index = 0; + int prev_tick = 0; + boolean prev_tick_valid = false; + boolean missing_time = false; + + try { + for (;;) { + String line = AltosRecord.gets(input); + if (line == null) + break; + AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick, prev_tick_valid); + if (record == null) + break; + if (record.cmd == Altos.AO_LOG_INVALID) + continue; + prev_tick = record.tick; + if (record.cmd < Altos.AO_LOG_CONFIG_VERSION) + prev_tick_valid = true; + if (record.cmd == Altos.AO_LOG_FLIGHT) { + flight_record = record; + continue; + } + + /* 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 == Altos.AO_LOG_GPS_DATE) { + gps_date_record = record; + continue; + } + + /* go back and fix up any missing time values */ + if (record.cmd == Altos.AO_LOG_GPS_TIME) { + last_gps_time = record; + if (missing_time) { + Iterator iterator = records.iterator(); + while (iterator.hasNext()) { + AltosOrderedRecord old = iterator.next(); + if (old.cmd == Altos.AO_LOG_GPS_TIME && + old.a == -1 && old.b == -1) + { + update_time(record, old); + } + } + missing_time = false; + } + } + + if (record.cmd == Altos.AO_LOG_GPS_LAT) { + if (last_gps_time == null || last_gps_time.tick != record.tick) { + AltosOrderedRecord add_gps_time = new AltosOrderedRecord(Altos.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; + + records.add(add_gps_time); + record.index = index++; + } + } + records.add(record); + + /* Bail after reading the 'landed' record; we're all done */ + if (record.cmd == Altos.AO_LOG_STATE && + record.a == Altos.ao_flight_landed) + break; + } + } catch (IOException io) { + } catch (ParseException pe) { + } + try { + input.close(); + } catch (IOException ie) { + } + } +} diff --git a/altosui/AltosEepromMonitor.java b/altosui/AltosEepromMonitor.java new file mode 100644 index 00000000..7ff00ead --- /dev/null +++ b/altosui/AltosEepromMonitor.java @@ -0,0 +1,176 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosEepromMonitor extends JDialog { + + Container pane; + Box box; + JLabel serial_label; + JLabel flight_label; + JLabel file_label; + JLabel serial_value; + JLabel flight_value; + JLabel file_value; + JButton cancel; + JProgressBar pbar; + int min_state, max_state; + + public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) { + super (owner, "Download Flight Data", false); + + GridBagConstraints c; + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 0; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JLabel(""); + pane.add(serial_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + flight_label = new JLabel("Flight:"); + pane.add(flight_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + flight_value = new JLabel(""); + pane.add(flight_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 2; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + file_label = new JLabel("File:"); + pane.add(file_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 2; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + file_value = new JLabel(""); + pane.add(file_value, c); + + min_state = in_min_state; + max_state = in_max_state; + pbar = new JProgressBar(); + pbar.setMinimum(0); + pbar.setMaximum((max_state - min_state) * 100); + pbar.setValue(0); + pbar.setString("startup"); + pbar.setStringPainted(true); + pbar.setPreferredSize(new Dimension(600, 20)); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 3; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ib = new Insets(4,4,4,4); + c.insets = ib; + pane.add(pbar, c); + + + cancel = new JButton("Cancel"); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 4; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ic = new Insets(4,4,4,4); + c.insets = ic; + pane.add(cancel, c); + + pack(); + setLocationRelativeTo(owner); + setVisible(true); + } + + public void addActionListener (ActionListener l) { + cancel.addActionListener(l); + } + + public void set_value(String state_name, int in_state, int in_block) { + int block = in_block; + int state = in_state; + + if (block > 100) + block = 100; + if (state < min_state) state = min_state; + if (state >= max_state) state = max_state - 1; + state -= min_state; + + int pos = state * 100 + block; + + pbar.setString(state_name); + pbar.setValue(pos); + } + + public void set_serial(int serial) { + serial_value.setText(String.format("%d", serial)); + } + + public void set_flight(int flight) { + flight_value.setText(String.format("%d", flight)); + } + + public void set_file(String file) { + file_value.setText(String.format("%s", file)); + } + + public void done() { + setVisible(false); + dispose(); + } +} diff --git a/altosui/AltosEepromRecord.java b/altosui/AltosEepromRecord.java new file mode 100644 index 00000000..5a673817 --- /dev/null +++ b/altosui/AltosEepromRecord.java @@ -0,0 +1,115 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosEepromRecord { + public int cmd; + public int tick; + public int a; + public int b; + public String data; + public boolean tick_valid; + + public AltosEepromRecord (String line) { + tick_valid = false; + tick = 0; + a = 0; + b = 0; + data = null; + if (line == null) { + cmd = Altos.AO_LOG_INVALID; + data = ""; + } else { + try { + String[] tokens = line.split("\\s+"); + + if (tokens[0].length() == 1) { + if (tokens.length != 4) { + cmd = Altos.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 = Altos.AO_LOG_CONFIG_VERSION; + data = tokens[2]; + } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { + cmd = Altos.AO_LOG_MAIN_DEPLOY; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { + cmd = Altos.AO_LOG_APOGEE_DELAY; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { + cmd = Altos.AO_LOG_RADIO_CHANNEL; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Callsign:")) { + cmd = Altos.AO_LOG_CALLSIGN; + data = tokens[1].replaceAll("\"",""); + } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { + cmd = Altos.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 = Altos.AO_LOG_RADIO_CAL; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("manufacturer")) { + cmd = Altos.AO_LOG_MANUFACTURER; + data = tokens[1]; + } else if (tokens[0].equals("product")) { + cmd = Altos.AO_LOG_PRODUCT; + data = tokens[1]; + } else if (tokens[0].equals("serial-number")) { + cmd = Altos.AO_LOG_SERIAL_NUMBER; + a = Integer.parseInt(tokens[1]); + } else if (tokens[0].equals("software-version")) { + cmd = Altos.AO_LOG_SOFTWARE_VERSION; + data = tokens[1]; + } else { + cmd = Altos.AO_LOG_INVALID; + data = line; + } + } catch (NumberFormatException ne) { + cmd = Altos.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/altosui/AltosFile.java b/altosui/AltosFile.java new file mode 100644 index 00000000..06360572 --- /dev/null +++ b/altosui/AltosFile.java @@ -0,0 +1,44 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.File; +import java.util.*; + +class AltosFile extends File { + + public AltosFile(int year, int month, int day, int serial, int flight, String extension) { + super (AltosPreferences.logdir(), + String.format("%04d-%02d-%02d-serial-%03d-flight-%03d.%s", + year, month, day, serial, flight, extension)); + } + + public AltosFile(int serial, int flight, String extension) { + this(Calendar.getInstance().get(Calendar.YEAR), + Calendar.getInstance().get(Calendar.MONTH) + 1, + Calendar.getInstance().get(Calendar.DAY_OF_MONTH), + serial, + flight, + extension); + } + + public AltosFile(AltosTelemetry telem) { + this(telem.serial, telem.flight, "telem"); + } +} diff --git a/altosui/AltosFlash.java b/altosui/AltosFlash.java new file mode 100644 index 00000000..3af25c23 --- /dev/null +++ b/altosui/AltosFlash.java @@ -0,0 +1,344 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlash { + File file; + FileInputStream input; + AltosHexfile image; + JFrame frame; + AltosDevice debug_dongle; + AltosDebug debug; + AltosRomconfig rom_config; + ActionListener listener; + boolean aborted; + + static final byte MOV_direct_data = (byte) 0x75; + static final byte MOV_DPTR_data16 = (byte) 0x90; + static final byte MOV_A_data = (byte) 0x74; + static final byte MOVX_atDPTR_A = (byte) 0xf0; + static final byte MOVX_A_atDPTR = (byte) 0xe0; + static final byte INC_DPTR = (byte) 0xa3; + static final byte TRAP = (byte) 0xa5; + + static final byte JB = (byte) 0x20; + + static final byte MOV_A_direct = (byte) 0xe5; + static final byte MOV_direct1_direct2 = (byte) 0x85; + static final byte MOV_direct_A = (byte) 0xf5; + static final byte MOV_R0_data = (byte) (0x78 | 0); + static final byte MOV_R1_data = (byte) (0x78 | 1); + static final byte MOV_R2_data = (byte) (0x78 | 2); + static final byte MOV_R3_data = (byte) (0x78 | 3); + static final byte MOV_R4_data = (byte) (0x78 | 4); + static final byte MOV_R5_data = (byte) (0x78 | 5); + static final byte MOV_R6_data = (byte) (0x78 | 6); + static final byte MOV_R7_data = (byte) (0x78 | 7); + static final byte DJNZ_R0_rel = (byte) (0xd8 | 0); + static final byte DJNZ_R1_rel = (byte) (0xd8 | 1); + static final byte DJNZ_R2_rel = (byte) (0xd8 | 2); + static final byte DJNZ_R3_rel = (byte) (0xd8 | 3); + static final byte DJNZ_R4_rel = (byte) (0xd8 | 4); + static final byte DJNZ_R5_rel = (byte) (0xd8 | 5); + static final byte DJNZ_R6_rel = (byte) (0xd8 | 6); + static final byte DJNZ_R7_rel = (byte) (0xd8 | 7); + + static final byte P1DIR = (byte) 0xFE; + static final byte P1 = (byte) 0x90; + + /* flash controller */ + static final byte FWT = (byte) 0xAB; + static final byte FADDRL = (byte) 0xAC; + static final byte FADDRH = (byte) 0xAD; + static final byte FCTL = (byte) 0xAE; + static final byte FCTL_BUSY = (byte) 0x80; + static final byte FCTL_BUSY_BIT = (byte) 7; + static final byte FCTL_SWBSY = (byte) 0x40; + static final byte FCTL_SWBSY_BIT = (byte) 6; + static final byte FCTL_CONTRD = (byte) 0x10; + static final byte FCTL_WRITE = (byte) 0x02; + static final byte FCTL_ERASE = (byte) 0x01; + static final byte FWDATA = (byte) 0xAF; + + static final byte ACC = (byte) 0xE0; + + /* offsets within the flash_page program */ + static final int FLASH_ADDR_HIGH = 8; + static final int FLASH_ADDR_LOW = 11; + static final int RAM_ADDR_HIGH = 13; + static final int RAM_ADDR_LOW = 14; + static final int FLASH_WORDS_HIGH = 16; + static final int FLASH_WORDS_LOW = 18; + static final int FLASH_TIMING = 21; + + /* sleep mode control */ + static final int SLEEP = (byte) 0xbe; + static final int SLEEP_USB_EN = (byte) 0x80; + static final int SLEEP_XOSC_STB = (byte) 0x40; + static final int SLEEP_HFRC_STB = (byte) 0x20; + static final int SLEEP_RST_MASK = (byte) 0x18; + static final int SLEEP_RST_POWERON = (byte) 0x00; + static final int SLEEP_RST_EXTERNAL = (byte) 0x10; + static final int SLEEP_RST_WATCHDOG = (byte) 0x08; + static final int SLEEP_OSC_PD = (byte) 0x04; + static final int SLEEP_MODE_MASK = (byte) 0x03; + static final int SLEEP_MODE_PM0 = (byte) 0x00; + static final int SLEEP_MODE_PM1 = (byte) 0x01; + static final int SLEEP_MODE_PM2 = (byte) 0x02; + static final int SLEEP_MODE_PM3 = (byte) 0x03; + + /* clock controller */ + static final byte CLKCON = (byte) 0xC6; + static final byte CLKCON_OSC32K = (byte) 0x80; + static final byte CLKCON_OSC = (byte) 0x40; + static final byte CLKCON_TICKSPD = (byte) 0x38; + static final byte CLKCON_CLKSPD = (byte) 0x07; + + static final byte[] flash_page_proto = { + + MOV_direct_data, P1DIR, (byte) 0x02, + MOV_direct_data, P1, (byte) 0xFF, + + MOV_direct_data, FADDRH, 0, /* FLASH_ADDR_HIGH */ + + MOV_direct_data, FADDRL, 0, /* FLASH_ADDR_LOW */ + + MOV_DPTR_data16, 0, 0, /* RAM_ADDR_HIGH, RAM_ADDR_LOW */ + + MOV_R7_data, 0, /* FLASH_WORDS_HIGH */ + + MOV_R6_data, 0, /* FLASH_WORDS_LOW */ + + + MOV_direct_data, FWT, 0x20, /* FLASH_TIMING */ + + MOV_direct_data, FCTL, FCTL_ERASE, +/* eraseWaitLoop: */ + MOV_A_direct, FCTL, + JB, ACC|FCTL_BUSY_BIT, (byte) 0xfb, + + MOV_direct_data, P1, (byte) 0xfd, + + MOV_direct_data, FCTL, FCTL_WRITE, +/* writeLoop: */ + MOV_R5_data, 2, +/* writeWordLoop: */ + MOVX_A_atDPTR, + INC_DPTR, + MOV_direct_A, FWDATA, + DJNZ_R5_rel, (byte) 0xfa, /* writeWordLoop */ +/* writeWaitLoop: */ + MOV_A_direct, FCTL, + JB, ACC|FCTL_SWBSY_BIT, (byte) 0xfb, /* writeWaitLoop */ + DJNZ_R6_rel, (byte) 0xf1, /* writeLoop */ + DJNZ_R7_rel, (byte) 0xef, /* writeLoop */ + + MOV_direct_data, P1DIR, (byte) 0x00, + MOV_direct_data, P1, (byte) 0xFF, + TRAP, + }; + + public byte[] make_flash_page(int flash_addr, int ram_addr, int byte_count) { + int flash_word_addr = flash_addr >> 1; + int flash_word_count = ((byte_count + 1) >> 1); + + byte[] flash_page = new byte[flash_page_proto.length]; + for (int i = 0; i < flash_page.length; i++) + flash_page[i] = flash_page_proto[i]; + + flash_page[FLASH_ADDR_HIGH] = (byte) (flash_word_addr >> 8); + flash_page[FLASH_ADDR_LOW] = (byte) (flash_word_addr); + flash_page[RAM_ADDR_HIGH] = (byte) (ram_addr >> 8); + flash_page[RAM_ADDR_LOW] = (byte) (ram_addr); + + byte flash_words_low = (byte) (flash_word_count); + byte flash_words_high = (byte) (flash_word_count >> 8); + /* the flashing code has a minor 'bug' */ + if (flash_words_low != 0) + flash_words_high++; + + flash_page[FLASH_WORDS_HIGH] = (byte) flash_words_high; + flash_page[FLASH_WORDS_LOW] = (byte) flash_words_low; + return flash_page; + } + + static byte[] set_clkcon_fast = { + MOV_direct_data, CLKCON, 0x00 + }; + + static byte[] get_sleep = { + MOV_A_direct, SLEEP + }; + + public void clock_init() throws IOException, InterruptedException { + debug.debug_instr(set_clkcon_fast); + + byte status; + for (int times = 0; times < 20; times++) { + Thread.sleep(1); + status = debug.debug_instr(get_sleep); + if ((status & SLEEP_XOSC_STB) != 0) + return; + } + throw new IOException("Failed to initialize target clock"); + } + + void action(String s, int percent) { + if (listener != null && !aborted) + listener.actionPerformed(new ActionEvent(this, + percent, + s)); + } + + void action(int part, int total) { + int percent = 100 * part / total; + action(String.format("%d/%d (%d%%)", + part, total, percent), + percent); + } + + void run(int pc) throws IOException, InterruptedException { + debug.set_pc(pc); + int set_pc = debug.get_pc(); + if (pc != set_pc) + throw new IOException("Failed to set target program counter"); + debug.resume(); + + for (int times = 0; times < 20; times++) { + byte status = debug.read_status(); + if ((status & AltosDebug.STATUS_CPU_HALTED) != 0) + return; + } + + throw new IOException("Failed to execute program on target"); + } + + public void flash() throws IOException, FileNotFoundException, InterruptedException { + if (!check_rom_config()) + throw new IOException("Invalid rom config settings"); + if (image.address + image.data.length > 0x8000) + throw new IOException(String.format("Flash image too long %d", + image.address + + image.data.length)); + if ((image.address & 0x3ff) != 0) + throw new IOException(String.format("Flash image must start on page boundary (is 0x%x)", + image.address)); + int ram_address = 0xf000; + int flash_prog = 0xf400; + + /* + * Store desired config values into image + */ + rom_config.write(image); + /* + * Bring up the clock + */ + clock_init(); + + int remain = image.data.length; + int 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 > 0x400) + this_time = 0x400; + + /* write the data */ + debug.write_memory(ram_address, image.data, + image_start, this_time); + + /* write the flash program */ + byte[] flash_page = make_flash_page(flash_addr, + ram_address, + this_time); + debug.write_memory(flash_prog, flash_page); + + run(flash_prog); + + byte[] check = debug.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])); + remain -= this_time; + flash_addr += this_time; + image_start += this_time; + + action(image.data.length - remain, image.data.length); + } + if (!aborted) { + action("done", 100); + debug.set_pc(image.address); + debug.resume(); + } + debug.close(); + } + + public void abort() { + aborted = true; + debug.close(); + } + + public void addActionListener(ActionListener l) { + listener = l; + } + + public boolean check_rom_config() { + 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 in_file, AltosDevice in_debug_dongle) + throws IOException, FileNotFoundException, AltosSerialInUseException, InterruptedException { + file = in_file; + debug_dongle = in_debug_dongle; + debug = new AltosDebug(in_debug_dongle); + input = new FileInputStream(file); + image = new AltosHexfile(input); + if (!debug.check_connection()) { + debug.close(); + throw new IOException("Debug port not connected"); + } + } +} \ No newline at end of file diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java new file mode 100644 index 00000000..f63097ac --- /dev/null +++ b/altosui/AltosFlashUI.java @@ -0,0 +1,218 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlashUI + extends JDialog + implements Runnable, ActionListener +{ + Container pane; + Box box; + JLabel serial_label; + JLabel serial_value; + JLabel file_label; + JLabel file_value; + JProgressBar pbar; + JButton cancel; + + File file; + Thread thread; + JFrame frame; + AltosDevice debug_dongle; + AltosFlash flash; + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == cancel) { + abort(); + dispose(); + } else { + String cmd = e.getActionCommand(); + if (cmd.equals("done")) + ; + else if (cmd.equals("start")) { + setVisible(true); + } else { + pbar.setValue(e.getID()); + pbar.setString(cmd); + } + } + } + + public void run() { + try { + flash = new AltosFlash(file, debug_dongle); + flash.addActionListener(this); + AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); + + romconfig_ui.set(flash.romconfig()); + AltosRomconfig romconfig = romconfig_ui.showDialog(); + + if (romconfig != null && romconfig.valid()) { + flash.set_romconfig(romconfig); + serial_value.setText(String.format("%d", + flash.romconfig().serial_number)); + file_value.setText(file.toString()); + setVisible(true); + flash.flash(); + flash = null; + } + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + "Cannot open image", + file.toString(), + JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(frame, + String.format("Device \"%s\" already in use", + debug_dongle.toShortString()), + "Device in use", + JOptionPane.ERROR_MESSAGE); + } catch (IOException e) { + JOptionPane.showMessageDialog(frame, + e.getMessage(), + file.toString(), + JOptionPane.ERROR_MESSAGE); + } catch (InterruptedException ie) { + } finally { + abort(); + } + dispose(); + } + + public void abort() { + if (flash != null) + flash.abort(); + } + + public void build_dialog() { + GridBagConstraints c; + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 0; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JLabel(""); + pane.add(serial_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + file_label = new JLabel("File:"); + pane.add(file_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + file_value = new JLabel(""); + pane.add(file_value, c); + + pbar = new JProgressBar(); + pbar.setMinimum(0); + pbar.setMaximum(100); + pbar.setValue(0); + pbar.setString(""); + pbar.setStringPainted(true); + pbar.setPreferredSize(new Dimension(600, 20)); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 2; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ib = new Insets(4,4,4,4); + c.insets = ib; + pane.add(pbar, c); + + cancel = new JButton("Cancel"); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 3; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ic = new Insets(4,4,4,4); + c.insets = ic; + pane.add(cancel, c); + cancel.addActionListener(this); + pack(); + setLocationRelativeTo(frame); + } + + public AltosFlashUI(JFrame in_frame) { + super(in_frame, "Program Altusmetrum Device", false); + + frame = in_frame; + + build_dialog(); + + debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.product_any); + + if (debug_dongle == null) + return; + + JFileChooser hexfile_chooser = new JFileChooser(); + + File firmwaredir = AltosPreferences.firmwaredir(); + if (firmwaredir != null) + hexfile_chooser.setCurrentDirectory(firmwaredir); + + hexfile_chooser.setDialogTitle("Select Flash Image"); + hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx")); + int returnVal = hexfile_chooser.showOpenDialog(frame); + + if (returnVal != JFileChooser.APPROVE_OPTION) + return; + + file = hexfile_chooser.getSelectedFile(); + + if (file != null) + AltosPreferences.set_firmwaredir(file.getParentFile()); + + thread = new Thread(this); + thread.start(); + } +} \ No newline at end of file diff --git a/altosui/AltosFlightDisplay.java b/altosui/AltosFlightDisplay.java new file mode 100644 index 00000000..d18d1d1f --- /dev/null +++ b/altosui/AltosFlightDisplay.java @@ -0,0 +1,24 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +public interface AltosFlightDisplay { + void reset(); + + void show(AltosState state, int crc_errors); +} diff --git a/altosui/AltosFlightInfoTableModel.java b/altosui/AltosFlightInfoTableModel.java new file mode 100644 index 00000000..e23eff68 --- /dev/null +++ b/altosui/AltosFlightInfoTableModel.java @@ -0,0 +1,84 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlightInfoTableModel extends AbstractTableModel { + final static private String[] columnNames = {"Field", "Value"}; + + int rows; + int cols; + private String[][] data; + + public int getColumnCount() { return cols; } + public int getRowCount() { return rows; } + public String getColumnName(int col) { return columnNames[col & 1]; } + + public Object getValueAt(int row, int col) { + if (row >= rows || col >= cols) + return ""; + return data[row][col]; + } + + int[] current_row; + + public void reset() { + for (int i = 0; i < cols / 2; i++) + current_row[i] = 0; + } + + public void clear() { + reset(); + for (int c = 0; c < cols; c++) + for (int r = 0; r < rows; r++) + data[r][c] = ""; + fireTableDataChanged(); + } + + public void addRow(int col, String name, String value) { + if (current_row[col] < rows) { + data[current_row[col]][col * 2] = name; + data[current_row[col]][col * 2 + 1] = value; + } + current_row[col]++; + } + + public void finish() { + for (int c = 0; c < cols / 2; c++) + while (current_row[c] < rows) + addRow(c, "", ""); + fireTableDataChanged(); + } + + public AltosFlightInfoTableModel (int in_rows, int in_cols) { + rows = in_rows; + cols = in_cols * 2; + data = new String[rows][cols]; + current_row = new int[in_cols]; + } +} diff --git a/altosui/AltosFlightReader.java b/altosui/AltosFlightReader.java new file mode 100644 index 00000000..3d59de9a --- /dev/null +++ b/altosui/AltosFlightReader.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; +import java.io.*; + +public class AltosFlightReader { + String name; + + int serial; + + void init() { } + + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } + + void close(boolean interrupted) { } + + void set_channel(int channel) { } + + void update(AltosState state) throws InterruptedException { } +} diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java new file mode 100644 index 00000000..59c9e9db --- /dev/null +++ b/altosui/AltosFlightStatus.java @@ -0,0 +1,154 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + + public class FlightValue { + JLabel label; + JTextField value; + + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + } + public FlightValue (GridBagLayout layout, int x, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(5, 5, 5, 5); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + c.weighty = 1; + + label = new JLabel(text); + label.setFont(Altos.status_font); + label.setHorizontalAlignment(SwingConstants.CENTER); + c.gridx = x; c.gridy = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(""); + value.setFont(Altos.status_font); + value.setHorizontalAlignment(SwingConstants.CENTER); + c.gridx = x; c.gridy = 1; + layout.setConstraints(value, c); + add(value); + } + } + + class Call extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(state.data.callsign); + } + public Call (GridBagLayout layout, int x) { + super (layout, x, "Callsign"); + } + } + + Call call; + + class Serial extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(String.format("%d", state.data.serial)); + } + public Serial (GridBagLayout layout, int x) { + super (layout, x, "Serial"); + } + } + + Serial serial; + + class Flight extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(String.format("%d", state.data.flight)); + } + public Flight (GridBagLayout layout, int x) { + super (layout, x, "Flight"); + } + } + + Flight flight; + + class FlightState extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(state.data.state()); + } + public FlightState (GridBagLayout layout, int x) { + super (layout, x, "State"); + } + } + + FlightState flight_state; + + class RSSI extends FlightValue { + void show(AltosState state, int crc_errors) { + value.setText(String.format("%d", state.data.rssi)); + } + public RSSI (GridBagLayout layout, int x) { + super (layout, x, "RSSI (dBm)"); + } + } + + RSSI rssi; + + public void reset () { + call.reset(); + serial.reset(); + flight.reset(); + flight_state.reset(); + rssi.reset(); + } + + public void show (AltosState state, int crc_errors) { + call.show(state, crc_errors); + serial.show(state, crc_errors); + flight.show(state, crc_errors); + flight_state.show(state, crc_errors); + rssi.show(state, crc_errors); + } + + public int height() { + Dimension d = layout.preferredLayoutSize(this); + return d.height; + } + + public AltosFlightStatus() { + layout = new GridBagLayout(); + + setLayout(layout); + + call = new Call(layout, 0); + serial = new Serial(layout, 1); + flight = new Flight(layout, 2); + flight_state = new FlightState(layout, 3); + rssi = new RSSI(layout, 4); + } +} diff --git a/altosui/AltosFlightStatusTableModel.java b/altosui/AltosFlightStatusTableModel.java new file mode 100644 index 00000000..4c24b6ac --- /dev/null +++ b/altosui/AltosFlightStatusTableModel.java @@ -0,0 +1,61 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlightStatusTableModel extends AbstractTableModel { + private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; + private Object[] data = { 0, "idle", 0, 0 }; + + public int getColumnCount() { return columnNames.length; } + public int getRowCount() { return 2; } + public Object getValueAt(int row, int col) { + if (row == 0) + return columnNames[col]; + return data[col]; + } + + public void setValueAt(Object value, int col) { + data[col] = value; + fireTableCellUpdated(1, col); + } + + public void setValueAt(Object value, int row, int col) { + setValueAt(value, col); + } + + public void set(AltosState state) { + setValueAt(String.format("%1.0f", state.height), 0); + setValueAt(state.data.state(), 1); + setValueAt(state.data.rssi, 2); + double speed = state.baro_speed; + if (state.ascent) + speed = state.speed; + setValueAt(String.format("%1.0f", speed), 3); + } +} diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java new file mode 100644 index 00000000..24d25bd7 --- /dev/null +++ b/altosui/AltosFlightUI.java @@ -0,0 +1,221 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosFlightUI extends JFrame implements AltosFlightDisplay { + String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; + Object[][] statusData = { { "0", "pad", "-50", "0" } }; + + AltosVoice voice; + AltosFlightReader reader; + AltosDisplayThread thread; + + JTabbedPane pane; + + AltosPad pad; + AltosAscent ascent; + AltosDescent descent; + AltosLanded landed; + AltosSiteMap sitemap; + + private AltosFlightStatus flightStatus; + private AltosInfoTable flightInfo; + + static final int tab_pad = 1; + static final int tab_ascent = 2; + static final int tab_descent = 3; + static final int tab_landed = 4; + + int cur_tab = 0; + + boolean exit_on_close = false; + + int which_tab(AltosState state) { + if (state.state < Altos.ao_flight_boost) + return tab_pad; + if (state.state <= Altos.ao_flight_coast) + return tab_ascent; + if (state.state <= Altos.ao_flight_main) + return tab_descent; + return tab_landed; + } + + void stop_display() { + if (thread != null && thread.isAlive()) { + thread.interrupt(); + try { + thread.join(); + } catch (InterruptedException ie) {} + } + thread = null; + } + + void disconnect() { + stop_display(); + } + + public void reset() { + pad.reset(); + ascent.reset(); + descent.reset(); + landed.reset(); + flightInfo.clear(); + sitemap.reset(); + } + + public void show(AltosState state, int crc_errors) { + int tab = which_tab(state); + pad.show(state, crc_errors); + ascent.show(state, crc_errors); + descent.show(state, crc_errors); + landed.show(state, crc_errors); + if (tab != cur_tab) { + switch (tab) { + case tab_pad: + pane.setSelectedComponent(pad); + break; + case tab_ascent: + pane.setSelectedComponent(ascent); + break; + case tab_descent: + pane.setSelectedComponent(descent); + break; + case tab_landed: + pane.setSelectedComponent(landed); + } + cur_tab = tab; + } + flightStatus.show(state, crc_errors); + flightInfo.show(state, crc_errors); + sitemap.show(state, crc_errors); + } + + public void set_exit_on_close() { + exit_on_close = true; + } + + Container bag; + JComboBox channels; + + public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { + AltosPreferences.init(this); + + voice = in_voice; + reader = in_reader; + + bag = getContentPane(); + bag.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + + java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg"); + if (imgURL != null) + setIconImage(new ImageIcon(imgURL).getImage()); + + setTitle(String.format("AltOS %s", reader.name)); + + /* Stick channel selector at top of table for telemetry monitoring */ + if (serial >= 0) { + // Channel menu + channels = new AltosChannelMenu(AltosPreferences.channel(serial)); + channels.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int channel = channels.getSelectedIndex(); + reader.set_channel(channel); + } + }); + c.gridx = 0; + c.gridy = 0; + c.anchor = GridBagConstraints.WEST; + bag.add (channels, c); + } + + /* Flight status is always visible */ + flightStatus = new AltosFlightStatus(); + c.gridx = 0; + c.gridy = 1; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + bag.add(flightStatus, c); + + /* The rest of the window uses a tabbed pane to + * show one of the alternate data views + */ + pane = new JTabbedPane(); + + pad = new AltosPad(); + pane.add("Launch Pad", pad); + + ascent = new AltosAscent(); + pane.add("Ascent", ascent); + + descent = new AltosDescent(); + pane.add("Descent", descent); + + landed = new AltosLanded(); + pane.add("Landed", landed); + + flightInfo = new AltosInfoTable(); + pane.add("Table", new JScrollPane(flightInfo)); + + sitemap = new AltosSiteMap(); + pane.add("Site Map", sitemap); + + /* Make the tabbed pane use the rest of the window space */ + c.gridx = 0; + c.gridy = 2; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + c.weighty = 1; + bag.add(pane, c); + + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + disconnect(); + setVisible(false); + dispose(); + if (exit_on_close) + System.exit(0); + } + }); + + pack(); + setVisible(true); + + thread = new AltosDisplayThread(this, voice, this, reader); + + thread.start(); + } + + public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) { + this(in_voice, in_reader, -1); + } +} diff --git a/altosui/AltosGPS.java b/altosui/AltosGPS.java new file mode 100644 index 00000000..83821842 --- /dev/null +++ b/altosui/AltosGPS.java @@ -0,0 +1,215 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; + +public class AltosGPS { + public class AltosGPSSat { + int svid; + int c_n0; + } + + int nsat; + boolean locked; + boolean connected; + boolean date_valid; + double lat; /* degrees (+N -S) */ + double lon; /* degrees (+E -W) */ + int alt; /* m */ + int year; + int month; + int day; + int hour; + int minute; + int second; + + int gps_extended; /* has extra data */ + double ground_speed; /* m/s */ + int course; /* degrees */ + double climb_rate; /* m/s */ + double hdop; /* unitless? */ + int h_error; /* m */ + int v_error; /* m */ + + AltosGPSSat[] cc_gps_sat; /* tracking data */ + + void ParseGPSDate(String date) throws ParseException { + String[] ymd = date.split("-"); + if (ymd.length != 3) + throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); + year = AltosParse.parse_int(ymd[0]); + month = AltosParse.parse_int(ymd[1]); + day = AltosParse.parse_int(ymd[2]); + } + + void ParseGPSTime(String time) throws ParseException { + String[] hms = time.split(":"); + if (hms.length != 3) + throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); + hour = AltosParse.parse_int(hms[0]); + minute = AltosParse.parse_int(hms[1]); + second = AltosParse.parse_int(hms[2]); + } + + void ClearGPSTime() { + year = month = day = 0; + hour = minute = second = 0; + } + + public AltosGPS(String[] words, int i, int version) throws ParseException { + AltosParse.word(words[i++], "GPS"); + nsat = AltosParse.parse_int(words[i++]); + AltosParse.word(words[i++], "sat"); + + connected = false; + locked = false; + lat = lon = 0; + alt = 0; + ClearGPSTime(); + if ((words[i]).equals("unlocked")) { + connected = true; + i++; + } else if ((words[i]).equals("not-connected")) { + i++; + } else if (words.length >= 40) { + locked = true; + connected = true; + + if (version > 1) + ParseGPSDate(words[i++]); + else + year = month = day = 0; + ParseGPSTime(words[i++]); + lat = AltosParse.parse_coord(words[i++]); + lon = AltosParse.parse_coord(words[i++]); + alt = AltosParse.parse_int(words[i++]); + if (version > 1 || (i < words.length && !words[i].equals("SAT"))) { + ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)")); + course = AltosParse.parse_int(words[i++]); + climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)")); + hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)")); + h_error = AltosParse.parse_int(words[i++]); + v_error = AltosParse.parse_int(words[i++]); + } + } else { + i++; + } + if (i < words.length) { + AltosParse.word(words[i++], "SAT"); + int tracking_channels = 0; + if (words[i].equals("not-connected")) + tracking_channels = 0; + else + tracking_channels = AltosParse.parse_int(words[i]); + i++; + cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels]; + for (int chan = 0; chan < tracking_channels; chan++) { + cc_gps_sat[chan] = new AltosGPS.AltosGPSSat(); + cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]); + /* Older versions included SiRF status bits */ + if (version < 2) + i++; + cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]); + } + } else + cc_gps_sat = new AltosGPS.AltosGPSSat[0]; + } + + public void set_latitude(int in_lat) { + lat = in_lat / 10.0e7; + } + + public void set_longitude(int in_lon) { + lon = in_lon / 10.0e7; + } + + public void set_time(int hour, int minute, int second) { + hour = hour; + minute = minute; + second = second; + } + + public void set_date(int year, int month, int day) { + year = year; + month = month; + day = day; + } + + public void set_flags(int flags) { + flags = flags; + } + + public void set_altitude(int altitude) { + altitude = altitude; + } + + public void add_sat(int svid, int c_n0) { + if (cc_gps_sat == null) { + cc_gps_sat = new AltosGPS.AltosGPSSat[1]; + } else { + AltosGPSSat[] new_gps_sat = new AltosGPS.AltosGPSSat[cc_gps_sat.length + 1]; + for (int i = 0; i < cc_gps_sat.length; i++) + new_gps_sat[i] = cc_gps_sat[i]; + cc_gps_sat = new_gps_sat; + } + AltosGPS.AltosGPSSat sat = new AltosGPS.AltosGPSSat(); + sat.svid = svid; + sat.c_n0 = c_n0; + cc_gps_sat[cc_gps_sat.length - 1] = sat; + } + + public AltosGPS() { + ClearGPSTime(); + cc_gps_sat = null; + } + + public AltosGPS(AltosGPS old) { + nsat = old.nsat; + locked = old.locked; + connected = old.connected; + date_valid = old.date_valid; + lat = old.lat; /* degrees (+N -S) */ + lon = old.lon; /* degrees (+E -W) */ + alt = old.alt; /* m */ + year = old.year; + month = old.month; + day = old.day; + hour = old.hour; + minute = old.minute; + second = old.second; + + gps_extended = old.gps_extended; /* has extra data */ + ground_speed = old.ground_speed; /* m/s */ + course = old.course; /* degrees */ + climb_rate = old.climb_rate; /* m/s */ + hdop = old.hdop; /* unitless? */ + h_error = old.h_error; /* m */ + v_error = old.v_error; /* m */ + + if (old.cc_gps_sat != null) { + cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length]; + for (int i = 0; i < old.cc_gps_sat.length; i++) { + cc_gps_sat[i] = new AltosGPSSat(); + cc_gps_sat[i].svid = old.cc_gps_sat[i].svid; + cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0; + } + } + } +} diff --git a/altosui/AltosGraph.java b/altosui/AltosGraph.java new file mode 100644 index 00000000..58c27979 --- /dev/null +++ b/altosui/AltosGraph.java @@ -0,0 +1,25 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.io.*; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.ChartUtilities; + +abstract class AltosGraph { + public String filename; + public abstract void addData(AltosDataPoint d); + public abstract JFreeChart createChart(); + public void toPNG() throws java.io.IOException { toPNG(300, 500); } + public void toPNG(int width, int height) + throws java.io.IOException + { + File pngout = new File(filename); + JFreeChart chart = createChart(); + ChartUtilities.saveChartAsPNG(pngout, chart, width, height); + System.out.println("Created " + filename); + } +} diff --git a/altosui/AltosGraphTime.java b/altosui/AltosGraphTime.java new file mode 100644 index 00000000..a5451280 --- /dev/null +++ b/altosui/AltosGraphTime.java @@ -0,0 +1,233 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.HashMap; + +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.AxisLocation; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.labels.StandardXYToolTipGenerator; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.plot.ValueMarker; +import org.jfree.chart.renderer.xy.StandardXYItemRenderer; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import org.jfree.ui.RectangleAnchor; +import org.jfree.ui.TextAnchor; + +class AltosGraphTime extends AltosGraph { + static interface Element { + void attachGraph(AltosGraphTime g); + void gotTimeData(double time, AltosDataPoint d); + void addToPlot(AltosGraphTime g, XYPlot plot); + } + + static class TimeAxis implements Element { + private int axis; + private Color color; + private String label; + private AxisLocation locn; + private double min_y = Double.NaN; + + public TimeAxis(int axis, String label, Color color, AxisLocation locn) + { + this.axis = axis; + this.color = color; + this.label = label; + this.locn = locn; + } + + public void setLowerBound(double min_y) { + this.min_y = min_y; + } + + public void attachGraph(AltosGraphTime g) { return; } + public void gotTimeData(double time, AltosDataPoint d) { return; } + + public void addToPlot(AltosGraphTime g, XYPlot plot) { + NumberAxis numAxis = new NumberAxis(label); + if (!Double.isNaN(min_y)) + numAxis.setLowerBound(min_y); + plot.setRangeAxis(axis, numAxis); + plot.setRangeAxisLocation(axis, locn); + numAxis.setLabelPaint(color); + numAxis.setTickLabelPaint(color); + numAxis.setAutoRangeIncludesZero(false); + } + } + + abstract static class TimeSeries implements Element { + protected XYSeries series; + private String axisName; + private Color color; + + public TimeSeries(String axisName, String label, Color color) { + this.series = new XYSeries(label); + this.axisName = axisName; + this.color = color; + } + + public void attachGraph(AltosGraphTime g) { + g.setAxis(this, axisName, color); + } + abstract public void gotTimeData(double time, AltosDataPoint d); + + public void addToPlot(AltosGraphTime g, XYPlot plot) { + XYSeriesCollection dataset = new XYSeriesCollection(); + dataset.addSeries(this.series); + + XYItemRenderer renderer = new StandardXYItemRenderer(); + renderer.setSeriesPaint(0, color); + + int dataNum = g.getDataNum(this); + int axisNum = g.getAxisNum(this); + + plot.setDataset(dataNum, dataset); + plot.mapDatasetToRangeAxis(dataNum, axisNum); + plot.setRenderer(dataNum, renderer); + } + } + + static class StateMarker implements Element { + private double val = Double.NaN; + private String name; + private int state; + + StateMarker(int state, String name) { + this.state = state; + this.name = name; + } + + public void attachGraph(AltosGraphTime g) { return; } + public void gotTimeData(double time, AltosDataPoint d) { + if (Double.isNaN(val) || time < val) { + if (d.state() == state) { + val = time; + } + } + } + + public void addToPlot(AltosGraphTime g, XYPlot plot) { + if (Double.isNaN(val)) + return; + + ValueMarker m = new ValueMarker(val); + m.setLabel(name); + m.setLabelAnchor(RectangleAnchor.TOP_RIGHT); + m.setLabelTextAnchor(TextAnchor.TOP_LEFT); + plot.addDomainMarker(m); + } + } + + private String callsign = null; + private Integer serial = null; + private Integer flight = null; + + private String title; + private ArrayList elements; + private HashMap axes; + private HashMap datasets; + private ArrayList datasetAxis; + + public AltosGraphTime(String title) { + this.filename = title.toLowerCase().replaceAll("[^a-z0-9]","_")+".png"; + this.title = title; + this.elements = new ArrayList(); + this.axes = new HashMap(); + this.datasets = new HashMap(); + this.datasetAxis = new ArrayList(); + } + + public AltosGraphTime addElement(Element e) { + e.attachGraph(this); + elements.add(e); + return this; + } + + public void setAxis(Element ds, String axisName, Color color) { + Integer axisNum = axes.get(axisName); + int dsNum = datasetAxis.size(); + if (axisNum == null) { + axisNum = newAxis(axisName, color); + } + datasets.put(ds, dsNum); + datasetAxis.add(axisNum); + } + + public int getAxisNum(Element ds) { + return datasetAxis.get( datasets.get(ds) ).intValue(); + } + public int getDataNum(Element ds) { + return datasets.get(ds).intValue(); + } + + private Integer newAxis(String name, Color color) { + int cnt = axes.size(); + AxisLocation locn = AxisLocation.BOTTOM_OR_LEFT; + if (cnt > 0) { + locn = AxisLocation.TOP_OR_RIGHT; + } + Integer res = new Integer(cnt); + axes.put(name, res); + this.addElement(new TimeAxis(cnt, name, color, locn)); + return res; + } + + public void addData(AltosDataPoint d) { + double time = d.time(); + for (Element e : elements) { + e.gotTimeData(time, d); + } + if (callsign == null) callsign = d.callsign(); + if (serial == null) serial = new Integer(d.serial()); + if (flight == null) flight = new Integer(d.flight()); + } + + public JFreeChart createChart() { + NumberAxis xAxis = new NumberAxis("Time (s)"); + xAxis.setAutoRangeIncludesZero(false); + XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); + XYPlot plot = new XYPlot(); + plot.setDomainAxis(xAxis); + plot.setRenderer(renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + + if (serial != null && flight != null) { + title = serial + "/" + flight + ": " + title; + } + if (callsign != null) { + title = callsign + " - " + title; + } + + renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, + plot, true); + ChartUtilities.applyCurrentTheme(chart); + + plot.setDomainPannable(true); + plot.setRangePannable(true); + + for (Element e : elements) { + e.addToPlot(this, plot); + } + + return chart; + } + + public void toPNG() throws java.io.IOException { + if (axes.size() > 1) { + toPNG(800, 500); + } else { + toPNG(300, 500); + } + } +} diff --git a/altosui/AltosGraphUI.java b/altosui/AltosGraphUI.java new file mode 100644 index 00000000..cd158651 --- /dev/null +++ b/altosui/AltosGraphUI.java @@ -0,0 +1,274 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.io.*; +import java.util.ArrayList; + +import javax.swing.JFrame; +import java.awt.Color; + +import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.AxisLocation; +import org.jfree.ui.ApplicationFrame; +import org.jfree.ui.RefineryUtilities; + +public class AltosGraphUI extends JFrame +{ + static final private Color red = new Color(194,31,31); + static final private Color green = new Color(31,194,31); + static final private Color blue = new Color(31,31,194); + static final private Color black = new Color(31,31,31); + + static private class OverallGraphs { + AltosGraphTime.Element height = + new AltosGraphTime.TimeSeries("Height (m)", "Height (AGL)", red) { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.height()); + } + }; + + AltosGraphTime.Element speed = + new AltosGraphTime.TimeSeries("Speed (m/s)", "Vertical Speed", green) { + public void gotTimeData(double time, AltosDataPoint d) { + if (d.state() < Altos.ao_flight_drogue) { + series.add(time, d.accel_speed()); + } else { + series.add(time, d.baro_speed()); + } + } + }; + + AltosGraphTime.Element acceleration = + new AltosGraphTime.TimeSeries("Acceleration (m/s\u00B2)", + "Axial Acceleration", blue) + { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.acceleration()); + } + }; + + AltosGraphTime.Element temperature = + new AltosGraphTime.TimeSeries("Temperature (\u00B0C)", + "Board temperature", red) + { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.temperature()); + } + }; + + AltosGraphTime.Element drogue_voltage = + new AltosGraphTime.TimeSeries("Voltage (V)", "Drogue Continuity", blue) + { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.drogue_voltage()); + } + }; + + AltosGraphTime.Element main_voltage = + new AltosGraphTime.TimeSeries("Voltage (V)", "Main Continuity", green) + { + public void gotTimeData(double time, AltosDataPoint d) { + series.add(time, d.main_voltage()); + } + }; + + AltosGraphTime.Element e_pad = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad"); + AltosGraphTime.Element e_boost = new AltosGraphTime.StateMarker(Altos.ao_flight_boost, "Boost"); + AltosGraphTime.Element e_fast = new AltosGraphTime.StateMarker(Altos.ao_flight_fast, "Fast"); + AltosGraphTime.Element e_coast = new AltosGraphTime.StateMarker(Altos.ao_flight_coast, "Coast"); + AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(Altos.ao_flight_drogue, "Drogue"); + AltosGraphTime.Element e_main = new AltosGraphTime.StateMarker(Altos.ao_flight_main, "Main"); + AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(Altos.ao_flight_landed, "Landed"); + + protected AltosGraphTime myAltosGraphTime(String suffix) { + return (new AltosGraphTime("Overall " + suffix)) + .addElement(e_boost) + .addElement(e_drogue) + .addElement(e_main) + .addElement(e_landed); + } + + public ArrayList graphs() { + ArrayList graphs = new ArrayList(); + + graphs.add( myAltosGraphTime("Summary") + .addElement(height) + .addElement(speed) + .addElement(acceleration) ); + + graphs.add( myAltosGraphTime("Altitude") + .addElement(height) ); + + graphs.add( myAltosGraphTime("Speed") + .addElement(speed) ); + + graphs.add( myAltosGraphTime("Acceleration") + .addElement(acceleration) ); + + graphs.add( myAltosGraphTime("Temperature") + .addElement(temperature) ); + + graphs.add( myAltosGraphTime("Continuity") + .addElement(drogue_voltage) + .addElement(main_voltage) ); + + return graphs; + } + } + + static private class AscentGraphs extends OverallGraphs { + protected AltosGraphTime myAltosGraphTime(String suffix) { + return (new AltosGraphTime("Ascent " + suffix) { + public void addData(AltosDataPoint d) { + int state = d.state(); + if (Altos.ao_flight_boost <= state && state <= Altos.ao_flight_coast) { + super.addData(d); + } + } + }).addElement(e_boost) + .addElement(e_fast) + .addElement(e_coast); + } + } + + static private class DescentGraphs extends OverallGraphs { + protected AltosGraphTime myAltosGraphTime(String suffix) { + return (new AltosGraphTime("Descent " + suffix) { + public void addData(AltosDataPoint d) { + int state = d.state(); + if (Altos.ao_flight_drogue <= state && state <= Altos.ao_flight_main) { + super.addData(d); + } + } + }).addElement(e_drogue) + .addElement(e_main); + // ((XYGraph)graph[8]).ymin = new Double(-50); + } + } + + public AltosGraphUI(AltosRecordIterable records) { + super("Altos Graph"); + + Iterable reader = new AltosDataPointReader (records); + if (reader == null) + return; + + init(reader, 0); + } + + public AltosGraphUI(Iterable data, int which) + { + super("Altos Graph"); + init(data, which); + } + + private void init(Iterable data, int which) { + AltosGraph graph = createGraph(data, which); + + JFreeChart chart = graph.createChart(); + ChartPanel chartPanel = new ChartPanel(chart); + chartPanel.setMouseWheelEnabled(true); + chartPanel.setPreferredSize(new java.awt.Dimension(800, 500)); + setContentPane(chartPanel); + + pack(); + + RefineryUtilities.centerFrameOnScreen(this); + + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + setVisible(true); + } + + private static AltosGraph createGraph(Iterable data, + int which) + { + return createGraphsWhich(data, which).get(0); + } + + private static ArrayList createGraphs( + Iterable data) + { + return createGraphsWhich(data, -1); + } + + private static ArrayList createGraphsWhich( + Iterable data, int which) + { + ArrayList graph = new ArrayList(); + graph.addAll((new OverallGraphs()).graphs()); + graph.addAll((new AscentGraphs()).graphs()); + graph.addAll((new DescentGraphs()).graphs()); + + if (which > 0) { + if (which >= graph.size()) { + which = 0; + } + AltosGraph g = graph.get(which); + graph = new ArrayList(); + graph.add(g); + } + + for (AltosDataPoint dp : data) { + for (AltosGraph g : graph) { + g.addData(dp); + } + } + + return graph; + } +} + +/* gnuplot bits... + * +300x400 + +-------------------------------------------------------- +TOO HARD! :) + +"ascent-gps-accuracy.png" "Vertical error margin to apogee - GPS v Baro (m)" + 5:($7 < 6 ? $24-$11 : 1/0) +"descent-gps-accuracy.png" "Vertical error margin during descent - GPS v Baro (m)" + 5:($7 < 6 ? 1/0 : $24-$11) + +set output "overall-gps-accuracy.png" +set ylabel "distance above sea level (m)" +plot "telemetry.csv" using 5:11 with lines ti "baro altitude" axis x1y1, \ + "telemetry.csv" using 5:24 with lines ti "gps altitude" axis x1y1 + +set term png tiny size 700,700 enhanced +set xlabel "m" +set ylabel "m" +set polar +set grid polar +set rrange[*:*] +set angles degrees + +set output "overall-gps-path.png" +#:30 with yerrorlines +plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0) with lines ti "pad", \ + "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0) with lines ti "boost", \ + "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0) with lines ti "fast", \ + "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0) with lines ti "coast", \ + "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \ + "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \ + "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed" + +set output "ascent-gps-path.png" +plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0):30 with lines ti "pad", \ + "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0):20 with lines ti "boost", \ + "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0):10 with lines ti "fast", \ + "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0):5 with lines ti "coast" + +set output "descent-gps-path.png" +plot "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \ + "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \ + "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed" + + */ + + diff --git a/altosui/AltosGreatCircle.java b/altosui/AltosGreatCircle.java new file mode 100644 index 00000000..fb1b6ab3 --- /dev/null +++ b/altosui/AltosGreatCircle.java @@ -0,0 +1,100 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.Math; + +public class AltosGreatCircle { + double distance; + double bearing; + + double sqr(double a) { return a * a; } + + static final double rad = Math.PI / 180; + static final double earth_radius = 6371.2 * 1000; /* in meters */ + + static int BEARING_LONG = 0; + static int BEARING_SHORT = 1; + static int BEARING_VOICE = 2; + String bearing_words(int length) { + String [][] bearing_string = { + { + "North", "North North East", "North East", "East North East", + "East", "East South East", "South East", "South South East", + "South", "South South West", "South West", "West South West", + "West", "West North West", "North West", "North North West" + }, { + "N", "NNE", "NE", "ENE", + "E", "ESE", "SE", "SSE", + "S", "SSW", "SW", "WSW", + "W", "WNW", "NW", "NNW" + }, { + "north", "nor nor east", "north east", "east nor east", + "east", "east sow east", "south east", "sow sow east", + "south", "sow sow west", "south west", "west sow west", + "west", "west nor west", "north west", "nor nor west " + } + }; + return bearing_string[length][(int)((bearing / 90 * 8 + 1) / 2)%16]; + } + + public AltosGreatCircle (double start_lat, double start_lon, + double end_lat, double end_lon) + { + double lat1 = rad * start_lat; + double lon1 = rad * -start_lon; + double lat2 = rad * end_lat; + double lon2 = rad * -end_lon; + + double d_lon = lon2 - lon1; + + /* From http://en.wikipedia.org/wiki/Great-circle_distance */ + double vdn = Math.sqrt(sqr(Math.cos(lat2) * Math.sin(d_lon)) + + sqr(Math.cos(lat1) * Math.sin(lat2) - + Math.sin(lat1) * Math.cos(lat2) * Math.cos(d_lon))); + double vdd = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(d_lon); + double d = Math.atan2(vdn,vdd); + double course; + + if (Math.cos(lat1) < 1e-20) { + if (lat1 > 0) + course = Math.PI; + else + course = -Math.PI; + } else { + if (d < 1e-10) + course = 0; + else + course = Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(d)) / + (Math.sin(d)*Math.cos(lat1))); + if (Math.sin(lon2-lon1) > 0) + course = 2 * Math.PI-course; + } + distance = d * earth_radius; + bearing = course * 180/Math.PI; + } + + public AltosGreatCircle(AltosGPS start, AltosGPS end) { + this(start.lat, start.lon, end.lat, end.lon); + } + + public AltosGreatCircle() { + distance = 0; + bearing = 0; + } +} diff --git a/altosui/AltosHexfile.java b/altosui/AltosHexfile.java new file mode 100644 index 00000000..19e35ae1 --- /dev/null +++ b/altosui/AltosHexfile.java @@ -0,0 +1,252 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.LinkedList; +import java.util.Iterator; +import java.util.Arrays; + +class HexFileInputStream extends PushbackInputStream { + public int line; + + public HexFileInputStream(FileInputStream o) { + super(new BufferedInputStream(o)); + line = 1; + } + + public int read() throws IOException { + int c = super.read(); + if (c == '\n') + line++; + return c; + } + + public void unread(int c) throws IOException { + if (c == '\n') + line--; + if (c != -1) + super.unread(c); + } +} + +class HexRecord implements Comparable { + public int address; + public int type; + public byte checksum; + public byte[] data; + + static final int NORMAL = 0; + static final int EOF = 1; + static final int EXTENDED_ADDRESS = 2; + + enum read_state { + marker, + length, + address, + type, + data, + checksum, + newline, + white, + done, + } + + boolean ishex(int c) { + if ('0' <= c && c <= '9') + return true; + if ('a' <= c && c <= 'f') + return true; + if ('A' <= c && c <= 'F') + return true; + return false; + } + + boolean isspace(int c) { + switch (c) { + case ' ': + case '\t': + return true; + } + return false; + } + + int fromhex(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - 'a' + 10; + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + return -1; + } + + public byte checksum() { + byte got = 0; + + got += data.length; + got += (address >> 8) & 0xff; + got += (address ) & 0xff; + got += type; + for (int i = 0; i < data.length; i++) + got += data[i]; + return (byte) (-got); + } + + public int compareTo(Object other) { + HexRecord o = (HexRecord) other; + return address - o.address; + } + + public String toString() { + return String.format("%04x: %02x (%d)", address, type, data.length); + } + + public HexRecord(HexFileInputStream input) throws IOException { + read_state state = read_state.marker; + int nhexbytes = 0; + int hex = 0; + int ndata = 0; + byte got_checksum; + + while (state != read_state.done) { + int c = input.read(); + if (c < 0 && state != read_state.white) + throw new IOException(String.format("%d: Unexpected EOF", input.line)); + if (c == ' ') + continue; + switch (state) { + case marker: + if (c != ':') + throw new IOException("Missing ':'"); + state = read_state.length; + nhexbytes = 2; + hex = 0; + break; + case length: + case address: + case type: + case data: + case checksum: + if(!ishex(c)) + throw new IOException(String.format("Non-hex char '%c'", c)); + hex = hex << 4 | fromhex(c); + --nhexbytes; + if (nhexbytes != 0) + break; + + switch (state) { + case length: + data = new byte[hex]; + state = read_state.address; + nhexbytes = 4; + break; + case address: + address = hex; + state = read_state.type; + nhexbytes = 2; + break; + case type: + type = hex; + if (data.length > 0) + state = read_state.data; + else + state = read_state.checksum; + nhexbytes = 2; + ndata = 0; + break; + case data: + data[ndata] = (byte) hex; + ndata++; + nhexbytes = 2; + if (ndata == data.length) + state = read_state.checksum; + break; + case checksum: + checksum = (byte) hex; + state = read_state.newline; + break; + default: + break; + } + hex = 0; + break; + case newline: + if (c != '\n' && c != '\r') + throw new IOException("Missing newline"); + state = read_state.white; + break; + case white: + if (!isspace(c)) { + input.unread(c); + state = read_state.done; + } + break; + case done: + break; + } + } + got_checksum = checksum(); + if (got_checksum != checksum) + throw new IOException(String.format("Invalid checksum (read 0x%02x computed 0x%02x)\n", + checksum, got_checksum)); + } +} + +public class AltosHexfile { + public int address; + public byte[] data; + + public byte get_byte(int a) { + return data[a - address]; + } + + public AltosHexfile(FileInputStream file) throws IOException { + HexFileInputStream input = new HexFileInputStream(file); + LinkedList record_list = new LinkedList(); + boolean done = false; + + while (!done) { + HexRecord record = new HexRecord(input); + + if (record.type == HexRecord.EOF) + done = true; + else + record_list.add(record); + } + HexRecord[] records = record_list.toArray(new HexRecord[0]); + Arrays.sort(records); + if (records.length > 0) { + int base = records[0].address; + int bound = records[records.length-1].address + + records[records.length-1].data.length; + + data = new byte[bound - base]; + address = base; + Arrays.fill(data, (byte) 0xff); + + /* Paint the records into the new array */ + for (int i = 0; i < records.length; i++) { + for (int j = 0; j < records[i].data.length; j++) + data[records[i].address - base + j] = records[i].data[j]; + } + } + } +} \ No newline at end of file diff --git a/altosui/AltosIgnite.java b/altosui/AltosIgnite.java new file mode 100644 index 00000000..3cbd8a75 --- /dev/null +++ b/altosui/AltosIgnite.java @@ -0,0 +1,173 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.io.*; +import java.util.concurrent.*; + +public class AltosIgnite { + AltosDevice device; + AltosSerial serial; + boolean remote; + boolean serial_started; + final static int None = 0; + final static int Apogee = 1; + final static int Main = 2; + + final static int Unknown = 0; + final static int Ready = 1; + final static int Active = 2; + final static int Open = 3; + + private void start_serial() throws InterruptedException { + serial_started = true; + if (remote) { + serial.set_radio(); + serial.printf("p\nE 0\n"); + serial.flush_input(); + } + } + + private void stop_serial() throws InterruptedException { + if (!serial_started) + return; + serial_started = false; + if (serial == null) + return; + if (remote) { + serial.printf("~"); + serial.flush_output(); + } + } + + class string_ref { + String value; + + public String get() { + return value; + } + public void set(String i) { + value = i; + } + public string_ref() { + value = null; + } + } + + private boolean get_string(String line, String label, string_ref s) { + if (line.startsWith(label)) { + String quoted = line.substring(label.length()).trim(); + + if (quoted.startsWith("\"")) + quoted = quoted.substring(1); + if (quoted.endsWith("\"")) + quoted = quoted.substring(0,quoted.length()-1); + s.set(quoted); + return true; + } else { + return false; + } + } + + private int status(String status_name) { + if (status_name.equals("unknown")) + return Unknown; + if (status_name.equals("ready")) + return Ready; + if (status_name.equals("active")) + return Active; + if (status_name.equals("open")) + return Open; + return Unknown; + } + + public int status(int igniter) throws InterruptedException, TimeoutException { + int status = Unknown; + if (serial == null) + return status; + string_ref status_name = new string_ref(); + start_serial(); + serial.printf("t\n"); + for (;;) { + String line = serial.get_reply(5000); + if (line == null) + throw new TimeoutException(); + if (get_string(line, "Igniter: drogue Status: ", status_name)) + if (igniter == Apogee) + status = status(status_name.get()); + if (get_string(line, "Igniter: main Status: ", status_name)) { + if (igniter == Main) + status = status(status_name.get()); + break; + } + } + stop_serial(); + return status; + } + + public String status_string(int status) { + switch (status) { + case Unknown: return "Unknown"; + case Ready: return "Ready"; + case Active: return "Active"; + case Open: return "Open"; + default: return "Unknown"; + } + } + + public void fire(int igniter) { + if (serial == null) + return; + try { + start_serial(); + switch (igniter) { + case Main: + serial.printf("i DoIt main\n"); + break; + case Apogee: + serial.printf("i DoIt drogue\n"); + break; + } + } catch (InterruptedException ie) { + } finally { + try { + stop_serial(); + } catch (InterruptedException ie) { + } + } + } + + public void close() { + try { + stop_serial(); + } catch (InterruptedException ie) { + } + serial.close(); + serial = null; + } + + public AltosIgnite(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { + + device = in_device; + serial = new AltosSerial(device); + remote = false; + + if (!device.matchProduct(AltosDevice.product_telemetrum)) + remote = true; + } +} \ No newline at end of file diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java new file mode 100644 index 00000000..d542729c --- /dev/null +++ b/altosui/AltosIgniteUI.java @@ -0,0 +1,317 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import javax.swing.event.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.*; + +public class AltosIgniteUI + extends JDialog + implements ActionListener +{ + AltosDevice device; + AltosIgnite ignite; + JFrame owner; + JLabel label; + JRadioButton apogee; + JLabel apogee_status_label; + JRadioButton main; + JLabel main_status_label; + JToggleButton arm; + JButton fire; + javax.swing.Timer timer; + + int apogee_status; + int main_status; + + final static int timeout = 1 * 1000; + + int time_remaining; + boolean timer_running; + + void set_arm_text() { + if (arm.isSelected()) + arm.setText(String.format("%d", time_remaining)); + else + arm.setText("Arm"); + } + + void start_timer() { + time_remaining = 10; + set_arm_text(); + timer_running = true; + } + + void stop_timer() { + time_remaining = 0; + arm.setSelected(false); + arm.setEnabled(false); + fire.setEnabled(false); + timer_running = false; + set_arm_text(); + } + + void cancel () { + apogee.setSelected(false); + main.setSelected(false); + fire.setEnabled(false); + stop_timer(); + } + + void get_ignite_status() throws InterruptedException, TimeoutException { + apogee_status = ignite.status(AltosIgnite.Apogee); + main_status = ignite.status(AltosIgnite.Main); + } + + void set_ignite_status() throws InterruptedException, TimeoutException { + get_ignite_status(); + apogee_status_label.setText(String.format("\"%s\"", ignite.status_string(apogee_status))); + main_status_label.setText(String.format("\"%s\"", ignite.status_string(main_status))); + } + + void close() { + timer.stop(); + setVisible(false); + ignite.close(); + } + + void abort() { + close(); + JOptionPane.showMessageDialog(owner, + String.format("Connection to \"%s\" failed", + device.toShortString()), + "Connection Failed", + JOptionPane.ERROR_MESSAGE); + } + + void tick_timer() { + if (timer_running) { + --time_remaining; + if (time_remaining <= 0) + cancel(); + else + set_arm_text(); + } + try { + set_ignite_status(); + } catch (InterruptedException ie) { + abort(); + } catch (TimeoutException te) { + abort(); + } + } + + void fire() { + if (arm.isEnabled() && arm.isSelected() && time_remaining > 0) { + int igniter = AltosIgnite.None; + if (apogee.isSelected() && !main.isSelected()) + igniter = AltosIgnite.Apogee; + else if (main.isSelected() && !apogee.isSelected()) + igniter = AltosIgnite.Main; + ignite.fire(igniter); + cancel(); + } + } + + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + if (cmd.equals("apogee") || cmd.equals("main")) { + stop_timer(); + } + + if (cmd.equals("apogee") && apogee.isSelected()) { + main.setSelected(false); + arm.setEnabled(true); + } + if (cmd.equals("main") && main.isSelected()) { + apogee.setSelected(false); + arm.setEnabled(true); + } + + if (cmd.equals("arm")) { + if (arm.isSelected()) { + fire.setEnabled(true); + start_timer(); + } else + cancel(); + } + if (cmd.equals("fire")) + fire(); + if (cmd.equals("tick")) + tick_timer(); + if (cmd.equals("close")) { + close(); + } + } + + /* A window listener to catch closing events and tell the config code */ + class ConfigListener extends WindowAdapter { + AltosIgniteUI ui; + + public ConfigListener(AltosIgniteUI this_ui) { + ui = this_ui; + } + + public void windowClosing(WindowEvent e) { + ui.actionPerformed(new ActionEvent(e.getSource(), + ActionEvent.ACTION_PERFORMED, + "close")); + } + } + + private boolean open() { + device = AltosDeviceDialog.show(owner, AltosDevice.product_any); + if (device != null) { + try { + ignite = new AltosIgnite(device); + return true; + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(owner, + String.format("Cannot open device \"%s\"", + device.toShortString()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(owner, + String.format("Device \"%s\" already in use", + device.toShortString()), + "Device in use", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(owner, + device.toShortString(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } + } + return false; + } + + public AltosIgniteUI(JFrame in_owner) { + + owner = in_owner; + apogee_status = AltosIgnite.Unknown; + main_status = AltosIgnite.Unknown; + + if (!open()) + return; + + Container pane = getContentPane(); + GridBagConstraints c = new GridBagConstraints(); + Insets i = new Insets(4,4,4,4); + + timer = new javax.swing.Timer(timeout, this); + timer.setActionCommand("tick"); + timer_running = false; + timer.restart(); + + owner = in_owner; + + pane.setLayout(new GridBagLayout()); + + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + c.weightx = 1; + c.weighty = 1; + + c.gridx = 0; + c.gridy = 0; + c.gridwidth = 2; + c.anchor = GridBagConstraints.CENTER; + label = new JLabel ("Fire Igniter"); + pane.add(label, c); + + c.gridx = 0; + c.gridy = 1; + c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; + apogee = new JRadioButton ("Apogee"); + pane.add(apogee, c); + apogee.addActionListener(this); + apogee.setActionCommand("apogee"); + + c.gridx = 1; + c.gridy = 1; + c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; + apogee_status_label = new JLabel(); + pane.add(apogee_status_label, c); + + c.gridx = 0; + c.gridy = 2; + c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; + main = new JRadioButton ("Main"); + pane.add(main, c); + main.addActionListener(this); + main.setActionCommand("main"); + + c.gridx = 1; + c.gridy = 2; + c.gridwidth = 1; + c.anchor = GridBagConstraints.WEST; + main_status_label = new JLabel(); + pane.add(main_status_label, c); + + try { + set_ignite_status(); + } catch (InterruptedException ie) { + abort(); + return; + } catch (TimeoutException te) { + abort(); + return; + } + + c.gridx = 0; + c.gridy = 3; + c.gridwidth = 1; + c.anchor = GridBagConstraints.CENTER; + arm = new JToggleButton ("Arm"); + pane.add(arm, c); + arm.addActionListener(this); + arm.setActionCommand("arm"); + arm.setEnabled(false); + + c.gridx = 1; + c.gridy = 3; + c.gridwidth = 1; + c.anchor = GridBagConstraints.CENTER; + fire = new JButton ("Fire"); + fire.setEnabled(false); + pane.add(fire, c); + fire.addActionListener(this); + fire.setActionCommand("fire"); + + pack(); + setLocationRelativeTo(owner); + setVisible(true); + + addWindowListener(new ConfigListener(this)); + } +} \ No newline at end of file diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java new file mode 100644 index 00000000..723f8301 --- /dev/null +++ b/altosui/AltosInfoTable.java @@ -0,0 +1,190 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosInfoTable extends JTable { + private AltosFlightInfoTableModel model; + + private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14); + private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14); + + static final int info_columns = 3; + static final int info_rows = 17; + + int desired_row_height() { + FontMetrics infoValueMetrics = getFontMetrics(infoValueFont); + return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10; + } + + public AltosInfoTable() { + super(new AltosFlightInfoTableModel(info_rows, info_columns)); + model = (AltosFlightInfoTableModel) getModel(); + setFont(infoValueFont); + setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); + setShowGrid(true); + setRowHeight(desired_row_height()); + doLayout(); + } + + public Dimension getPreferredScrollableViewportSize() { + return getPreferredSize(); + } + + void info_reset() { + model.reset(); + } + + void info_add_row(int col, String name, String value) { + model.addRow(col, name, value); + } + + void info_add_row(int col, String name, String format, Object... parameters) { + info_add_row (col, name, String.format(format, parameters)); + } + + void info_add_deg(int col, String name, double v, int pos, int neg) { + int c = pos; + if (v < 0) { + c = neg; + v = -v; + } + double deg = Math.floor(v); + double min = (v - deg) * 60; + + info_add_row(col, name, String.format("%3.0f°%08.5f'", deg, min)); + } + + void info_finish() { + model.finish(); + } + + public void clear() { + model.clear(); + } + + public void show(AltosState state, int crc_errors) { + if (state == null) + return; + info_reset(); + info_add_row(0, "Rocket state", "%s", state.data.state()); + info_add_row(0, "Callsign", "%s", state.data.callsign); + info_add_row(0, "Rocket serial", "%6d", state.data.serial); + info_add_row(0, "Rocket flight", "%6d", state.data.flight); + + info_add_row(0, "RSSI", "%6d dBm", state.data.rssi); + info_add_row(0, "CRC Errors", "%6d", crc_errors); + info_add_row(0, "Height", "%6.0f m", state.height); + info_add_row(0, "Max height", "%6.0f m", state.max_height); + info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration); + info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration); + info_add_row(0, "Speed", "%8.1f m/s", state.ascent ? state.speed : state.baro_speed); + info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed); + info_add_row(0, "Temperature", "%9.2f °C", state.temperature); + info_add_row(0, "Battery", "%9.2f V", state.battery); + info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense); + info_add_row(0, "Main", "%9.2f V", state.main_sense); + info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude); + if (state.gps == null) { + info_add_row(1, "GPS", "not available"); + } else { + if (state.gps_ready) + info_add_row(1, "GPS state", "%s", "ready"); + else + info_add_row(1, "GPS state", "wait (%d)", + state.gps_waiting); + if (state.data.gps.locked) + info_add_row(1, "GPS", " locked"); + else if (state.data.gps.connected) + 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); + + /* The SkyTraq GPS doesn't report these values */ + if (false) { + info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°", + state.gps.ground_speed, + state.gps.course); + info_add_row(1, "GPS climb rate", "%8.1f m/s", + state.gps.climb_rate); + info_add_row(1, "GPS error", "%6d m(h)%3d m(v)", + state.gps.h_error, state.gps.v_error); + } + info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop); + + if (state.npad > 0) { + if (state.from_pad != null) { + info_add_row(1, "Distance from pad", "%6d m", + (int) (state.from_pad.distance + 0.5)); + info_add_row(1, "Direction from pad", "%6d°", + (int) (state.from_pad.bearing + 0.5)); + info_add_row(1, "Elevation from pad", "%6d°", + (int) (state.elevation + 0.5)); + info_add_row(1, "Range from pad", "%6d m", + (int) (state.range + 0.5)); + } else { + info_add_row(1, "Distance from pad", "unknown"); + info_add_row(1, "Direction from pad", "unknown"); + info_add_row(1, "Elevation from pad", "unknown"); + info_add_row(1, "Range from pad", "unknown"); + } + info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); + 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); + int nsat_vis = 0; + int c; + + if (state.gps.cc_gps_sat == null) + info_add_row(2, "Satellites Visible", "%4d", 0); + else { + info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length); + for (c = 0; c < state.gps.cc_gps_sat.length; c++) { + info_add_row(2, "Satellite id,C/N0", + "%4d, %4d", + state.gps.cc_gps_sat[c].svid, + state.gps.cc_gps_sat[c].c_n0); + } + } + } + info_finish(); + } +} diff --git a/altosui/AltosKML.java b/altosui/AltosKML.java new file mode 100644 index 00000000..d586033f --- /dev/null +++ b/altosui/AltosKML.java @@ -0,0 +1,169 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.text.*; +import java.util.*; + +public class AltosKML implements AltosWriter { + + File name; + PrintStream out; + int state = -1; + AltosRecord prev = null; + + static final String[] kml_state_colors = { + "FF000000", + "FF000000", + "FF000000", + "FF0000FF", + "FF4080FF", + "FF00FFFF", + "FFFF0000", + "FF00FF00", + "FF000000", + "FFFFFFFF" + }; + + static final String kml_header_start = + "\n" + + "\n" + + "\n" + + " AO Flight#%d S/N: %03d\n" + + " \n"; + static final String kml_header_end = + " \n" + + " 0\n"; + + static final String kml_style_start = + " \n"; + + static final String kml_placemark_start = + " \n" + + " %s\n" + + " #ao-flightstate-%s\n" + + " \n" + + " 1\n" + + " absolute\n" + + " \n"; + + static final String kml_coord_fmt = + " %12.7f, %12.7f, %12.7f \n"; + + static final String kml_placemark_end = + " \n" + + " \n" + + " \n"; + + static final String kml_footer = + "\n" + + "\n"; + + void start (AltosRecord 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); + out.printf("Time: %2d:%02d:%02d\n", + record.gps.hour, record.gps.minute, record.gps.second); + out.printf("%s", kml_header_end); + } + + 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]); + 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) { + out.printf("%s", kml_placemark_end); + } + + void coord(AltosRecord record) { + AltosGPS gps = record.gps; + out.printf(kml_coord_fmt, + gps.lon, gps.lat, + record.filtered_altitude(), (double) gps.alt, + record.time, gps.nsat); + } + + void end() { + out.printf("%s", kml_footer); + } + + public void close() { + if (prev != null) { + state_end(prev); + end(); + prev = null; + } + } + + public void write(AltosRecord record) { + AltosGPS gps = record.gps; + + if (gps == null) + return; + if (!started) { + start(record); + started = true; + } + if (prev != null && + prev.gps.second == record.gps.second && + prev.gps.minute == record.gps.minute && + prev.gps.hour == record.gps.hour) + return; + if (record.state != state) { + state = record.state; + if (prev != null) { + coord(record); + state_end(prev); + } + state_start(record); + } + coord(record); + prev = record; + } + + public void write(AltosRecordIterable iterable) { + for (AltosRecord record : iterable) + write(record); + } + + public AltosKML(File in_name) throws FileNotFoundException { + name = in_name; + out = new PrintStream(name); + } + + public AltosKML(String in_string) throws FileNotFoundException { + this(new File(in_string)); + } +} diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java new file mode 100644 index 00000000..d34efe6d --- /dev/null +++ b/altosui/AltosLanded.java @@ -0,0 +1,212 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosLanded extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + Font label_font; + Font value_font; + + public class LandedValue { + JLabel label; + JTextField value; + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + } + + void show(String format, double v) { + value.setText(String.format(format, v)); + } + + public LandedValue (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 0; c.gridy = y; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + c.weightx = 0; + c.fill = GridBagConstraints.VERTICAL; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(Altos.text_width); + value.setFont(value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 1; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.weightx = 1; + c.fill = GridBagConstraints.BOTH; + layout.setConstraints(value, c); + add(value); + } + } + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } + + class Lat extends LandedValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lat,"N", "S")); + else + value.setText("???"); + } + public Lat (GridBagLayout layout, int y) { + super (layout, y, "Latitude"); + } + } + + Lat lat; + + class Lon extends LandedValue { + void show (AltosState state, int crc_errors) { + if (state.gps != null) + value.setText(pos(state.gps.lon,"E", "W")); + else + value.setText("???"); + } + public Lon (GridBagLayout layout, int y) { + super (layout, y, "Longitude"); + } + } + + Lon lon; + + class Bearing extends LandedValue { + void show (AltosState state, int crc_errors) { + if (state.from_pad != null) + show("%3.0f°", state.from_pad.bearing); + else + value.setText("???"); + } + public Bearing (GridBagLayout layout, int y) { + super (layout, y, "Bearing"); + } + } + + Bearing bearing; + + class Distance extends LandedValue { + void show (AltosState state, int crc_errors) { + if (state.from_pad != null) + show("%6.0f m", state.from_pad.distance); + else + value.setText("???"); + } + public Distance (GridBagLayout layout, int y) { + super (layout, y, "Distance"); + } + } + + Distance distance; + + class Height extends LandedValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m", state.max_height); + } + public Height (GridBagLayout layout, int y) { + super (layout, y, "Maximum Height"); + } + } + + Height height; + + class Speed extends LandedValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m/s", state.max_speed); + } + public Speed (GridBagLayout layout, int y) { + super (layout, y, "Maximum Speed"); + } + } + + Speed speed; + + class Accel extends LandedValue { + void show (AltosState state, int crc_errors) { + show("%6.0f m/s²", state.max_acceleration); + } + public Accel (GridBagLayout layout, int y) { + super (layout, y, "Maximum Acceleration"); + } + } + + Accel accel; + + public void reset() { + lat.reset(); + lon.reset(); + bearing.reset(); + distance.reset(); + height.reset(); + speed.reset(); + accel.reset(); + } + + public void show(AltosState state, int crc_errors) { + bearing.show(state, crc_errors); + distance.show(state, crc_errors); + lat.show(state, crc_errors); + lon.show(state, crc_errors); + height.show(state, crc_errors); + speed.show(state, crc_errors); + accel.show(state, crc_errors); + } + + public AltosLanded() { + layout = new GridBagLayout(); + + label_font = new Font("Dialog", Font.PLAIN, 22); + value_font = new Font("Monospaced", Font.PLAIN, 22); + setLayout(layout); + + /* Elements in descent display */ + bearing = new Bearing(layout, 0); + distance = new Distance(layout, 1); + lat = new Lat(layout, 2); + lon = new Lon(layout, 3); + height = new Height(layout, 4); + speed = new Speed(layout, 5); + accel = new Accel(layout, 6); + } +} diff --git a/altosui/AltosLed.java b/altosui/AltosLed.java new file mode 100644 index 00000000..e08e9960 --- /dev/null +++ b/altosui/AltosLed.java @@ -0,0 +1,54 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosLed extends JLabel { + ImageIcon on, off; + + ImageIcon create_icon(String path) { + java.net.URL imgURL = AltosUI.class.getResource(path); + if (imgURL != null) + return new ImageIcon(imgURL); + System.err.printf("Cannot find icon \"%s\"\n", path); + return null; + } + + public void set(boolean set) { + if (set) + setIcon(on); + else + setIcon(off); + } + + public AltosLed(String on_path, String off_path) { + on = create_icon(on_path); + off = create_icon(off_path); + setIcon(off); + } +} diff --git a/altosui/AltosLights.java b/altosui/AltosLights.java new file mode 100644 index 00000000..2fa38412 --- /dev/null +++ b/altosui/AltosLights.java @@ -0,0 +1,73 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosLights extends JComponent { + + GridBagLayout gridbag; + + AltosLed red, green; + + ImageIcon create_icon(String path, String description) { + java.net.URL imgURL = AltosUI.class.getResource(path); + if (imgURL != null) + return new ImageIcon(imgURL, description); + System.err.printf("Cannot find icon \"%s\"\n", path); + return null; + } + + public void set (boolean on) { + if (on) { + red.set(false); + green.set(true); + } else { + red.set(true); + green.set(false); + } + } + + public AltosLights() { + GridBagConstraints c; + gridbag = new GridBagLayout(); + setLayout(gridbag); + + c = new GridBagConstraints(); + red = new AltosLed("/redled.png", "/grayled.png"); + c.gridx = 0; c.gridy = 0; + c.insets = new Insets (0, 5, 0, 5); + gridbag.setConstraints(red, c); + add(red); + red.set(true); + green = new AltosLed("/greenled.png", "/grayled.png"); + c.gridx = 1; c.gridy = 0; + gridbag.setConstraints(green, c); + add(green); + green.set(false); + } +} diff --git a/altosui/AltosLine.java b/altosui/AltosLine.java new file mode 100644 index 00000000..86e9d4c6 --- /dev/null +++ b/altosui/AltosLine.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +public class AltosLine { + public String line; + + public AltosLine() { + line = null; + } + + public AltosLine(String s) { + line = s; + } +} \ No newline at end of file diff --git a/altosui/AltosLog.java b/altosui/AltosLog.java new file mode 100644 index 00000000..dd147d21 --- /dev/null +++ b/altosui/AltosLog.java @@ -0,0 +1,115 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.io.*; +import java.lang.*; +import java.util.*; +import java.text.ParseException; +import java.util.concurrent.LinkedBlockingQueue; + +/* + * This creates a thread to capture telemetry data and write it to + * a log file + */ +class AltosLog implements Runnable { + + LinkedBlockingQueue input_queue; + LinkedBlockingQueue pending_queue; + int serial; + int flight; + FileWriter log_file; + Thread log_thread; + + private void close_log_file() { + if (log_file != null) { + try { + log_file.close(); + } catch (IOException io) { + } + log_file = null; + } + } + + void close() { + close_log_file(); + if (log_thread != null) { + log_thread.interrupt(); + log_thread = null; + } + } + + boolean open (AltosTelemetry telem) throws IOException { + AltosFile a = new AltosFile(telem); + + log_file = new FileWriter(a, true); + if (log_file != null) { + while (!pending_queue.isEmpty()) { + try { + String s = pending_queue.take(); + log_file.write(s); + log_file.write('\n'); + } catch (InterruptedException ie) { + } + } + log_file.flush(); + } + return log_file != null; + } + + public void run () { + try { + for (;;) { + AltosLine line = input_queue.take(); + if (line.line == null) + continue; + try { + AltosTelemetry telem = new AltosTelemetry(line.line); + if (telem.serial != serial || telem.flight != flight || log_file == null) { + close_log_file(); + serial = telem.serial; + flight = telem.flight; + open(telem); + } + } catch (ParseException pe) { + } catch (AltosCRCException ce) { + } + if (log_file != null) { + log_file.write(line.line); + log_file.write('\n'); + log_file.flush(); + } else + pending_queue.put(line.line); + } + } catch (InterruptedException ie) { + } catch (IOException ie) { + } + close(); + } + + public AltosLog (AltosSerial s) { + pending_queue = new LinkedBlockingQueue (); + input_queue = new LinkedBlockingQueue (); + s.add_monitor(input_queue); + serial = -1; + flight = -1; + log_file = null; + log_thread = new Thread(this); + log_thread.start(); + } +} diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java new file mode 100644 index 00000000..66954347 --- /dev/null +++ b/altosui/AltosPad.java @@ -0,0 +1,269 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosPad extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + + public class LaunchStatus { + JLabel label; + JTextField value; + AltosLights lights; + + void show(AltosState state, int crc_errors) {} + void reset() { + value.setText(""); + lights.set(false); + } + + public LaunchStatus (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + lights = new AltosLights(); + c.gridx = 0; c.gridy = y; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(lights, c); + add(lights); + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(Altos.text_width); + value.setFont(Altos.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + + } + } + + public class LaunchValue { + JLabel label; + JTextField value; + void show(AltosState state, int crc_errors) {} + + void reset() { + value.setText(""); + } + public LaunchValue (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(Altos.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(Altos.text_width); + value.setFont(Altos.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + } + } + + class Battery extends LaunchStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.battery)); + lights.set(state.battery > 3.7); + } + public Battery (GridBagLayout layout, int y) { + super(layout, y, "Battery Voltage"); + } + } + + Battery battery; + + class Apogee extends LaunchStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.drogue_sense)); + lights.set(state.drogue_sense > 3.2); + } + public Apogee (GridBagLayout layout, int y) { + super(layout, y, "Apogee Igniter Voltage"); + } + } + + Apogee apogee; + + class Main extends LaunchStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.2f V", state.main_sense)); + lights.set(state.main_sense > 3.2); + } + public Main (GridBagLayout layout, int y) { + super(layout, y, "Main Igniter Voltage"); + } + } + + Main main; + + class GPSLocked extends LaunchStatus { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4d sats", state.gps.nsat)); + lights.set(state.gps.locked); + } + public GPSLocked (GridBagLayout layout, int y) { + super (layout, y, "GPS Locked"); + } + } + + GPSLocked gps_locked; + + class GPSReady extends LaunchStatus { + void show (AltosState state, int crc_errors) { + if (state.gps_ready) + value.setText("Ready"); + else + value.setText(String.format("Waiting %d", state.gps_waiting)); + lights.set(state.gps_ready); + } + public GPSReady (GridBagLayout layout, int y) { + super (layout, y, "GPS Ready"); + } + } + + GPSReady gps_ready; + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } + + class PadLat extends LaunchValue { + void show (AltosState state, int crc_errors) { + value.setText(pos(state.pad_lat,"N", "S")); + } + public PadLat (GridBagLayout layout, int y) { + super (layout, y, "Pad Latitude"); + } + } + + PadLat pad_lat; + + class PadLon extends LaunchValue { + void show (AltosState state, int crc_errors) { + value.setText(pos(state.pad_lon,"E", "W")); + } + public PadLon (GridBagLayout layout, int y) { + super (layout, y, "Pad Longitude"); + } + } + + PadLon pad_lon; + + class PadAlt extends LaunchValue { + void show (AltosState state, int crc_errors) { + value.setText(String.format("%4.0f m", state.pad_alt)); + } + public PadAlt (GridBagLayout layout, int y) { + super (layout, y, "Pad Altitude"); + } + } + + PadAlt pad_alt; + + public void reset() { + battery.reset(); + apogee.reset(); + main.reset(); + gps_locked.reset(); + gps_ready.reset(); + pad_lat.reset(); + pad_lon.reset(); + pad_alt.reset(); + } + + public void show(AltosState state, int crc_errors) { + battery.show(state, crc_errors); + apogee.show(state, crc_errors); + main.show(state, crc_errors); + gps_locked.show(state, crc_errors); + gps_ready.show(state, crc_errors); + pad_lat.show(state, crc_errors); + pad_lon.show(state, crc_errors); + pad_alt.show(state, crc_errors); + } + + public AltosPad() { + layout = new GridBagLayout(); + + setLayout(layout); + + /* Elements in pad display: + * + * Battery voltage + * Igniter continuity + * GPS lock status + * GPS ready status + * GPS location + * Pad altitude + * RSSI + */ + battery = new Battery(layout, 0); + apogee = new Apogee(layout, 1); + main = new Main(layout, 2); + gps_locked = new GPSLocked(layout, 3); + gps_ready = new GPSReady(layout, 4); + pad_lat = new PadLat(layout, 5); + pad_lon = new PadLon(layout, 6); + pad_alt = new PadAlt(layout, 7); + } +} diff --git a/altosui/AltosParse.java b/altosui/AltosParse.java new file mode 100644 index 00000000..fbfcaaee --- /dev/null +++ b/altosui/AltosParse.java @@ -0,0 +1,79 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.text.*; +import java.lang.*; + +public class AltosParse { + static boolean isdigit(char c) { + return '0' <= c && c <= '9'; + } + + static int parse_int(String v) throws ParseException { + try { + return Altos.fromdec(v); + } catch (NumberFormatException e) { + throw new ParseException("error parsing int " + v, 0); + } + } + + static int parse_hex(String v) throws ParseException { + try { + return Altos.fromhex(v); + } catch (NumberFormatException e) { + throw new ParseException("error parsing hex " + v, 0); + } + } + + static double parse_double(String v) throws ParseException { + try { + return Double.parseDouble(v); + } catch (NumberFormatException e) { + throw new ParseException("error parsing double " + v, 0); + } + } + + static double parse_coord(String coord) throws ParseException { + String[] dsf = coord.split("\\D+"); + + if (dsf.length != 3) { + throw new ParseException("error parsing coord " + coord, 0); + } + int deg = parse_int(dsf[0]); + int min = parse_int(dsf[1]); + int frac = parse_int(dsf[2]); + + double r = deg + (min + frac / 10000.0) / 60.0; + if (coord.endsWith("S") || coord.endsWith("W")) + r = -r; + return r; + } + + static String strip_suffix(String v, String suffix) { + if (v.endsWith(suffix)) + return v.substring(0, v.length() - suffix.length()); + return v; + } + + static void word(String v, String m) throws ParseException { + if (!v.equals(m)) { + throw new ParseException("error matching '" + v + "' '" + m + "'", 0); + } + } +} diff --git a/altosui/AltosPreferences.java b/altosui/AltosPreferences.java new file mode 100644 index 00000000..e2a3df3b --- /dev/null +++ b/altosui/AltosPreferences.java @@ -0,0 +1,205 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.awt.Component; +import javax.swing.*; +import javax.swing.filechooser.FileSystemView; + +class AltosPreferences { + static Preferences preferences; + + /* logdir preference name */ + final static String logdirPreference = "LOGDIR"; + + /* channel preference name */ + final static String channelPreferenceFormat = "CHANNEL-%d"; + + /* voice preference name */ + final static String voicePreference = "VOICE"; + + /* callsign preference name */ + final static String callsignPreference = "CALLSIGN"; + + /* firmware directory preference name */ + final static String firmwaredirPreference = "FIRMWARE"; + + /* Default logdir is ~/TeleMetrum */ + final static String logdirName = "TeleMetrum"; + + /* UI Component to pop dialogs up */ + static Component component; + + /* Log directory */ + static File logdir; + + /* Channel (map serial to channel) */ + static Hashtable channels; + + /* Voice preference */ + static boolean voice; + + /* Callsign preference */ + static String callsign; + + /* Firmware directory */ + static File firmwaredir; + + public static void init(Component ui) { + preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); + + component = ui; + + /* Initialize logdir from preferences */ + String logdir_string = preferences.get(logdirPreference, null); + if (logdir_string != null) + logdir = new File(logdir_string); + else { + /* Use the file system view default directory */ + logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName); + if (!logdir.exists()) + logdir.mkdirs(); + } + + channels = new Hashtable(); + + voice = preferences.getBoolean(voicePreference, true); + + callsign = preferences.get(callsignPreference,"N0CALL"); + + String firmwaredir_string = preferences.get(firmwaredirPreference, null); + if (firmwaredir_string != null) + firmwaredir = new File(firmwaredir_string); + else + firmwaredir = null; + } + + static void flush_preferences() { + try { + preferences.flush(); + } catch (BackingStoreException ee) { + JOptionPane.showMessageDialog(component, + preferences.absolutePath(), + "Cannot save prefernces", + JOptionPane.ERROR_MESSAGE); + } + } + + public static void set_logdir(File new_logdir) { + logdir = new_logdir; + synchronized (preferences) { + preferences.put(logdirPreference, logdir.getPath()); + flush_preferences(); + } + } + + private static boolean check_dir(File dir) { + if (!dir.exists()) { + if (!dir.mkdirs()) { + JOptionPane.showMessageDialog(component, + dir.getName(), + "Cannot create directory", + JOptionPane.ERROR_MESSAGE); + return false; + } + } else if (!dir.isDirectory()) { + JOptionPane.showMessageDialog(component, + dir.getName(), + "Is not a directory", + JOptionPane.ERROR_MESSAGE); + return false; + } + return true; + } + + /* Configure the log directory. This is where all telemetry and eeprom files + * will be written to, and where replay will look for telemetry files + */ + public static void ConfigureLog() { + JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile()); + + logdir_chooser.setDialogTitle("Configure Data Logging Directory"); + logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + + if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) { + File dir = logdir_chooser.getSelectedFile(); + if (check_dir(dir)) + set_logdir(dir); + } + } + + public static File logdir() { + return logdir; + } + + public static void set_channel(int serial, int new_channel) { + channels.put(serial, new_channel); + synchronized (preferences) { + preferences.putInt(String.format(channelPreferenceFormat, serial), new_channel); + flush_preferences(); + } + } + + public static int channel(int serial) { + if (channels.containsKey(serial)) + return channels.get(serial); + int channel = preferences.getInt(String.format(channelPreferenceFormat, serial), 0); + channels.put(serial, channel); + return channel; + } + + public static void set_voice(boolean new_voice) { + voice = new_voice; + synchronized (preferences) { + preferences.putBoolean(voicePreference, voice); + flush_preferences(); + } + } + + public static boolean voice() { + return voice; + } + + public static void set_callsign(String new_callsign) { + callsign = new_callsign; + synchronized(preferences) { + preferences.put(callsignPreference, callsign); + flush_preferences(); + } + } + + public static String callsign() { + return callsign; + } + + public static void set_firmwaredir(File new_firmwaredir) { + firmwaredir = new_firmwaredir; + synchronized (preferences) { + preferences.put(firmwaredirPreference, firmwaredir.getPath()); + flush_preferences(); + } + } + + public static File firmwaredir() { + return firmwaredir; + } +} diff --git a/altosui/AltosReader.java b/altosui/AltosReader.java new file mode 100644 index 00000000..b9280a0c --- /dev/null +++ b/altosui/AltosReader.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.io.*; +import java.util.*; +import java.text.*; + +public class AltosReader { + public AltosRecord read() throws IOException, ParseException { return null; } + public void close() { } + public void write_comments(PrintStream out) { } +} diff --git a/altosui/AltosRecord.java b/altosui/AltosRecord.java new file mode 100644 index 00000000..1160a273 --- /dev/null +++ b/altosui/AltosRecord.java @@ -0,0 +1,219 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; +import java.util.HashMap; +import java.io.*; + +public class AltosRecord { + int version; + String callsign; + int serial; + int flight; + int rssi; + int status; + int state; + int tick; + int accel; + int pres; + int temp; + int batt; + int drogue; + int main; + int flight_accel; + int ground_accel; + int flight_vel; + int flight_pres; + int ground_pres; + int accel_plus_g; + int accel_minus_g; + AltosGPS gps; + + double time; /* seconds since boost */ + + /* + * 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 raw_pressure() { + return barometer_to_pressure(pres); + } + + public double filtered_pressure() { + return barometer_to_pressure(flight_pres); + } + + public double ground_pressure() { + return barometer_to_pressure(ground_pres); + } + + public double filtered_altitude() { + return AltosConvert.pressure_to_altitude(filtered_pressure()); + } + + public double raw_altitude() { + return AltosConvert.pressure_to_altitude(raw_pressure()); + } + + public double ground_altitude() { + return AltosConvert.pressure_to_altitude(ground_pressure()); + } + + public double filtered_height() { + return filtered_altitude() - ground_altitude(); + } + + public double raw_height() { + return raw_altitude() - ground_altitude(); + } + + public double battery_voltage() { + return AltosConvert.cc_battery_to_voltage(batt); + } + + public double main_voltage() { + return AltosConvert.cc_ignitor_to_voltage(main); + } + + public double drogue_voltage() { + 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() { + 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() { + return (ground_accel - accel) / accel_counts_per_mss(); + } + + public double accel_speed() { + double speed = flight_vel / (accel_counts_per_mss() * 100.0); + return speed; + } + + public String state() { + return Altos.state_name(state); + } + + public static String gets(FileInputStream s) throws IOException { + int c; + String line = ""; + + while ((c = s.read()) != -1) { + if (c == '\r') + continue; + if (c == '\n') { + return line; + } + line = line + (char) c; + } + return null; + } + + public AltosRecord(AltosRecord 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; + gps = new AltosGPS(old.gps); + } + + public AltosRecord() { + version = 0; + callsign = "N0CALL"; + serial = 0; + flight = 0; + rssi = 0; + status = 0; + state = Altos.ao_flight_startup; + tick = 0; + accel = 0; + pres = 0; + temp = 0; + batt = 0; + drogue = 0; + main = 0; + flight_accel = 0; + ground_accel = 0; + flight_vel = 0; + flight_pres = 0; + ground_pres = 0; + accel_plus_g = 0; + accel_minus_g = 0; + gps = new AltosGPS(); + } +} diff --git a/altosui/AltosRecordIterable.java b/altosui/AltosRecordIterable.java new file mode 100644 index 00000000..a7df92d1 --- /dev/null +++ b/altosui/AltosRecordIterable.java @@ -0,0 +1,34 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +public abstract class AltosRecordIterable implements Iterable { + public abstract Iterator iterator(); + public void write_comments(PrintStream out) { } +} diff --git a/altosui/AltosReplayReader.java b/altosui/AltosReplayReader.java new file mode 100644 index 00000000..4e5e1d93 --- /dev/null +++ b/altosui/AltosReplayReader.java @@ -0,0 +1,57 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +/* + * Open an existing telemetry file and replay it in realtime + */ + +public class AltosReplayReader extends AltosFlightReader { + Iterator iterator; + + public AltosRecord read() { + if (iterator.hasNext()) + return iterator.next(); + return null; + } + + public void close (boolean interrupted) { + } + + void update(AltosState state) throws InterruptedException { + /* Make it run in realtime after the rocket leaves the pad */ + if (state.state > Altos.ao_flight_pad) + Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); + } + + public AltosReplayReader(Iterator in_iterator, String in_name) { + iterator = in_iterator; + name = in_name; + } +} diff --git a/altosui/AltosRomconfig.java b/altosui/AltosRomconfig.java new file mode 100644 index 00000000..55056b5e --- /dev/null +++ b/altosui/AltosRomconfig.java @@ -0,0 +1,147 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; +import java.io.*; + +public class AltosRomconfig { + public boolean valid; + public int version; + public int check; + public int serial_number; + public int radio_calibration; + + static int get_int(byte[] bytes, int start, int len) { + int v = 0; + int o = 0; + while (len > 0) { + v = v | ((((int) bytes[start]) & 0xff) << o); + start++; + len--; + o += 8; + } + return v; + } + + static void put_int(int value, byte[] bytes, int start, int len) { + while (len > 0) { + bytes[start] = (byte) (value & 0xff); + start++; + len--; + value >>= 8; + } + } + + static void put_string(String value, byte[] bytes, int start) { + for (int i = 0; i < value.length(); i++) + bytes[start + i] = (byte) value.charAt(i); + } + + static final int AO_USB_DESC_STRING = 3; + + static void put_usb_serial(int value, byte[] bytes, int start) { + int offset = start + 0xa; + int string_num = 0; + + while (offset < bytes.length && bytes[offset] != 0) { + if (bytes[offset + 1] == AO_USB_DESC_STRING) { + ++string_num; + if (string_num == 4) + break; + } + offset += ((int) bytes[offset]) & 0xff; + } + if (offset >= bytes.length || bytes[offset] == 0) + return; + int len = ((((int) bytes[offset]) & 0xff) - 2) / 2; + String fmt = String.format("%%0%dd", len); + + String s = String.format(fmt, value); + if (s.length() != len) { + System.out.printf("weird usb length issue %s isn't %d\n", + s, len); + return; + } + for (int i = 0; i < len; i++) { + bytes[offset + 2 + i*2] = (byte) s.charAt(i); + bytes[offset + 2 + i*2+1] = 0; + } + } + + public AltosRomconfig(byte[] bytes, int offset) { + version = get_int(bytes, offset + 0, 2); + check = get_int(bytes, offset + 2, 2); + if (check == (~version & 0xffff)) { + switch (version) { + case 2: + case 1: + serial_number = get_int(bytes, offset + 4, 2); + radio_calibration = get_int(bytes, offset + 6, 4); + valid = true; + break; + } + } + } + + public AltosRomconfig(AltosHexfile hexfile) { + this(hexfile.data, 0xa0 - hexfile.address); + } + + public void write(byte[] bytes, int offset) throws IOException { + if (!valid) + throw new IOException("rom configuration invalid"); + + if (offset < 0 || bytes.length < offset + 10) + throw new IOException("image cannot contain rom config"); + + AltosRomconfig existing = new AltosRomconfig(bytes, offset); + if (!existing.valid) + throw new IOException("image does not contain existing rom config"); + + switch (existing.version) { + case 2: + put_usb_serial(serial_number, bytes, offset); + case 1: + put_int(serial_number, bytes, offset + 4, 2); + put_int(radio_calibration, bytes, offset + 6, 4); + break; + } + } + + public void write (AltosHexfile hexfile) throws IOException { + write(hexfile.data, 0xa0 - hexfile.address); + AltosRomconfig check = new AltosRomconfig(hexfile); + if (!check.valid()) + throw new IOException("writing new rom config failed\n"); + } + + public AltosRomconfig(int in_serial_number, int in_radio_calibration) { + valid = true; + version = 1; + check = (~version & 0xffff); + serial_number = in_serial_number; + radio_calibration = in_radio_calibration; + } + + public boolean valid() { + return valid && serial_number != 0; + } + + public AltosRomconfig() { + valid = false; + } +} diff --git a/altosui/AltosRomconfigUI.java b/altosui/AltosRomconfigUI.java new file mode 100644 index 00000000..e1dc974e --- /dev/null +++ b/altosui/AltosRomconfigUI.java @@ -0,0 +1,186 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import javax.swing.event.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; + +public class AltosRomconfigUI + extends JDialog + implements ActionListener +{ + Container pane; + Box box; + JLabel serial_label; + JLabel radio_calibration_label; + + JFrame owner; + JTextField serial_value; + JTextField radio_calibration_value; + + JButton ok; + JButton cancel; + + /* Build the UI using a grid bag */ + public AltosRomconfigUI(JFrame in_owner) { + super (in_owner, "Configure TeleMetrum Rom Values", true); + + owner = in_owner; + GridBagConstraints c; + + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + /* Serial */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 0; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JTextField("0"); + pane.add(serial_value, c); + + /* Radio calibration value */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 1; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_calibration_label = new JLabel("Radio Calibration:"); + pane.add(radio_calibration_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 1; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_calibration_value = new JTextField("1186611"); + pane.add(radio_calibration_value, c); + + /* Buttons */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 2; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + ok = new JButton("OK"); + pane.add(ok, c); + ok.addActionListener(this); + ok.setActionCommand("ok"); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 2; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + cancel = new JButton("Cancel"); + pane.add(cancel, c); + cancel.addActionListener(this); + cancel.setActionCommand("cancel"); + + pack(); + setLocationRelativeTo(owner); + } + + boolean selected; + + /* Listen for events from our buttons */ + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + + if (cmd.equals("ok")) { + AltosRomconfig romconfig = romconfig(); + if (romconfig == null || !romconfig.valid()) { + JOptionPane.showMessageDialog(this, + "Invalid serial number or radio calibration value", + "Invalid rom configuration", + JOptionPane.ERROR_MESSAGE); + return; + } + selected = true; + } + setVisible(false); + } + + int serial() { + return Integer.parseInt(serial_value.getText()); + } + + void set_serial(int serial) { + serial_value.setText(String.format("%d", serial)); + } + + int radio_calibration() { + return Integer.parseInt(radio_calibration_value.getText()); + } + + void set_radio_calibration(int calibration) { + radio_calibration_value.setText(String.format("%d", calibration)); + } + + public void set(AltosRomconfig config) { + if (config != null && config.valid()) { + set_serial(config.serial_number); + set_radio_calibration(config.radio_calibration); + } + } + + AltosRomconfig romconfig() { + try { + return new AltosRomconfig(serial(), radio_calibration()); + } catch (NumberFormatException ne) { + return null; + } + } + + public AltosRomconfig showDialog() { + setVisible(true); + if (selected) + return romconfig(); + return null; + } +} diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java new file mode 100644 index 00000000..b19143e5 --- /dev/null +++ b/altosui/AltosSerial.java @@ -0,0 +1,253 @@ +/* + * Copyright © 2010 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. + */ + +/* + * Deal with TeleDongle on a serial port + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.util.concurrent.*; +import java.util.*; + +import libaltosJNI.*; + +/* + * This class reads from the serial port and places each received + * line in a queue. Dealing with that queue is left up to other + * threads. + */ + +public class AltosSerial implements Runnable { + + static List devices_opened = Collections.synchronizedList(new LinkedList()); + + AltosDevice device; + SWIGTYPE_p_altos_file altos; + LinkedList> monitors; + LinkedBlockingQueue reply_queue; + Thread input_thread; + String line; + byte[] line_bytes; + int line_count; + boolean monitor_mode; + + public void run () { + int c; + + try { + for (;;) { + c = libaltos.altos_getchar(altos, 0); + if (Thread.interrupted()) + break; + if (c == libaltosConstants.LIBALTOS_ERROR) { + for (int e = 0; e < monitors.size(); e++) { + LinkedBlockingQueue q = monitors.get(e); + q.put(new AltosLine()); + } + reply_queue.put (new AltosLine()); + break; + } + if (c == libaltosConstants.LIBALTOS_TIMEOUT) + continue; + if (c == '\r') + continue; + synchronized(this) { + if (c == '\n') { + if (line_count != 0) { + try { + line = new String(line_bytes, 0, line_count, "UTF-8"); + } catch (UnsupportedEncodingException ue) { + line = ""; + for (int i = 0; i < line_count; i++) + line = line + line_bytes[i]; + } + if (line.startsWith("VERSION") || line.startsWith("CRC")) { + for (int e = 0; e < monitors.size(); e++) { + LinkedBlockingQueue q = monitors.get(e); + q.put(new AltosLine (line)); + } + } else { +// System.out.printf("GOT: %s\n", line); + reply_queue.put(new AltosLine (line)); + } + line_count = 0; + line = ""; + } + } else { + if (line_bytes == null) { + line_bytes = new byte[256]; + } else if (line_count == line_bytes.length) { + byte[] new_line_bytes = new byte[line_count * 2]; + System.arraycopy(line_bytes, 0, new_line_bytes, 0, line_count); + line_bytes = new_line_bytes; + } + line_bytes[line_count] = (byte) c; + line_count++; + } + } + } + } catch (InterruptedException e) { + } + } + + public void flush_output() { + if (altos != null) + libaltos.altos_flush(altos); + } + + public void flush_input() { + flush_output(); + boolean got_some; + do { + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + } + got_some = !reply_queue.isEmpty(); + synchronized(this) { + if (!"VERSION".startsWith(line) && + !line.startsWith("VERSION")) + line = ""; + reply_queue.clear(); + } + } while (got_some); + } + + public String get_reply() throws InterruptedException { + flush_output(); + AltosLine line = reply_queue.take(); + return line.line; + } + + public String get_reply(int timeout) throws InterruptedException { + flush_output(); + AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS); + if (line == null) + return null; + return line.line; + } + + public void add_monitor(LinkedBlockingQueue q) { + set_monitor(true); + monitors.add(q); + } + + public void remove_monitor(LinkedBlockingQueue q) { + monitors.remove(q); + if (monitors.isEmpty()) + set_monitor(false); + } + + public void close() { + if (altos != null) { + libaltos.altos_close(altos); + } + if (input_thread != null) { + try { + input_thread.interrupt(); + input_thread.join(); + } catch (InterruptedException e) { + } + input_thread = null; + } + if (altos != null) { + libaltos.altos_free(altos); + altos = null; + } + synchronized (devices_opened) { + devices_opened.remove(device.getPath()); + } + } + + public void putc(char c) { + if (altos != null) + libaltos.altos_putchar(altos, c); + } + + public void print(String data) { +// System.out.printf("\"%s\" ", data); + for (int i = 0; i < data.length(); i++) + putc(data.charAt(i)); + } + + public void printf(String format, Object ... arguments) { + print(String.format(format, arguments)); + } + + private void open() throws FileNotFoundException, AltosSerialInUseException { + synchronized (devices_opened) { + if (devices_opened.contains(device.getPath())) + throw new AltosSerialInUseException(device); + devices_opened.add(device.getPath()); + } + altos = libaltos.altos_open(device); + if (altos == null) { + close(); + throw new FileNotFoundException(device.toShortString()); + } + input_thread = new Thread(this); + input_thread.start(); + print("~\nE 0\n"); + set_monitor(false); + flush_output(); + } + + public void set_radio() { + set_channel(AltosPreferences.channel(device.getSerial())); + set_callsign(AltosPreferences.callsign()); + } + + public void set_channel(int channel) { + if (altos != null) { + if (monitor_mode) + printf("m 0\nc r %d\nm 1\n", channel); + else + printf("c r %d\n", channel); + flush_output(); + } + } + + void set_monitor(boolean monitor) { + monitor_mode = monitor; + if (altos != null) { + if (monitor) + printf("m 1\n"); + else + printf("m 0\n"); + flush_output(); + } + } + + public void set_callsign(String callsign) { + if (altos != null) { + printf ("c c %s\n", callsign); + flush_output(); + } + } + + public AltosSerial(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { + device = in_device; + line = ""; + monitor_mode = false; + monitors = new LinkedList> (); + reply_queue = new LinkedBlockingQueue (); + open(); + } +} diff --git a/altosui/AltosSerialInUseException.java b/altosui/AltosSerialInUseException.java new file mode 100644 index 00000000..4b108c7c --- /dev/null +++ b/altosui/AltosSerialInUseException.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import libaltosJNI.*; + +public class AltosSerialInUseException extends Exception { + public altos_device device; + + public AltosSerialInUseException (altos_device in_device) { + device = in_device; + } +} diff --git a/altosui/AltosSerialMonitor.java b/altosui/AltosSerialMonitor.java new file mode 100644 index 00000000..ad0e9295 --- /dev/null +++ b/altosui/AltosSerialMonitor.java @@ -0,0 +1,22 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +public interface AltosSerialMonitor { + void data(String data); +} diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java new file mode 100644 index 00000000..80970605 --- /dev/null +++ b/altosui/AltosSiteMap.java @@ -0,0 +1,388 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.MouseInputAdapter; +import javax.imageio.ImageIO; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.lang.Math; +import java.awt.geom.Point2D; +import java.awt.geom.Line2D; + +public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { + // preferred vertical step in a tile in naut. miles + // will actually choose a step size between x and 2x, where this + // is 1.5x + static final double tile_size_nmi = 0.75; + + static final int px_size = 512; + + static final int MAX_TILE_DELTA = 100; + + private static Point2D.Double translatePoint(Point2D.Double p, + Point2D.Double d) + { + return new Point2D.Double(p.x + d.x, p.y + d.y); + } + + static class LatLng { + public double lat, lng; + public LatLng(double lat, double lng) { + this.lat = lat; + this.lng = lng; + } + } + + // based on google js + // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js + // search for fromLatLngToPoint and fromPointToLatLng + private static Point2D.Double pt(LatLng latlng, int zoom) { + double scale_x = 256/360.0 * Math.pow(2, zoom); + double scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + return pt(latlng, scale_x, scale_y); + } + + private static Point2D.Double pt(LatLng latlng, + double scale_x, double scale_y) + { + Point2D.Double res = new Point2D.Double(); + double e; + + res.x = latlng.lng * scale_x; + + e = Math.sin(Math.toRadians(latlng.lat)); + e = Math.max(e,-(1-1.0E-15)); + e = Math.min(e, 1-1.0E-15 ); + + res.y = 0.5*Math.log((1+e)/(1-e))*-scale_y; + return res; + } + + static private LatLng latlng(Point2D.Double pt, + double scale_x, double scale_y) + { + double lat, lng; + double rads; + + lng = pt.x/scale_x; + rads = 2 * Math.atan(Math.exp(-pt.y/scale_y)); + lat = Math.toDegrees(rads - Math.PI/2); + + return new LatLng(lat,lng); + } + + int zoom; + double scale_x, scale_y; + + private Point2D.Double pt(double lat, double lng) { + return pt(new LatLng(lat, lng), scale_x, scale_y); + } + + private LatLng latlng(double x, double y) { + return latlng(new Point2D.Double(x,y), scale_x, scale_y); + } + private LatLng latlng(Point2D.Double pt) { + return latlng(pt, scale_x, scale_y); + } + + HashMap mapTiles = new HashMap(); + Point2D.Double centre; + + private Point2D.Double tileCoordOffset(Point p) { + return new Point2D.Double(centre.x - p.x*px_size, + centre.y - p.y * px_size); + } + + private Point tileOffset(Point2D.Double p) { + return new Point((int)Math.floor((centre.x+p.x)/px_size), + (int)Math.floor((centre.y+p.y)/px_size)); + } + + private Point2D.Double getBaseLocation(double lat, double lng) { + Point2D.Double locn, north_step; + + zoom = 2; + // stupid loop structure to please Java's control flow analysis + do { + zoom++; + scale_x = 256/360.0 * Math.pow(2, zoom); + scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + locn = pt(lat, lng); + north_step = pt(lat+tile_size_nmi*4/3/60.0, lng); + if (locn.y - north_step.y > px_size) + break; + } while (zoom < 22); + locn.x = -px_size * Math.floor(locn.x/px_size); + locn.y = -px_size * Math.floor(locn.y/px_size); + return locn; + } + + public void reset() { + // nothing + } + + private void bgLoadMap(final AltosSiteMapTile tile, + final File pngfile, final String pngurl) + { + //System.out.printf("Loading/fetching map %s\n", pngfile); + Thread thread = new Thread() { + public void run() { + ImageIcon res; + res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl); + if (res != null) { + tile.loadMap(res); + } else { + System.out.printf("# Failed to fetch file %s\n", pngfile); + System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); + } + } + }; + thread.start(); + } + + public static void prefetchMaps(double lat, double lng, int w, int h) { + AltosPreferences.init(null); + + AltosSiteMap asm = new AltosSiteMap(true); + asm.centre = asm.getBaseLocation(lat, lng); + + Point2D.Double p = new Point2D.Double(); + Point2D.Double p2; + int dx = -w/2, dy = -h/2; + for (int y = dy; y < h+dy; y++) { + for (int x = dx; x < w+dx; x++) { + LatLng map_latlng = asm.latlng( + -asm.centre.x + x*px_size + px_size/2, + -asm.centre.y + y*px_size + px_size/2); + File pngfile = asm.MapFile(map_latlng.lat, map_latlng.lng); + String pngurl = asm.MapURL(map_latlng.lat, map_latlng.lng); + if (pngfile.exists()) { + System.out.printf("Already have %s\n", pngfile); + } else if (AltosSiteMapCache.fetchMap(pngfile, pngurl)) { + System.out.printf("Fetched map %s\n", pngfile); + } else { + System.out.printf("# Failed to fetch file %s\n", pngfile); + System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); + } + } + } + } + + private void initMap(AltosSiteMapTile tile, Point offset) { + Point2D.Double coord = tileCoordOffset(offset); + + LatLng map_latlng = latlng(px_size/2-coord.x, px_size/2-coord.y); + + File pngfile = MapFile(map_latlng.lat, map_latlng.lng); + String pngurl = MapURL(map_latlng.lat, map_latlng.lng); + bgLoadMap(tile, pngfile, pngurl); + } + + private void initMaps(double lat, double lng) { + centre = getBaseLocation(lat, lng); + + for (Point k : mapTiles.keySet()) { + initMap(mapTiles.get(k), k); + } + } + + private File MapFile(double lat, double lng) { + char chlat = lat < 0 ? 'S' : 'N'; + char chlng = lng < 0 ? 'E' : 'W'; + if (lat < 0) lat = -lat; + if (lng < 0) lng = -lng; + return new File(AltosPreferences.logdir(), + String.format("map-%c%.6f,%c%.6f-%d.png", + chlat, lat, chlng, lng, zoom)); + } + + private String MapURL(double lat, double lng) { + return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32", lat, lng, zoom, px_size, px_size); + } + + boolean initialised = false; + Point2D.Double last_pt = null; + int last_state = -1; + public void show(final AltosState state, final int crc_errors) { + // if insufficient gps data, nothing to update + if (state.gps == null) + return; + if (state.pad_lat == 0 && state.pad_lon == 0) + return; + if (!state.gps.locked) { + if (state.gps.nsat < 4) + return; + } + + if (!initialised) { + initMaps(state.pad_lat, state.pad_lon); + initialised = true; + } + + final Point2D.Double pt = pt(state.gps.lat, state.gps.lon); + if (last_pt == pt && last_state == state.state) + return; + + if (last_pt == null) { + last_pt = pt; + } + boolean in_any = false; + for (Point offset : mapTiles.keySet()) { + AltosSiteMapTile tile = mapTiles.get(offset); + Point2D.Double ref, lref; + ref = translatePoint(pt, tileCoordOffset(offset)); + lref = translatePoint(last_pt, tileCoordOffset(offset)); + tile.show(state, crc_errors, lref, ref); + if (0 <= ref.x && ref.x < px_size) + if (0 <= ref.y && ref.y < px_size) + in_any = true; + } + + Point offset = tileOffset(pt); + if (!in_any) { + Point2D.Double ref, lref; + ref = translatePoint(pt, tileCoordOffset(offset)); + lref = translatePoint(last_pt, tileCoordOffset(offset)); + + AltosSiteMapTile tile = createTile(offset); + tile.show(state, crc_errors, lref, ref); + initMap(tile, offset); + finishTileLater(tile, offset); + } + + scrollRocketToVisible(pt); + + if (offset != tileOffset(last_pt)) { + ensureTilesAround(offset); + } + + last_pt = pt; + last_state = state.state; + } + + private AltosSiteMapTile createTile(Point offset) { + AltosSiteMapTile tile = new AltosSiteMapTile(px_size); + mapTiles.put(offset, tile); + return tile; + } + private void finishTileLater(final AltosSiteMapTile tile, + final Point offset) + { + SwingUtilities.invokeLater( new Runnable() { + public void run() { + addTileAt(tile, offset); + } + } ); + } + + private void ensureTilesAround(Point base_offset) { + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + Point offset = new Point(base_offset.x + x, base_offset.y + y); + if (mapTiles.containsKey(offset)) + continue; + AltosSiteMapTile tile = createTile(offset); + initMap(tile, offset); + finishTileLater(tile, offset); + } + } + } + + private Point topleft = new Point(0,0); + private void scrollRocketToVisible(Point2D.Double pt) { + Rectangle r = comp.getVisibleRect(); + Point2D.Double copt = translatePoint(pt, tileCoordOffset(topleft)); + int dx = (int)copt.x - r.width/2 - r.x; + int dy = (int)copt.y - r.height/2 - r.y; + if (Math.abs(dx) > r.width/4 || Math.abs(dy) > r.height/4) { + r.x += dx; + r.y += dy; + comp.scrollRectToVisible(r); + } + } + + private void addTileAt(AltosSiteMapTile tile, Point offset) { + if (Math.abs(offset.x) >= MAX_TILE_DELTA || + Math.abs(offset.y) >= MAX_TILE_DELTA) + { + System.out.printf("Rocket too far away from pad (tile %d,%d)\n", + offset.x, offset.y); + return; + } + + boolean review = false; + Rectangle r = comp.getVisibleRect(); + if (offset.x < topleft.x) { + r.x += (topleft.x - offset.x) * px_size; + topleft.x = offset.x; + review = true; + } + if (offset.y < topleft.y) { + r.y += (topleft.y - offset.y) * px_size; + topleft.y = offset.y; + review = true; + } + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.BOTH; + // put some space between the map tiles, debugging only + // c.insets = new Insets(5, 5, 5, 5); + + c.gridx = offset.x + MAX_TILE_DELTA; + c.gridy = offset.y + MAX_TILE_DELTA; + layout.setConstraints(tile, c); + + comp.add(tile); + if (review) { + comp.scrollRectToVisible(r); + } + } + + private AltosSiteMap(boolean knowWhatYouAreDoing) { + if (!knowWhatYouAreDoing) { + throw new RuntimeException("Arggh."); + } + } + + JComponent comp = new JComponent() { }; + private GridBagLayout layout = new GridBagLayout(); + + public AltosSiteMap() { + GrabNDrag scroller = new GrabNDrag(comp); + + comp.setLayout(layout); + + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + Point offset = new Point(x, y); + AltosSiteMapTile t = createTile(offset); + addTileAt(t, offset); + } + } + setViewportView(comp); + setPreferredSize(new Dimension(500,200)); + } +} diff --git a/altosui/AltosSiteMapCache.java b/altosui/AltosSiteMapCache.java new file mode 100644 index 00000000..2e62cc45 --- /dev/null +++ b/altosui/AltosSiteMapCache.java @@ -0,0 +1,103 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import javax.swing.*; +import javax.imageio.ImageIO; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.net.URL; +import java.net.URLConnection; + +public class AltosSiteMapCache extends JLabel { + public static boolean fetchMap(File file, String url) { + URL u; + + try { + u = new URL(url); + } catch (java.net.MalformedURLException e) { + return false; + } + + byte[] data; + try { + URLConnection uc = u.openConnection(); + int contentLength = uc.getContentLength(); + InputStream in = new BufferedInputStream(uc.getInputStream()); + int bytesRead = 0; + int offset = 0; + data = new byte[contentLength]; + while (offset < contentLength) { + bytesRead = in.read(data, offset, data.length - offset); + if (bytesRead == -1) + break; + offset += bytesRead; + } + in.close(); + + if (offset != contentLength) { + return false; + } + } catch (IOException e) { + return false; + } + + try { + FileOutputStream out = new FileOutputStream(file); + out.write(data); + out.flush(); + out.close(); + } catch (FileNotFoundException e) { + return false; + } catch (IOException e) { + if (file.exists()) { + file.delete(); + } + return false; + } + return true; + } + + public static ImageIcon fetchAndLoadMap(File pngfile, String url) { + if (!pngfile.exists()) { + if (!fetchMap(pngfile, url)) { + return null; + } + } + return loadMap(pngfile, url); + } + + public static ImageIcon loadMap(File pngfile, String url) { + if (!pngfile.exists()) { + return null; + } + + try { + return new ImageIcon(ImageIO.read(pngfile)); + } catch (IOException e) { + System.out.printf("# IO error trying to load %s\n", pngfile); + return null; + } + } +} diff --git a/altosui/AltosSiteMapTile.java b/altosui/AltosSiteMapTile.java new file mode 100644 index 00000000..8301f42b --- /dev/null +++ b/altosui/AltosSiteMapTile.java @@ -0,0 +1,112 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import javax.swing.*; +import javax.imageio.ImageIO; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.lang.Math; +import java.awt.geom.Point2D; +import java.awt.geom.Line2D; + +public class AltosSiteMapTile extends JLayeredPane { + JLabel mapLabel; + JLabel draw; + Graphics2D g2d; + + public void loadMap(ImageIcon icn) { + mapLabel.setIcon(icn); + } + + static Color stateColors[] = { + Color.WHITE, // startup + Color.WHITE, // idle + Color.WHITE, // pad + Color.RED, // boost + Color.PINK, // fast + Color.YELLOW, // coast + Color.CYAN, // drogue + Color.BLUE, // main + Color.BLACK // landed + }; + + private boolean drawn_landed_circle = false; + private boolean drawn_boost_circle = false; + public synchronized void show(AltosState state, int crc_errors, + Point2D.Double last_pt, Point2D.Double pt) + { + if (0 <= state.state && state.state < stateColors.length) { + g2d.setColor(stateColors[state.state]); + } + g2d.draw(new Line2D.Double(last_pt, pt)); + + if (state.state == 3 && !drawn_boost_circle) { + drawn_boost_circle = true; + g2d.setColor(Color.RED); + g2d.drawOval((int)last_pt.x-5, (int)last_pt.y-5, 10, 10); + g2d.drawOval((int)last_pt.x-20, (int)last_pt.y-20, 40, 40); + g2d.drawOval((int)last_pt.x-35, (int)last_pt.y-35, 70, 70); + } + if (state.state == 8 && !drawn_landed_circle) { + drawn_landed_circle = true; + g2d.setColor(Color.BLACK); + g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); + g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); + g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); + } + + repaint(); + } + + public static Graphics2D fillLabel(JLabel l, Color c, int px_size) { + BufferedImage img = new BufferedImage(px_size, px_size, + BufferedImage.TYPE_INT_ARGB); + Graphics2D g = img.createGraphics(); + g.setColor(c); + g.fillRect(0, 0, px_size, px_size); + l.setIcon(new ImageIcon(img)); + return g; + } + + public AltosSiteMapTile(int px_size) { + setPreferredSize(new Dimension(px_size, px_size)); + + mapLabel = new JLabel(); + fillLabel(mapLabel, Color.GRAY, px_size); + mapLabel.setOpaque(true); + mapLabel.setBounds(0, 0, px_size, px_size); + add(mapLabel, new Integer(0)); + + draw = new JLabel(); + g2d = fillLabel(draw, new Color(127, 127, 127, 0), px_size); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); + draw.setBounds(0, 0, px_size, px_size); + draw.setOpaque(false); + + add(draw, new Integer(1)); + } +} diff --git a/altosui/AltosState.java b/altosui/AltosState.java new file mode 100644 index 00000000..ec499d5a --- /dev/null +++ b/altosui/AltosState.java @@ -0,0 +1,197 @@ +/* + * Copyright © 2010 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. + */ + +/* + * Track flight state from telemetry or eeprom data stream + */ + +package altosui; + +public class AltosState { + AltosRecord data; + + /* derived data */ + + long report_time; + + double time_change; + int tick; + + int state; + boolean landed; + boolean ascent; /* going up? */ + + double ground_altitude; + double height; + double speed; + double acceleration; + double battery; + double temperature; + double main_sense; + double drogue_sense; + double baro_speed; + + double max_height; + double max_acceleration; + double max_speed; + + AltosGPS gps; + + double pad_lat; + double pad_lon; + double pad_alt; + + static final int MIN_PAD_SAMPLES = 10; + + int npad; + int ngps; + int gps_waiting; + boolean gps_ready; + + AltosGreatCircle from_pad; + double elevation; /* from pad */ + double range; /* total distance */ + + double gps_height; + + int speak_tick; + double speak_altitude; + + + void init (AltosRecord cur, AltosState prev_state) { + int i; + AltosRecord prev; + + data = cur; + + ground_altitude = data.ground_altitude(); + height = data.filtered_altitude() - ground_altitude; + + report_time = System.currentTimeMillis(); + + acceleration = data.acceleration(); + speed = data.accel_speed(); + temperature = data.temperature(); + drogue_sense = data.drogue_voltage(); + main_sense = data.main_voltage(); + battery = data.battery_voltage(); + 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; + 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_speed = prev_state.max_speed; + + /* make sure the clock is monotonic */ + while (tick < prev_state.tick) + tick += 65536; + + time_change = (tick - prev_state.tick) / 100.0; + + /* compute barometric speed */ + + double height_change = height - prev_state.height; + if (time_change > 0) + baro_speed = (prev_state.baro_speed * 3 + (height_change / time_change)) / 4.0; + else + baro_speed = prev_state.baro_speed; + } else { + npad = 0; + ngps = 0; + gps = null; + baro_speed = 0; + time_change = 0; + } + + if (state == Altos.ao_flight_pad) { + + /* 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) { + /* 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; + } + ngps++; + } + } + + gps_waiting = MIN_PAD_SAMPLES - npad; + if (gps_waiting < 0) + gps_waiting = 0; + + gps_ready = gps_waiting == 0; + + ascent = (Altos.ao_flight_boost <= state && + state <= Altos.ao_flight_coast); + + /* Only look at accelerometer data on the way up */ + if (ascent && acceleration > max_acceleration) + max_acceleration = acceleration; + if (ascent && speed > max_speed) + max_speed = speed; + + if (height > max_height) + max_height = height; + if (data.gps != null) { + if (gps == null || !gps.locked || data.gps.locked) + gps = data.gps; + if (ngps > 0 && gps.locked) { + from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); + } + } + elevation = 0; + range = -1; + if (ngps > 0) { + gps_height = gps.alt - pad_alt; + if (from_pad != null) { + elevation = Math.atan2(height, from_pad.distance) * 180 / Math.PI; + range = Math.sqrt(height * height + from_pad.distance * from_pad.distance); + } + } else { + gps_height = 0; + } + } + + public AltosState(AltosRecord cur) { + init(cur, null); + } + + public AltosState (AltosRecord cur, AltosState prev) { + init(cur, prev); + } +} diff --git a/altosui/AltosTelemetry.java b/altosui/AltosTelemetry.java new file mode 100644 index 00000000..bdb6466a --- /dev/null +++ b/altosui/AltosTelemetry.java @@ -0,0 +1,143 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; +import java.util.HashMap; + +/* + * Telemetry data contents + */ + + +/* + * The telemetry data stream is a bit of a mess at present, 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 AltosTelemetry extends AltosRecord { + public AltosTelemetry(String line) throws ParseException, AltosCRCException { + String[] words = line.split("\\s+"); + int i = 0; + + if (words[i].equals("CRC") && words[i+1].equals("INVALID")) { + i += 2; + AltosParse.word(words[i++], "RSSI"); + rssi = AltosParse.parse_int(words[i++]); + throw new AltosCRCException(rssi); + } + if (words[i].equals("CALL")) { + version = 0; + } else { + AltosParse.word (words[i++], "VERSION"); + version = AltosParse.parse_int(words[i++]); + } + + 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 = Altos.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:"); + drogue = 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++]); + + 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); + } +} diff --git a/altosui/AltosTelemetryIterable.java b/altosui/AltosTelemetryIterable.java new file mode 100644 index 00000000..a71ab872 --- /dev/null +++ b/altosui/AltosTelemetryIterable.java @@ -0,0 +1,82 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.io.*; +import java.util.*; +import java.text.*; + +public class AltosTelemetryIterable extends AltosRecordIterable { + LinkedList records; + + public Iterator iterator () { + return records.iterator(); + } + + public AltosTelemetryIterable (FileInputStream input) { + boolean saw_boost = false; + int current_tick = 0; + int boost_tick = 0; + + records = new LinkedList (); + + try { + for (;;) { + String line = AltosRecord.gets(input); + if (line == null) { + break; + } + try { + AltosTelemetry record = new AltosTelemetry(line); + if (record == null) + break; + if (records.isEmpty()) { + current_tick = record.tick; + } else { + int tick = record.tick | (current_tick & ~ 0xffff); + if (tick < current_tick - 0x1000) + tick += 0x10000; + current_tick = tick; + record.tick = current_tick; + } + if (!saw_boost && record.state >= Altos.ao_flight_boost) + { + saw_boost = true; + boost_tick = record.tick; + } + records.add(record); + } catch (ParseException pe) { + System.out.printf("parse exception %s\n", pe.getMessage()); + } catch (AltosCRCException ce) { + System.out.printf("crc error\n"); + } + } + } catch (IOException io) { + System.out.printf("io exception\n"); + } + + /* 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/altosui/AltosTelemetryReader.java b/altosui/AltosTelemetryReader.java new file mode 100644 index 00000000..6c5a9397 --- /dev/null +++ b/altosui/AltosTelemetryReader.java @@ -0,0 +1,61 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; +import java.io.*; +import java.util.concurrent.*; + +class AltosTelemetryReader extends AltosFlightReader { + AltosDevice device; + AltosSerial serial; + AltosLog log; + + LinkedBlockingQueue telem; + + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { + AltosLine l = telem.take(); + if (l.line == null) + throw new IOException("IO error"); + return new AltosTelemetry(l.line); + } + + void close(boolean interrupted) { + serial.remove_monitor(telem); + log.close(); + serial.close(); + } + + void set_channel(int channel) { + serial.set_channel(channel); + AltosPreferences.set_channel(device.getSerial(), channel); + } + + public AltosTelemetryReader (AltosDevice in_device) + throws FileNotFoundException, AltosSerialInUseException, IOException { + device = in_device; + serial = new AltosSerial(device); + log = new AltosLog(serial); + name = device.toShortString(); + + telem = new LinkedBlockingQueue(); + serial.set_radio(); + serial.add_monitor(telem); + } +} diff --git a/altosui/AltosUI.app/Contents/Info.plist b/altosui/AltosUI.app/Contents/Info.plist new file mode 100644 index 00000000..97b1b59c --- /dev/null +++ b/altosui/AltosUI.app/Contents/Info.plist @@ -0,0 +1,38 @@ + + + + + CFBundleName + altosui + CFBundleVersion + 100.0 + CFBundleAllowMixedLocalizations + true + CFBundleExecutable + JavaApplicationStub + CFBundleDevelopmentRegion + English + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleGetInfoString + AltOS UI version 0.7 + CFBundleInfoDictionaryVersion + 6.0 + CFBundleIconFile + AltosUIIcon.icns + Java + + MainClass + altosui.AltosUI + JVMVersion + 1.5+ + ClassPath + + $JAVAROOT/altosui.jar + $JAVAROOT/freetts.jar + + + + diff --git a/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub b/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub new file mode 100755 index 00000000..c661d3e1 Binary files /dev/null and b/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub differ diff --git a/altosui/AltosUI.app/Contents/PkgInfo b/altosui/AltosUI.app/Contents/PkgInfo new file mode 100644 index 00000000..8a43480f --- /dev/null +++ b/altosui/AltosUI.app/Contents/PkgInfo @@ -0,0 +1 @@ +APPLAM.O diff --git a/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns b/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns new file mode 100644 index 00000000..fe49f362 Binary files /dev/null and b/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns differ diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java new file mode 100644 index 00000000..94c4dd2a --- /dev/null +++ b/altosui/AltosUI.java @@ -0,0 +1,405 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import libaltosJNI.*; + +public class AltosUI extends JFrame { + public AltosVoice voice = new AltosVoice(); + + public static boolean load_library(Frame frame) { + if (!AltosDevice.load_library()) { + JOptionPane.showMessageDialog(frame, + String.format("No AltOS library in \"%s\"", + System.getProperty("java.library.path","")), + "Cannot load device access library", + JOptionPane.ERROR_MESSAGE); + return false; + } + return true; + } + + void telemetry_window(AltosDevice device) { + try { + AltosFlightReader reader = new AltosTelemetryReader(device); + if (reader != null) + new AltosFlightUI(voice, reader, device.getSerial()); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + String.format("Cannot open device \"%s\"", + device.toShortString()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(AltosUI.this, + String.format("Device \"%s\" already in use", + device.toShortString()), + "Device in use", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ee) { + JOptionPane.showMessageDialog(AltosUI.this, + device.toShortString(), + "Unkonwn I/O error", + JOptionPane.ERROR_MESSAGE); + } + } + + Container pane; + GridBagLayout gridbag; + + JButton addButton(int x, int y, String label) { + GridBagConstraints c; + JButton b; + + c = new GridBagConstraints(); + c.gridx = x; c.gridy = y; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + c.weighty = 1; + b = new JButton(label); + + Dimension ps = b.getPreferredSize(); + + gridbag.setConstraints(b, c); + add(b, c); + return b; + } + + public AltosUI() { + + load_library(null); + + java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg"); + if (imgURL != null) + setIconImage(new ImageIcon(imgURL).getImage()); + + AltosPreferences.init(this); + + pane = getContentPane(); + gridbag = new GridBagLayout(); + pane.setLayout(gridbag); + + JButton b; + + b = addButton(0, 0, "Monitor Flight"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ConnectToDevice(); + } + }); + b = addButton(1, 0, "Save Flight Data"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + SaveFlightData(); + } + }); + b = addButton(2, 0, "Replay Flight"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Replay(); + } + }); + b = addButton(3, 0, "Graph Data"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + GraphData(); + } + }); + b = addButton(4, 0, "Export Data"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ExportData(); + } + }); + b = addButton(0, 1, "Configure TeleMetrum"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ConfigureTeleMetrum(); + } + }); + + b = addButton(1, 1, "Configure AltosUI"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ConfigureAltosUI(); + } + }); + + b = addButton(2, 1, "Flash Image"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + FlashImage(); + } + }); + + b = addButton(3, 1, "Fire Igniter"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + FireIgniter(); + } + }); + + b = addButton(4, 1, "Quit"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + + setTitle("AltOS"); + + pane.doLayout(); + pane.validate(); + + doLayout(); + validate(); + + setVisible(true); + + Insets i = getInsets(); + Dimension ps = rootPane.getPreferredSize(); + ps.width += i.left + i.right; + ps.height += i.top + i.bottom; + setPreferredSize(ps); + setSize(ps); + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + } + + private void ConnectToDevice() { + AltosDevice device = AltosDeviceDialog.show(AltosUI.this, + AltosDevice.product_basestation); + + if (device != null) + telemetry_window(device); + } + + void ConfigureCallsign() { + String result; + result = JOptionPane.showInputDialog(AltosUI.this, + "Configure Callsign", + AltosPreferences.callsign()); + if (result != null) + AltosPreferences.set_callsign(result); + } + + void ConfigureTeleMetrum() { + new AltosConfig(AltosUI.this); + } + + void FlashImage() { + new AltosFlashUI(AltosUI.this); + } + + void FireIgniter() { + new AltosIgniteUI(AltosUI.this); + } + + /* + * Replay a flight from telemetry data + */ + private void Replay() { + AltosDataChooser chooser = new AltosDataChooser( + AltosUI.this); + + AltosRecordIterable iterable = chooser.runDialog(); + if (iterable != null) { + AltosFlightReader reader = new AltosReplayReader(iterable.iterator(), + chooser.filename()); + new AltosFlightUI(voice, reader); + } + } + + /* Connect to TeleMetrum, either directly or through + * a TeleDongle over the packet link + */ + private void SaveFlightData() { + new AltosEepromDownload(AltosUI.this); + } + + /* Load a flight log file and write out a CSV file containing + * all of the data in standard units + */ + + private void ExportData() { + AltosDataChooser chooser; + chooser = new AltosDataChooser(this); + AltosRecordIterable record_reader = chooser.runDialog(); + if (record_reader == null) + return; + new AltosCSVUI(AltosUI.this, record_reader, chooser.file()); + } + + /* Load a flight log CSV file and display a pretty graph. + */ + + private void GraphData() { + AltosDataChooser chooser; + chooser = new AltosDataChooser(this); + AltosRecordIterable record_reader = chooser.runDialog(); + if (record_reader == null) + return; + new AltosGraphUI(record_reader); + } + + private void ConfigureAltosUI() { + new AltosConfigureUI(AltosUI.this, voice); + } + + static AltosRecordIterable open_logfile(String filename) { + File file = new File (filename); + try { + FileInputStream in; + + in = new FileInputStream(file); + if (filename.endsWith("eeprom")) + return new AltosEepromIterable(in); + else + return new AltosTelemetryIterable(in); + } catch (FileNotFoundException fe) { + System.out.printf("Cannot open '%s'\n", filename); + return null; + } + } + + static AltosWriter open_csv(String filename) { + File file = new File (filename); + try { + return new AltosCSV(file); + } catch (FileNotFoundException fe) { + System.out.printf("Cannot open '%s'\n", filename); + return null; + } + } + + static AltosWriter open_kml(String filename) { + File file = new File (filename); + try { + return new AltosKML(file); + } catch (FileNotFoundException fe) { + System.out.printf("Cannot open '%s'\n", filename); + return null; + } + } + + static final int process_csv = 1; + static final int process_kml = 2; + + static void process_file(String input, int process) { + AltosRecordIterable iterable = open_logfile(input); + if (iterable == null) + return; + if (process == 0) + process = process_csv; + if ((process & process_csv) != 0) { + String output = Altos.replace_extension(input,".csv"); + System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); + if (input.equals(output)) { + System.out.printf("Not processing '%s'\n", input); + } else { + AltosWriter writer = open_csv(output); + if (writer != null) { + writer.write(iterable); + writer.close(); + } + } + } + if ((process & process_kml) != 0) { + String output = Altos.replace_extension(input,".kml"); + System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); + if (input.equals(output)) { + System.out.printf("Not processing '%s'\n", input); + } else { + AltosWriter writer = open_kml(output); + if (writer == null) + return; + writer.write(iterable); + writer.close(); + } + } + } + + public static void main(final String[] args) { + int process = 0; + /* Handle batch-mode */ + if (args.length == 1 && args[0].equals("--help")) { + System.out.printf("Usage: altosui [OPTION]... [FILE]...\n"); + System.out.printf(" Options:\n"); + System.out.printf(" --fetchmaps \tpre-fetch maps for site map view\n"); + System.out.printf(" --replay \t\trelive the glory of past flights \n"); + System.out.printf(" --csv\tgenerate comma separated output for spreadsheets, etc\n"); + System.out.printf(" --kml\tgenerate KML output for use with Google Earth\n"); + } else if (args.length == 3 && args[0].equals("--fetchmaps")) { + double lat = Double.parseDouble(args[1]); + double lon = Double.parseDouble(args[2]); + AltosSiteMap.prefetchMaps(lat, lon, 5, 5); + } else if (args.length == 2 && args[0].equals("--replay")) { + String filename = args[1]; + FileInputStream in; + try { + in = new FileInputStream(filename); + } catch (Exception e) { + System.out.printf("Failed to open file '%s'\n", filename); + return; + } + AltosRecordIterable recs; + AltosReplayReader reader; + if (filename.endsWith("eeprom")) { + recs = new AltosEepromIterable(in); + } else { + recs = new AltosTelemetryIterable(in); + } + reader = new AltosReplayReader(recs.iterator(), filename); + AltosFlightUI flight_ui = new AltosFlightUI(new AltosVoice(), reader); + flight_ui.set_exit_on_close(); + return; + } else if (args.length > 0) { + for (int i = 0; i < args.length; i++) { + if (args[i].equals("--kml")) + process |= process_kml; + else if (args[i].equals("--csv")) + process |= process_csv; + else + process_file(args[i], process); + } + } else { + AltosUI altosui = new AltosUI(); + altosui.setVisible(true); + + AltosDevice[] devices = AltosDevice.list(AltosDevice.product_basestation); + for (int i = 0; i < devices.length; i++) + altosui.telemetry_window(devices[i]); + } + } +} diff --git a/altosui/AltosVoice.java b/altosui/AltosVoice.java new file mode 100644 index 00000000..ac13ee14 --- /dev/null +++ b/altosui/AltosVoice.java @@ -0,0 +1,95 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import com.sun.speech.freetts.Voice; +import com.sun.speech.freetts.VoiceManager; +import com.sun.speech.freetts.audio.JavaClipAudioPlayer; +import java.util.concurrent.LinkedBlockingQueue; + +public class AltosVoice implements Runnable { + VoiceManager voice_manager; + Voice voice; + LinkedBlockingQueue phrases; + Thread thread; + boolean busy; + + final static String voice_name = "kevin16"; + + public void run() { + try { + for (;;) { + String s = phrases.take(); + voice.speak(s); + synchronized(this) { + if (phrases.isEmpty()) { + busy = false; + notifyAll(); + } + } + } + } catch (InterruptedException e) { + } + } + + public synchronized void drain() throws InterruptedException { + while (busy) + wait(); + } + + public void speak_always(String s) { + try { + if (voice != null) { + synchronized(this) { + busy = true; + phrases.put(s); + } + } + } catch (InterruptedException e) { + } + } + + public void speak(String s) { + if (AltosPreferences.voice()) + speak_always(s); + } + + public void speak(String format, Object... parameters) { + speak(String.format(format, parameters)); + } + + public AltosVoice () { + busy = false; + voice_manager = VoiceManager.getInstance(); + voice = voice_manager.getVoice(voice_name); + if (voice != null) { + voice.allocate(); + phrases = new LinkedBlockingQueue (); + thread = new Thread(this); + thread.start(); + } else { + System.out.printf("Voice manager failed to open %s\n", voice_name); + Voice[] voices = voice_manager.getVoices(); + System.out.printf("Available voices:\n"); + for (int i = 0; i < voices.length; i++) { + System.out.println(" " + voices[i].getName() + + " (" + voices[i].getDomain() + " domain)"); + } + } + } +} diff --git a/altosui/AltosWriter.java b/altosui/AltosWriter.java new file mode 100644 index 00000000..a172dff0 --- /dev/null +++ b/altosui/AltosWriter.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2010 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. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.text.*; +import java.util.*; + +public interface AltosWriter { + + public void write(AltosRecord record); + + public void write(AltosRecordIterable iterable); + + public void close(); +} diff --git a/altosui/GrabNDrag.java b/altosui/GrabNDrag.java new file mode 100644 index 00000000..e6b87b58 --- /dev/null +++ b/altosui/GrabNDrag.java @@ -0,0 +1,54 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.MouseInputAdapter; +import javax.imageio.ImageIO; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; + +class GrabNDrag extends MouseInputAdapter { + private JComponent scroll; + private Point startPt = new Point(); + + public GrabNDrag(JComponent scroll) { + this.scroll = scroll; + scroll.addMouseMotionListener(this); + scroll.addMouseListener(this); + scroll.setAutoscrolls(true); + } + + public void mousePressed(MouseEvent e) { + startPt.setLocation(e.getPoint()); + } + public void mouseDragged(MouseEvent e) { + int xd = e.getX() - startPt.x; + int yd = e.getY() - startPt.y; + + Rectangle r = scroll.getVisibleRect(); + r.x -= xd; + r.y -= yd; + scroll.scrollRectToVisible(r); + } +} diff --git a/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi b/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi new file mode 100644 index 00000000..3ed821eb --- /dev/null +++ b/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi @@ -0,0 +1,84 @@ +# +# InstDrv Example, (c) 2003 Jan Kiszka (Jan Kiszka@web.de) +# + +Name "InstDrv.dll test" + +OutFile "InstDrv-Test.exe" + +ShowInstDetails show + +ComponentText "InstDrv Plugin Usage Example" + +Page components +Page instfiles + +Section "Install a Driver" InstDriver + InstDrv::InitDriverSetup /NOUNLOAD "{4d36e978-e325-11ce-bfc1-08002be10318}" "IrCOMM2k" + Pop $0 + DetailPrint "InitDriverSetup: $0" + + InstDrv::DeleteOemInfFiles /NOUNLOAD + Pop $0 + DetailPrint "DeleteOemInfFiles: $0" + StrCmp $0 "00000000" PrintInfNames ContInst1 + + PrintInfNames: + Pop $0 + DetailPrint "Deleted $0" + Pop $0 + DetailPrint "Deleted $0" + + ContInst1: + InstDrv::CreateDevice /NOUNLOAD + Pop $0 + DetailPrint "CreateDevice: $0" + + SetOutPath $TEMP + File "ircomm2k.inf" + File "ircomm2k.sys" + + InstDrv::InstallDriver /NOUNLOAD "$TEMP\ircomm2k.inf" + Pop $0 + DetailPrint "InstallDriver: $0" + StrCmp $0 "00000000" PrintReboot ContInst2 + + PrintReboot: + Pop $0 + DetailPrint "Reboot: $0" + + ContInst2: + InstDrv::CountDevices + Pop $0 + DetailPrint "CountDevices: $0" +SectionEnd + +Section "Uninstall the driver again" UninstDriver + InstDrv::InitDriverSetup /NOUNLOAD "{4d36e978-e325-11ce-bfc1-08002be10318}" "IrCOMM2k" + Pop $0 + DetailPrint "InitDriverSetup: $0" + + InstDrv::DeleteOemInfFiles /NOUNLOAD + Pop $0 + DetailPrint "DeleteOemInfFiles: $0" + StrCmp $0 "00000000" PrintInfNames ContUninst1 + + PrintInfNames: + Pop $0 + DetailPrint "Deleted $0" + Pop $0 + DetailPrint "Deleted $0" + + ContUninst1: + InstDrv::RemoveAllDevices + Pop $0 + DetailPrint "RemoveAllDevices: $0" + StrCmp $0 "00000000" PrintReboot ContUninst2 + + PrintReboot: + Pop $0 + DetailPrint "Reboot: $0" + + ContUninst2: + Delete "$SYSDIR\system32\ircomm2k.sys" +SectionEnd \ No newline at end of file diff --git a/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe b/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe new file mode 100644 index 00000000..615bae15 Binary files /dev/null and b/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe differ diff --git a/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c b/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c new file mode 100644 index 00000000..efe866e9 --- /dev/null +++ b/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c @@ -0,0 +1,704 @@ +/* + +InstDrv.dll - Installs or Removes Device Drivers + +Copyright 2003 Jan Kiszka (Jan.Kiszka@web.de) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute +it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment in the + product documentation would be appreciated but is not required. +2. Altered versions must be plainly marked as such, + and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any distribution. + +*/ + + +#include +#include +#include +#include "../exdll/exdll.h" + + +char paramBuf[1024]; +GUID devClass; +char hwIdBuf[1024]; +int initialized = 0; + + + +void* memset(void* dst, int val, unsigned int len) +{ + while (len-- > 0) + *((char *)dst)++ = val; + + return NULL; +} + + + +void* memcpy(void* dst, const void* src, unsigned int len) +{ + while (len-- > 0) + *((char *)dst)++ = *((char *)src)++; + + return NULL; +} + + + +int HexCharToInt(char c) +{ + if ((c >= '0') && (c <= '9')) + return c - '0'; + else if ((c >= 'a') && (c <= 'f')) + return c - 'a' + 10; + else if ((c >= 'A') && (c <= 'F')) + return c - 'A' + 10; + else + return -1; +} + + + +BOOLEAN HexStringToUInt(char* str, int width, void* valBuf) +{ + int i, val; + + + for (i = width - 4; i >= 0; i -= 4) + { + val = HexCharToInt(*str++); + if (val < 0) + return FALSE; + *(unsigned int *)valBuf += val << i; + } + + return TRUE; +} + + + +BOOLEAN StringToGUID(char* guidStr, GUID* pGuid) +{ + int i; + + + memset(pGuid, 0, sizeof(GUID)); + + if (*guidStr++ != '{') + return FALSE; + + if (!HexStringToUInt(guidStr, 32, &pGuid->Data1)) + return FALSE; + guidStr += 8; + + if (*guidStr++ != '-') + return FALSE; + + if (!HexStringToUInt(guidStr, 16, &pGuid->Data2)) + return FALSE; + guidStr += 4; + + if (*guidStr++ != '-') + return FALSE; + + if (!HexStringToUInt(guidStr, 16, &pGuid->Data3)) + return FALSE; + guidStr += 4; + + if (*guidStr++ != '-') + return FALSE; + + for (i = 0; i < 2; i++) + { + if (!HexStringToUInt(guidStr, 8, &pGuid->Data4[i])) + return FALSE; + guidStr += 2; + } + + if (*guidStr++ != '-') + return FALSE; + + for (i = 2; i < 8; i++) + { + if (!HexStringToUInt(guidStr, 8, &pGuid->Data4[i])) + return FALSE; + guidStr += 2; + } + + if (*guidStr++ != '}') + return FALSE; + + return TRUE; +} + + + +DWORD FindNextDevice(HDEVINFO devInfoSet, SP_DEVINFO_DATA* pDevInfoData, DWORD* pIndex) +{ + DWORD buffersize = 0; + LPTSTR buffer = NULL; + DWORD dataType; + DWORD result; + + + while (1) + { + if (!SetupDiEnumDeviceInfo(devInfoSet, (*pIndex)++, pDevInfoData)) + { + result = GetLastError(); + break; + } + + GetDeviceRegistryProperty: + if (!SetupDiGetDeviceRegistryProperty(devInfoSet, pDevInfoData, SPDRP_HARDWAREID, + &dataType, (PBYTE)buffer, buffersize, + &buffersize)) + { + result = GetLastError(); + + if (result == ERROR_INSUFFICIENT_BUFFER) + { + if (buffer != NULL) + LocalFree(buffer); + + buffer = (LPTSTR)LocalAlloc(LPTR, buffersize); + + if (buffer == NULL) + break; + + goto GetDeviceRegistryProperty; + } + else if (result == ERROR_INVALID_DATA) + continue; // ignore invalid entries + else + break; // break on other errors + } + + if (lstrcmpi(buffer, hwIdBuf) == 0) + { + result = 0; + break; + } + } + + if (buffer != NULL) + LocalFree(buffer); + + return result; +} + + + +DWORD FindFirstDevice(HWND hwndParent, const GUID* pDevClass, const LPTSTR hwId, + HDEVINFO* pDevInfoSet, SP_DEVINFO_DATA* pDevInfoData, + DWORD *pIndex, DWORD flags) +{ + DWORD result; + + + *pDevInfoSet = SetupDiGetClassDevs((GUID*)pDevClass, NULL, hwndParent, flags); + if (*pDevInfoSet == INVALID_HANDLE_VALUE) + return GetLastError(); + + pDevInfoData->cbSize = sizeof(SP_DEVINFO_DATA); + *pIndex = 0; + + result = FindNextDevice(*pDevInfoSet, pDevInfoData, pIndex); + + if (result != 0) + SetupDiDestroyDeviceInfoList(*pDevInfoSet); + + return result; +} + + + +/* + * InstDrv::InitDriverSetup devClass drvHWID + * + * devClass - GUID of the driver's device setup class + * drvHWID - Hardware ID of the supported device + * + * Return: + * result - error message, empty on success + */ +void __declspec(dllexport) InitDriverSetup(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + EXDLL_INIT(); + + /* convert class GUID */ + popstring(paramBuf); + + if (!StringToGUID(paramBuf, &devClass)) + { + popstring(paramBuf); + pushstring("Invalid GUID!"); + return; + } + + /* get hardware ID */ + memset(hwIdBuf, 0, sizeof(hwIdBuf)); + popstring(hwIdBuf); + + initialized = 1; + pushstring(""); +} + + + +/* + * InstDrv::CountDevices + * + * Return: + * result - Number of installed devices the driver supports + */ +void __declspec(dllexport) CountDevices(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfoSet; + SP_DEVINFO_DATA devInfoData; + int count = 0; + char countBuf[16]; + DWORD index; + DWORD result; + + + EXDLL_INIT(); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + result = FindFirstDevice(hwndParent, &devClass, hwIdBuf, &devInfoSet, &devInfoData, + &index, DIGCF_PRESENT); + if (result != 0) + { + pushstring("0"); + return; + } + + do + { + count++; + } while (FindNextDevice(devInfoSet, &devInfoData, &index) == 0); + + SetupDiDestroyDeviceInfoList(devInfoSet); + + wsprintf(countBuf, "%d", count); + pushstring(countBuf); +} + + + +/* + * InstDrv::CreateDevice + * + * Return: + * result - Windows error code + */ +void __declspec(dllexport) CreateDevice(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfoSet; + SP_DEVINFO_DATA devInfoData; + DWORD result = 0; + char resultBuf[16]; + + + EXDLL_INIT(); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + devInfoSet = SetupDiCreateDeviceInfoList(&devClass, hwndParent); + if (devInfoSet == INVALID_HANDLE_VALUE) + { + wsprintf(resultBuf, "%08X", GetLastError()); + pushstring(resultBuf); + return; + } + + devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); + if (!SetupDiCreateDeviceInfo(devInfoSet, hwIdBuf, &devClass, NULL, + hwndParent, DICD_GENERATE_ID, &devInfoData)) + { + result = GetLastError(); + goto InstallCleanup; + } + + if (!SetupDiSetDeviceRegistryProperty(devInfoSet, &devInfoData, SPDRP_HARDWAREID, + hwIdBuf, (lstrlen(hwIdBuf)+2)*sizeof(TCHAR))) + { + result = GetLastError(); + goto InstallCleanup; + } + + if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, devInfoSet, &devInfoData)) + result = GetLastError(); + + InstallCleanup: + SetupDiDestroyDeviceInfoList(devInfoSet); + + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +/* + * InstDrv::InstallDriver infPath + * + * Return: + * result - Windows error code + * reboot - non-zero if reboot is required + */ +void __declspec(dllexport) InstallDriver(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + char resultBuf[16]; + BOOL reboot; + + + EXDLL_INIT(); + popstring(paramBuf); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + if (!UpdateDriverForPlugAndPlayDevices(hwndParent, hwIdBuf, paramBuf, + INSTALLFLAG_FORCE, &reboot)) + { + wsprintf(resultBuf, "%08X", GetLastError()); + pushstring(resultBuf); + } + else + { + wsprintf(resultBuf, "%d", reboot); + pushstring(resultBuf); + pushstring("00000000"); + } +} + + + +/* + * InstDrv::DeleteOemInfFiles + * + * Return: + * result - Windows error code + * oeminf - Path of the deleted devices setup file (oemXX.inf) + * oempnf - Path of the deleted devices setup file (oemXX.pnf) + */ +void __declspec(dllexport) DeleteOemInfFiles(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfo; + SP_DEVINFO_DATA devInfoData; + SP_DRVINFO_DATA drvInfoData; + SP_DRVINFO_DETAIL_DATA drvInfoDetail; + DWORD index; + DWORD result; + char resultBuf[16]; + + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + result = FindFirstDevice(NULL, &devClass, hwIdBuf, &devInfo, &devInfoData, &index, 0); + if (result != 0) + goto Cleanup1; + + if (!SetupDiBuildDriverInfoList(devInfo, &devInfoData, SPDIT_COMPATDRIVER)) + { + result = GetLastError(); + goto Cleanup2; + } + + drvInfoData.cbSize = sizeof(SP_DRVINFO_DATA); + drvInfoDetail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA); + + if (!SetupDiEnumDriverInfo(devInfo, &devInfoData, SPDIT_COMPATDRIVER, 0, &drvInfoData)) + { + result = GetLastError(); + goto Cleanup3; + } + + if (!SetupDiGetDriverInfoDetail(devInfo, &devInfoData, &drvInfoData, + &drvInfoDetail, sizeof(drvInfoDetail), NULL)) + { + result = GetLastError(); + + if (result != ERROR_INSUFFICIENT_BUFFER) + goto Cleanup3; + + result = 0; + } + + pushstring(drvInfoDetail.InfFileName); + if (!DeleteFile(drvInfoDetail.InfFileName)) + result = GetLastError(); + else + { + index = lstrlen(drvInfoDetail.InfFileName); + if (index > 3) + { + lstrcpy(drvInfoDetail.InfFileName+index-3, "pnf"); + pushstring(drvInfoDetail.InfFileName); + if (!DeleteFile(drvInfoDetail.InfFileName)) + result = GetLastError(); + } + } + + Cleanup3: + SetupDiDestroyDriverInfoList(devInfo, &devInfoData, SPDIT_COMPATDRIVER); + + Cleanup2: + SetupDiDestroyDeviceInfoList(devInfo); + + Cleanup1: + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +/* + * InstDrv::RemoveAllDevices + * + * Return: + * result - Windows error code + * reboot - non-zero if reboot is required + */ +void __declspec(dllexport) RemoveAllDevices(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfo; + SP_DEVINFO_DATA devInfoData; + DWORD index; + DWORD result; + char resultBuf[16]; + BOOL reboot = FALSE; + SP_DEVINSTALL_PARAMS instParams; + + + EXDLL_INIT(); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + result = FindFirstDevice(NULL, &devClass, hwIdBuf, &devInfo, &devInfoData, &index, 0); + if (result != 0) + goto Cleanup1; + + do + { + if (!SetupDiCallClassInstaller(DIF_REMOVE, devInfo, &devInfoData)) + { + result = GetLastError(); + break; + } + + instParams.cbSize = sizeof(instParams); + if (!reboot && + SetupDiGetDeviceInstallParams(devInfo, &devInfoData, &instParams) && + ((instParams.Flags & (DI_NEEDRESTART|DI_NEEDREBOOT)) != 0)) + { + reboot = TRUE; + } + + result = FindNextDevice(devInfo, &devInfoData, &index); + } while (result == 0); + + SetupDiDestroyDeviceInfoList(devInfo); + + Cleanup1: + if ((result == 0) || (result == ERROR_NO_MORE_ITEMS)) + { + wsprintf(resultBuf, "%d", reboot); + pushstring(resultBuf); + pushstring("00000000"); + } + else + { + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); + } +} + + + +/* + * InstDrv::StartSystemService serviceName + * + * Return: + * result - Windows error code + */ +void __declspec(dllexport) StartSystemService(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + SC_HANDLE managerHndl; + SC_HANDLE svcHndl; + SERVICE_STATUS svcStatus; + DWORD oldCheckPoint; + DWORD result; + char resultBuf[16]; + + + EXDLL_INIT(); + popstring(paramBuf); + + managerHndl = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (managerHndl == NULL) + { + result = GetLastError(); + goto Cleanup1; + } + + svcHndl = OpenService(managerHndl, paramBuf, SERVICE_START | SERVICE_QUERY_STATUS); + if (svcHndl == NULL) + { + result = GetLastError(); + goto Cleanup2; + } + + if (!StartService(svcHndl, 0, NULL) || !QueryServiceStatus(svcHndl, &svcStatus)) + { + result = GetLastError(); + goto Cleanup3; + } + + while (svcStatus.dwCurrentState == SERVICE_START_PENDING) + { + oldCheckPoint = svcStatus.dwCheckPoint; + + Sleep(svcStatus.dwWaitHint); + + if (!QueryServiceStatus(svcHndl, &svcStatus)) + { + result = GetLastError(); + break; + } + + if (oldCheckPoint >= svcStatus.dwCheckPoint) + { + if ((svcStatus.dwCurrentState == SERVICE_STOPPED) && + (svcStatus.dwWin32ExitCode != 0)) + result = svcStatus.dwWin32ExitCode; + else + result = ERROR_SERVICE_REQUEST_TIMEOUT; + } + } + + if (svcStatus.dwCurrentState == SERVICE_RUNNING) + result = 0; + + Cleanup3: + CloseServiceHandle(svcHndl); + + Cleanup2: + CloseServiceHandle(managerHndl); + + Cleanup1: + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +/* + * InstDrv::StopSystemService serviceName + * + * Return: + * result - Windows error code + */ +void __declspec(dllexport) StopSystemService(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + SC_HANDLE managerHndl; + SC_HANDLE svcHndl; + SERVICE_STATUS svcStatus; + DWORD oldCheckPoint; + DWORD result; + char resultBuf[16]; + + + EXDLL_INIT(); + popstring(paramBuf); + + managerHndl = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (managerHndl == NULL) + { + result = GetLastError(); + goto Cleanup1; + } + + svcHndl = OpenService(managerHndl, paramBuf, SERVICE_STOP | SERVICE_QUERY_STATUS); + if (svcHndl == NULL) + { + result = GetLastError(); + goto Cleanup2; + } + + if (!ControlService(svcHndl, SERVICE_CONTROL_STOP, &svcStatus)) + { + result = GetLastError(); + goto Cleanup3; + } + + while (svcStatus.dwCurrentState == SERVICE_STOP_PENDING) + { + oldCheckPoint = svcStatus.dwCheckPoint; + + Sleep(svcStatus.dwWaitHint); + + if (!QueryServiceStatus(svcHndl, &svcStatus)) + { + result = GetLastError(); + break; + } + + if (oldCheckPoint >= svcStatus.dwCheckPoint) + { + result = ERROR_SERVICE_REQUEST_TIMEOUT; + break; + } + } + + if (svcStatus.dwCurrentState == SERVICE_STOPPED) + result = 0; + + Cleanup3: + CloseServiceHandle(svcHndl); + + Cleanup2: + CloseServiceHandle(managerHndl); + + Cleanup1: + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + return TRUE; +} diff --git a/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp b/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp new file mode 100644 index 00000000..874e66c7 --- /dev/null +++ b/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="InstDrv" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=InstDrv - Win32 Debug +!MESSAGE Dies ist kein gltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE +!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und fhren Sie den Befehl +!MESSAGE +!MESSAGE NMAKE /f "InstDrv.mak". +!MESSAGE +!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben +!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: +!MESSAGE +!MESSAGE NMAKE /f "InstDrv.mak" CFG="InstDrv - Win32 Debug" +!MESSAGE +!MESSAGE Fr die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "InstDrv - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library") +!MESSAGE "InstDrv - Win32 Debug" (basierend auf "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "InstDrv - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O1 /I "C:\Programme\WINDDK\3790\inc\ddk\w2k" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib setupapi.lib newdev.lib /nologo /entry:"_DllMainCRTStartup" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/InstDrv.dll" /libpath:"C:\Programme\WINDDK\3790\lib\w2k\i386" /opt:nowin98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "InstDrv - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"_DllMainCRTStartup" /dll /debug /machine:I386 /pdbtype:sept +# SUBTRACT LINK32 /nodefaultlib + +!ENDIF + +# Begin Target + +# Name "InstDrv - Win32 Release" +# Name "InstDrv - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\InstDrv.c +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Ressourcendateien" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw b/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw new file mode 100644 index 00000000..b3d02f0e --- /dev/null +++ b/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELSCHT WERDEN! + +############################################################################### + +Project: "InstDrv"=.\InstDrv.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt b/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt new file mode 100644 index 00000000..e5877aa6 --- /dev/null +++ b/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt @@ -0,0 +1,141 @@ +InstDrv.dll version 0.2 - Installs or Removes Device Drivers +------------------------------------------------------------ + + +The plugin helps you to create NSIS scripts for installing device drivers or +removing them again. It can count installed device instances, create new ones +or delete all supported device. InstDrv works on Windows 2000 or later. + + + +InstDrv::InitDriverSetup devClass drvHWID +Return: result + +To start processing a driver, first call this function. devClass is the GUID +of the device class the driver supports, drvHWID is the device hardware ID. If +you don't know what these terms mean, you may want to take a look at the +Windows DDK. This function returns an empty string on success, otherwise an +error message. + +InitDriverSetup has to be called every time after the plugin dll has been +(re-)loaded, or if you want to switch to a different driver. + + + +InstDrv::CountDevices +Return: number + +This call returns the number of installed and supported devices of the driver. + + + +InstDrv::CreateDevice +Return: result + +To create a new deviced node which the driver has to support, use this +function. You may even call it multiple times for more than one instance. The +return value is the Windows error code (in hex). Use CreateDevice before +installing or updating the driver itself. + + + +InstDrv::InstallDriver infPath +Return: result + reboot + +InstallDriver installs or updates a device driver as specified in the .inf +setup script. It returns a Windows error code (in hex) and, on success, a flag +signalling if a system reboot is required. + + + +InstDrv::DeleteOemInfFiles +Return: result + oeminf + oempnf + +DeleteOemInfFiles tries to clean up the Windows inf directory by deleting the +oemXX.inf and oemXX.pnf files associated with the drivers. It returns a +Windows error code (in hex) and, on success, the names of the deleted files. +This functions requires that at least one device instance is still present. +So, call it before you remove the devices itself. You should also call it +before updating a driver. This avoids that the inf directory gets slowly +messed up with useless old setup scripts (which does NOT really accelerate +Windows). The error code which comes up when no device is installed is +"00000103". + + + +InstDrv::RemoveAllDevices +Return: result + reboot + +This functions deletes all devices instances the driver supported. It returns +a Windows error code (in hex) and, on success, a flag signalling if the system +needs to be rebooted. You additionally have to remove the driver binaries from +the system paths. + + + +InstDrv::StartSystemService serviceName +Return: result + +Call this function to start the provided system service. The function blocks +until the service is started or the system reported a timeout. The return value +is the Windows error code (in hex). + + + +InstDrv::StopSystemService serviceName +Return: result + +This function tries to stop the provided system service. It blocks until the +service has been shut down or the system reported a timeout. The return value +is the Windows error code (in hex). + + + +Example.nsi + +The example script installs or removes the virtual COM port driver of IrCOMM2k +(2.0.0-alpha8, see www.ircomm2k.de/english). The driver and its setup script +are only included for demonstration purposes, they do not work without the +rest of IrCOMM2k (but they also do not cause any harm). + + + +Building the Source Code + +To build the plugin from the source code, some include files and libraries +which come with the Windows DDK are required. + + + +History + + 0.2 - fixed bug when calling InitDriverSetup the second time + - added StartSystemService and StopSystemService + + 0.1 - first release + + + +License + +Copyright 2003 Jan Kiszka (Jan.Kiszka@web.de) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute +it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment in the + product documentation would be appreciated but is not required. +2. Altered versions must be plainly marked as such, + and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any distribution. diff --git a/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf b/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf new file mode 100644 index 00000000..ccda1d87 --- /dev/null +++ b/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf @@ -0,0 +1,137 @@ +; IrCOMM2k.inf +; +; Installation file for the Virtual Infrared-COM-Port +; +; (c) Copyright 2001, 2002 Jan Kiszka +; + +[Version] +Signature="$Windows NT$" +Provider=%JK% +Class=Ports +ClassGUID={4d36e978-e325-11ce-bfc1-08002be10318} +;DriverVer=03/26/2002,1.2.1.0 + +[DestinationDirs] +IrCOMM2k.Copy2Drivers = 12 +IrCOMM2k.Copy2Winnt = 10 +IrCOMM2k.Copy2System32 = 11 +IrCOMM2k.Copy2Help = 18 + + +; +; Driver information +; + +[Manufacturer] +%JK% = JK.Mfg + +[JK.Mfg] +%JK.DeviceDescIrCOMM% = IrCOMM2k_inst,IrCOMM2k + + +; +; General installation section +; + +[IrCOMM2k_inst] +CopyFiles = IrCOMM2k.Copy2Drivers ;,IrCOMM2k.Copy2System32,IrCOMM2k.Copy2Help,IrCOMM2k.Copy2Winnt +;AddReg = IrCOMM2k_inst_AddReg + + +; +; File sections +; + +[IrCOMM2k.Copy2Drivers] +ircomm2k.sys,,,2 + +;[IrCOMM2k.Copy2System32] +;ircomm2k.exe,,,2 +;ircomm2k.dll,,,2 + +;[IrCOMM2k.Copy2Help] +;ircomm2k.hlp,,,2 + +;[IrCOMM2k.Copy2Winnt] +;IrCOMM2k-Setup.exe,Setup.exe,,2 + + +; +; Service Installation +; + +[IrCOMM2k_inst.Services] +AddService = IrCOMM2k,0x00000002,IrCOMM2k_DriverService_Inst,IrCOMM2k_DriverEventLog_Inst +;AddService = IrCOMM2kSvc,,IrCOMM2k_Service_Inst + +[IrCOMM2k_DriverService_Inst] +DisplayName = %IrCOMM2k.DrvName% +ServiceType = 1 ; SERVICE_KERNEL_DRIVER +StartType = 3 ; SERVICE_DEMAND_START +ErrorControl = 0 ; SERVICE_ERROR_IGNORE +ServiceBinary = %12%\ircomm2k.sys + +;[IrCOMM2k_Service_Inst] +;DisplayName = %IrCOMM2k.SvcName% +;Description = %IrCOMM2k.SvcDesc% +;ServiceType = 0x00000120 ; SERVICE_WIN32_SHARE_PROCESS, SERVICE_INTERACTIVE_PROCESS +;StartType = 2 ; SERVICE_AUTO_START +;ErrorControl = 0 ; SERVICE_ERROR_IGNORE +;ServiceBinary = %11%\ircomm2k.exe +;Dependencies = IrCOMM2k +;AddReg = IrCOMM2kSvcAddReg + + +[IrCOMM2k_inst.nt.HW] +AddReg=IrCOMM2kHwAddReg + +[IrCOMM2kHwAddReg] +HKR,,PortSubClass,REG_BINARY,0x00000001 +;HKR,,TimeoutScaling,REG_DWORD,0x00000001 +;HKR,,StatusLines,REG_DWORD,0x00000000 + +;[IrCOMM2k_inst_AddReg] +;HKR,,EnumPropPages32,,"ircomm2k.dll,IrCOMM2kPropPageProvider" +;HKLM,%UNINSTALL_KEY%,DisplayIcon,0x00020000,"%windir%\IrCOMM2k-Setup.exe" +;HKLM,%UNINSTALL_KEY%,DisplayName,,"IrCOMM2k 1.2.1 " +;HKLM,%UNINSTALL_KEY%,DisplayVersion,,"1.2.1" +;HKLM,%UNINSTALL_KEY%,HelpLink,,"http://www.ircomm2k.de" +;HKLM,%UNINSTALL_KEY%,Publisher,,%JK% +;HKLM,%UNINSTALL_KEY%,UninstallString,0x00020000,"%windir%\IrCOMM2k-Setup.exe" + +;[IrCOMM2kSvcAddReg] +;HKR,Parameters,ActiveConnectOnly,REG_DWORD,0x00000000 + + +[IrCOMM2k_DriverEventLog_Inst] +AddReg = IrCOMM2k_DriverEventLog_AddReg + +[IrCOMM2k_DriverEventLog_AddReg] +HKR,,EventMessageFile,REG_EXPAND_SZ,"%SystemRoot%\System32\IoLogMsg.dll;%SystemRoot%\System32\drivers\ircomm2k.sys" +HKR,,TypesSupported,REG_DWORD,7 + + +[Strings] + +; +; Non-Localizable Strings +; + +REG_SZ = 0x00000000 +REG_MULTI_SZ = 0x00010000 +REG_EXPAND_SZ = 0x00020000 +REG_BINARY = 0x00000001 +REG_DWORD = 0x00010001 +SERVICEROOT = "System\CurrentControlSet\Services" +UNINSTALL_KEY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrCOMM2k" + +; +; Localizable Strings +; + +JK = "Jan Kiszka" +JK.DeviceDescIrCOMM = "Virtueller Infrarot-Kommunikationsanschluss" +IrCOMM2k.DrvName = "Virtueller Infrarot-Kommunikationsanschluss" +;IrCOMM2k.SvcName = "Virtueller Infrarot-Kommunikationsanschlu, Dienstprogramm" +;IrCOMM2k.SvcDesc = "Bildet ber Infarot einen Kommunikationsanschlu nach." diff --git a/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys b/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys new file mode 100644 index 00000000..7882583b Binary files /dev/null and b/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys differ diff --git a/altosui/Instdrv/NSIS/Plugins/InstDrv.dll b/altosui/Instdrv/NSIS/Plugins/InstDrv.dll new file mode 100644 index 00000000..482e955e Binary files /dev/null and b/altosui/Instdrv/NSIS/Plugins/InstDrv.dll differ diff --git a/altosui/Makefile-standalone b/altosui/Makefile-standalone new file mode 100644 index 00000000..a95a5aa8 --- /dev/null +++ b/altosui/Makefile-standalone @@ -0,0 +1,184 @@ +.SUFFIXES: .java .class + +CLASSPATH=classes:./*:/usr/share/java/* +CLASSFILES=\ + Altos.class \ + AltosChannelMenu.class \ + AltosConfig.class \ + AltosConfigUI.class \ + AltosConvert.class \ + AltosCRCException.class \ + AltosCSV.class \ + AltosCSVUI.class \ + AltosDebug.class \ + AltosEepromDownload.class \ + AltosEepromMonitor.class \ + AltosEepromReader.class \ + AltosEepromRecord.class \ + AltosFile.class \ + AltosFlash.class \ + AltosFlashUI.class \ + AltosFlightInfoTableModel.class \ + AltosFlightStatusTableModel.class \ + AltosGPS.class \ + AltosGreatCircle.class \ + AltosHexfile.class \ + AltosLine.class \ + AltosInfoTable.class \ + AltosLog.class \ + AltosLogfileChooser.class \ + AltosParse.class \ + AltosPreferences.class \ + AltosReader.class \ + AltosRecord.class \ + AltosSerialMonitor.class \ + AltosSerial.class \ + AltosState.class \ + AltosStatusTable.class \ + AltosTelemetry.class \ + AltosTelemetryReader.class \ + AltosUI.class \ + AltosDevice.class \ + AltosDeviceDialog.class \ + AltosRomconfig.class \ + AltosRomconfigUI.class \ + AltosVoice.class + +JAVA_ICON=../../icon/altus-metrum-16x16.jpg +WINDOWS_ICON=../../icon/altus-metrum.ico + +# where altosui.jar gets installed +ALTOSLIB=/usr/share/java + +# where freetts.jar is to be found +FREETTSLIB=/usr/share/java + +# all of the freetts files +FREETTSJAR= \ + $(FREETTSLIB)/cmudict04.jar \ + $(FREETTSLIB)/cmulex.jar \ + $(FREETTSLIB)/cmu_time_awb.jar \ + $(FREETTSLIB)/cmutimelex.jar \ + $(FREETTSLIB)/cmu_us_kal.jar \ + $(FREETTSLIB)/en_us.jar \ + $(FREETTSLIB)/freetts.jar + +# The current hex files +HEXLIB=../../src +HEXFILES = \ + $(HEXLIB)/telemetrum-v1.0.ihx \ + $(HEXLIB)/teledongle-v0.2.ihx + +JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation + +ALTOSUIJAR = altosui.jar +FATJAR = fat/altosui.jar + +OS:=$(shell uname) + +LINUX_APP=altosui + +DARWIN_ZIP=Altos-Mac.zip + +WINDOWS_EXE=Altos-Windows.exe + +LINUX_TGZ=Altos-Linux.tgz + +all: altosui.jar $(LINUX_APP) +fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) + +$(CLASSFILES): + +.java.class: + javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java + +altosui.jar: classes/images classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt + cd ./classes && jar cfm ../$@ altosui/Manifest.txt images/* altosui/*.class libaltosJNI/*.class + +Manifest.txt: Makefile $(CLASSFILES) + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: $(FREETTSLIB)/freetts.jar" >> $@ + +classes/altosui: + mkdir -p classes + ln -sf .. classes/altosui + +classes/libaltosJNI: + mkdir -p classes + ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI + +classes/images: + mkdir -p classes/images + ln -sf ../../$(JAVA_ICON) classes/images + +altosui: + echo "#!/bin/sh" > $@ + echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ + chmod +x ./altosui + +fat/altosui: + echo "#!/bin/sh" > $@ + echo 'ME=`which "$0"`' >> $@ + echo 'DIR=`dirname "$ME"`' >> $@ + echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ + chmod +x $@ + +fat/altosui.jar: $(CLASSFILES) $(JAVA_ICON) fat/classes/Manifest.txt + mkdir -p fat/classes + test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui + mkdir -p fat/classes/images + cp $(JAVA_ICON) fat/classes/images + test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI + cd ./fat/classes && jar cfm ../../$@ Manifest.txt images/* altosui/*.class libaltosJNI/*.class + +fat/classes/Manifest.txt: $(CLASSFILES) Makefile + mkdir -p fat/classes + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: freetts.jar" >> $@ + +install: altosui.jar altosui + install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 + install altosui $(DESTDIR)/usr/bin/altosui + +clean: + rm -f *.class altosui.jar + rm -f AltosUI.app/Contents/Resources/Java/* + rm -rf classes + rm -rf windows linux + +distclean: clean + rm -f $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) + rm -rf darwin fat + +FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) + +LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui +$(LINUX_TGZ): $(LINUX_FILES) + rm -f $@ + mkdir -p linux/AltOS + rm -f linux/AltOS/* + cp $(LINUX_FILES) linux/AltOS + cd linux && tar czf ../$@ AltOS + +DARWIN_RESOURCES=$(FATJAR) $(FREETTSJAR) ../libaltos/libaltos.dylib +DARWIN_EXTRA=$(HEXFILES) +DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) + +$(DARWIN_ZIP): $(DARWIN_FILES) + rm -f $@ + cp -a AltosUI.app darwin/ + mkdir -p darwin/AltosUI.app/Contents/Resources/Java + cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java + mkdir -p darwin/AltOS + cp $(DARWIN_EXTRA) darwin/AltOS + cd darwin && zip -r ../$@ AltosUI.app AltOS + +WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ICON) + +$(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi + rm -f $@ + mkdir -p windows/AltOS + rm -f windows/AltOS/* + cp $(WINDOWS_FILES) windows/AltOS + makensis altos-windows.nsi diff --git a/altosui/Makefile.am b/altosui/Makefile.am new file mode 100644 index 00000000..e2ff55af --- /dev/null +++ b/altosui/Makefile.am @@ -0,0 +1,272 @@ +SUBDIRS=libaltos +JAVAROOT=classes +AM_JAVACFLAGS=-encoding UTF-8 + +man_MANS=altosui.1 + +altoslibdir=$(libdir)/altos + +CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:libaltos:$(FREETTS)/*:/usr/share/java/*" + +bin_SCRIPTS=altosui + +altosui_JAVA = \ + GrabNDrag.java \ + AltosAscent.java \ + AltosChannelMenu.java \ + AltosConfig.java \ + AltosConfigUI.java \ + AltosConfigureUI.java \ + AltosConvert.java \ + AltosCRCException.java \ + AltosCSV.java \ + AltosCSVUI.java \ + AltosDebug.java \ + AltosDescent.java \ + AltosDeviceDialog.java \ + AltosDevice.java \ + AltosDisplayThread.java \ + AltosEepromDownload.java \ + AltosEepromMonitor.java \ + AltosEepromIterable.java \ + AltosEepromRecord.java \ + AltosFile.java \ + AltosFlash.java \ + AltosFlashUI.java \ + AltosFlightDisplay.java \ + AltosFlightInfoTableModel.java \ + AltosFlightReader.java \ + AltosFlightStatus.java \ + AltosFlightUI.java \ + AltosGPS.java \ + AltosGreatCircle.java \ + AltosHexfile.java \ + Altos.java \ + AltosIgnite.java \ + AltosIgniteUI.java \ + AltosInfoTable.java \ + AltosKML.java \ + AltosLanded.java \ + AltosLed.java \ + AltosLights.java \ + AltosLine.java \ + AltosLog.java \ + AltosPad.java \ + AltosParse.java \ + AltosPreferences.java \ + AltosReader.java \ + AltosRecord.java \ + AltosRecordIterable.java \ + AltosTelemetryReader.java \ + AltosReplayReader.java \ + AltosRomconfig.java \ + AltosRomconfigUI.java \ + AltosSerial.java \ + AltosSerialInUseException.java \ + AltosSerialMonitor.java \ + AltosSiteMap.java \ + AltosSiteMapCache.java \ + AltosSiteMapTile.java \ + AltosState.java \ + AltosTelemetry.java \ + AltosTelemetryIterable.java \ + AltosUI.java \ + AltosWriter.java \ + AltosDataPointReader.java \ + AltosDataPoint.java \ + AltosGraph.java \ + AltosGraphTime.java \ + AltosGraphUI.java \ + AltosDataChooser.java \ + AltosVoice.java + +JFREECHART_CLASS= \ + jfreechart.jar + +JCOMMON_CLASS=\ + jcommon.jar + +FREETTS_CLASS= \ + cmudict04.jar \ + cmulex.jar \ + cmu_time_awb.jar \ + cmutimelex.jar \ + cmu_us_kal.jar \ + en_us.jar \ + freetts.jar + +LIBALTOS= \ + libaltos.so \ + libaltos.dylib \ + altos.dll + +JAR=altosui.jar + +FATJAR=altosui-fat.jar + +# Icons +ICONDIR=$(top_srcdir)/icon + +JAVA_ICON=$(ICONDIR)/altus-metrum-16x16.jpg + +ICONS= $(ICONDIR)/redled.png $(ICONDIR)/redoff.png \ + $(ICONDIR)/greenled.png $(ICONDIR)/greenoff.png \ + $(ICONDIR)/grayled.png $(ICONDIR)/grayoff.png + +# icon base names for jar +ICONJAR= -C $(ICONDIR) altus-metrum-16x16.jpg \ + -C $(ICONDIR) redled.png -C $(ICONDIR) redoff.png \ + -C $(ICONDIR) greenled.png -C $(ICONDIR) greenoff.png \ + -C $(ICONDIR) grayon.png -C $(ICONDIR) grayled.png + +WINDOWS_ICON=$(ICONDIR)/altus-metrum.ico + +# Firmware +FIRMWARE_TD=$(top_srcdir)/src/teledongle-v0.2-$(VERSION).ihx +FIRMWARE_TM=$(top_srcdir)/src/telemetrum-v1.0-$(VERSION).ihx +FIRMWARE=$(FIRMWARE_TM) $(FIRMWARE_TD) + +# Distribution targets +LINUX_DIST=Altos-Linux-$(VERSION).tar.bz2 +MACOSX_DIST=Altos-Mac-$(VERSION).zip +WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe + +FAT_FILES=$(FATJAR) $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) + +LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) +LINUX_EXTRA=altosui-fat + +MACOSX_FILES=$(FAT_FILES) libaltos.dylib +MACOSX_EXTRA=$(FIRMWARE) + +WINDOWS_FILES=$(FAT_FILES) altos.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) + +all-local: classes/altosui $(JAR) altosui altosui-test altosui-jdb + +clean-local: + -rm -rf classes $(JAR) $(FATJAR) \ + $(LINUX_DIST) $(MACOSX_DIST) windows $(WINDOWS_DIST) $(FREETTS_CLASS) \ + $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ + altosui altosui-test altosui-jdb macosx linux + +if FATINSTALL + +FATTARGET=$(FATDIR)/$(VERSION) + +LINUX_DIST_TARGET=$(FATTARGET)/$(LINUX_DIST) +MACOSX_DIST_TARGET=$(FATTARGET)/$(MACOSX_DIST) +WINDOWS_DIST_TARGET=$(FATTARGET)/$(WINDOWS_DIST) + +fat: $(LINUX_DIST_TARGET) $(MACOSX_DIST_TARGET) $(WINDOWS_DIST_TARGET) + +$(LINUX_DIST_TARGET): $(LINUX_DIST) + mkdir -p $(FATTARGET) + cp -p $< $@ + +$(MACOSX_DIST_TARGET): $(MACOSX_DIST) + mkdir -p $(FATTARGET) + cp -p $< $@ + +$(WINDOWS_DIST_TARGET): $(WINDOWS_DIST) + mkdir -p $(FATTARGET) + cp -p $< $@ + +else +fat: $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) +endif + + +altosuidir=$(datadir)/java + +install-altosuiJAVA: altosui.jar + @$(NORMAL_INSTALL) + test -z "$(altosuidir)" || $(MKDIR_P) "$(DESTDIR)$(altosuidir)" + echo " $(INSTALL_DATA)" "$<" "'$(DESTDIR)$(altosuidir)/altosui.jar'"; \ + $(INSTALL_DATA) "$<" "$(DESTDIR)$(altosuidir)" + +classes/altosui: + mkdir -p classes/altosui + +$(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) + jar cfm $@ Manifest.txt \ + $(ICONJAR) \ + -C classes altosui \ + -C libaltos libaltosJNI + +$(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) $(JAVA_ICON) + jar cfm $@ Manifest-fat.txt \ + $(ICONJAR) \ + -C classes altosui \ + -C libaltos libaltosJNI + +Manifest.txt: Makefile + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: $(FREETTS)/freetts.jar $(JFREECHART)/jfreechart.jar $(JCOMMON)/jcommon.jar" >> $@ + +Manifest-fat.txt: + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: freetts.jar jfreechart.jar jcommon.jar" >> $@ + +altosui: Makefile + echo "#!/bin/sh" > $@ + echo 'exec java -cp "$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="$(altoslibdir)" -jar "$(altosuidir)/altosui.jar" "$$@"' >> $@ + chmod +x $@ + +altosui-test: Makefile + echo "#!/bin/sh" > $@ + echo 'exec java -cp "$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="libaltos/.libs" -jar altosui.jar "$$@"' >> $@ + chmod +x $@ + +altosui-jdb: Makefile + echo "#!/bin/sh" > $@ + echo 'exec jdb -classpath "classes:libaltos:$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="libaltos/.libs" altosui/AltosUI "$$@"' >> $@ + chmod +x $@ + +libaltos.so: + -rm -f "$@" + $(LN_S) libaltos/.libs/"$@" . + +libaltos.dylib: + -rm -f "$@" + $(LN_S) libaltos/"$@" . + +altos.dll: + -rm -f "$@" + $(LN_S) libaltos/"$@" . + +$(FREETTS_CLASS): + -rm -f "$@" + $(LN_S) "$(FREETTS)"/"$@" . + +$(JFREECHART_CLASS): + -rm -f "$@" + $(LN_S) "$(JFREECHART)"/"$@" . + +$(JCOMMON_CLASS): + -rm -f "$@" + $(LN_S) "$(JCOMMON)"/"$@" . + +$(LINUX_DIST): $(LINUX_FILES) $(LINUX_EXTRA) + -rm -f $@ + -rm -rf linux + mkdir -p linux/AltOS + cp -p $(LINUX_FILES) linux/AltOS + cp -p altosui-fat linux/AltOS/altosui + chmod +x linux/AltOS/altosui + tar cjf $@ -C linux AltOS + +$(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) + -rm -f $@ + -rm -rf macosx + mkdir macosx + cp -a AltosUI.app macosx/ + mkdir -p macosx/AltOS macosx/AltosUI.app/Contents/Resources/Java + cp -p $(FATJAR) macosx/AltosUI.app/Contents/Resources/Java/altosui.jar + cp -p $(FREETTS_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java + cp -p $(JFREECHART_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java + cp -p $(MACOSX_EXTRA) macosx/AltOS + cd macosx && zip -r ../$@ AltosUI.app AltOS + +$(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi + -rm -f $@ + makensis -Oaltos-windows.log "-XOutFile $@" "-DVERSION=$(VERSION)" altos-windows.nsi diff --git a/altosui/altos-windows.nsi b/altosui/altos-windows.nsi new file mode 100644 index 00000000..37777fd6 --- /dev/null +++ b/altosui/altos-windows.nsi @@ -0,0 +1,113 @@ +!addplugindir Instdrv/NSIS/Plugins + +Name "Altus Metrum Installer" + +; Default install directory +InstallDir "$PROGRAMFILES\AltusMetrum" + +; Tell the installer where to re-install a new version +InstallDirRegKey HKLM "Software\AltusMetrum" "Install_Dir" + +LicenseText "GNU General Public License Version 2" +LicenseData "../../COPYING" + +; Need admin privs for Vista or Win7 +RequestExecutionLevel admin + +ShowInstDetails Show + +ComponentText "Altus Metrum Software and Driver Installer" + +; Pages to present + +Page license +Page components +Page directory +Page instfiles + +UninstPage uninstConfirm +UninstPage instfiles + +; And the stuff to install + +Section "Install Driver" InstDriver + InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} "Altus Metrum" + Pop $0 + DetailPrint "InitDriverSetup: $0" + + InstDrv::DeleteOemInfFiles /NOUNLOAD + InstDrv::CreateDevice /NOUNLOAD + SetOutPath $TEMP + File "../../telemetrum.inf" + InstDrv::InstallDriver /NOUNLOAD "$TEMP\telemetrum.inf" + + SetOutPath $INSTDIR + File "../../telemetrum.inf" +SectionEnd + +Section "AltosUI Application" + SetOutPath $INSTDIR + + File "altosui-fat.jar" + File "cmudict04.jar" + File "cmulex.jar" + File "cmu_time_awb.jar" + File "cmutimelex.jar" + File "cmu_us_kal.jar" + File "en_us.jar" + File "freetts.jar" + + File "*.dll" + + File "../../icon/*.ico" + + CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui-fat.jar" "" "$INSTDIR\altus-metrum.ico" +SectionEnd + +Section "AltosUI Desktop Shortcut" + CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui-fat.jar" "" "$INSTDIR\altus-metrum.ico" +SectionEnd + +Section "TeleMetrum and TeleDongle Firmware" + + SetOutPath $INSTDIR + + File "../../src/telemetrum-v1.0/telemetrum-v1.0-${VERSION}.ihx" + File "../../src/teledongle-v0.2/teledongle-v0.2-${VERSION}.ihx" + +SectionEnd + +Section "Uninstaller" + + ; Deal with the uninstaller + + SetOutPath $INSTDIR + + ; Write the install path to the registry + WriteRegStr HKLM SOFTWARE\AltusMetrum "Install_Dir" "$INSTDIR" + + ; Write the uninstall keys for windows + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "DisplayName" "Altus Metrum" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "UninstallString" '"$INSTDIR\uninstall.exe"' + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoModify" "1" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoRepair" "1" + + WriteUninstaller "uninstall.exe" +SectionEnd + +Section "Uninstall" + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" + DeleteRegKey HKLM "Software\AltusMetrum" + + Delete "$INSTDIR\*.*" + RMDir "$INSTDIR" + + ; Remove devices + InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} "Altus Metrum" + InstDrv::DeleteOemInfFiles /NOUNLOAD + InstDrv::RemoveAllDevices + + ; Remove shortcuts, if any + Delete "$SMPROGRAMS\AltusMetrum.lnk" + Delete "$DESKTOP\AltusMetrum.lnk" +SectionEnd diff --git a/altosui/altosui-fat b/altosui/altosui-fat new file mode 100755 index 00000000..95b1c051 --- /dev/null +++ b/altosui/altosui-fat @@ -0,0 +1,4 @@ +#!/bin/sh +me=`which "$0"` +dir=`dirname "$me"` +exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui-fat.jar "$@" diff --git a/altosui/altosui.1 b/altosui/altosui.1 new file mode 100644 index 00000000..57fa4489 --- /dev/null +++ b/altosui/altosui.1 @@ -0,0 +1,46 @@ +.\" +.\" Copyright © 2010 Bdale Garbee +.\" +.\" 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 ALTOSUI 1 "altosui" "" +.SH NAME +altosui \- Rocket flight monitor +.SH SYNOPSIS +.B "altosui" +.SH DESCRIPTION +.I altosui +connects to a TeleDongle or TeleMetrum device through a USB serial device. +It provides a menu-oriented +user interface to monitor, record and review rocket flight data. +.SH USAGE +When connected to a TeleDongle device, altosui turns on the radio +receiver and listens for telemetry packets. It displays the received +telemetry data, and reports flight status via voice synthesis. All +received telemetry information is recorded to a file. +.P +When connected to a TeleMetrum device, altosui can be used to configure the +TeleMetrum, and to downloads the eeprom data and store it in a file. +.P +A number of other menu options exist, including the ability to export flight +data in different formats. +.SH FILES +All data log files are recorded into a user-specified directory +(default ~/TeleMetrum). Files are named using the current date, the serial +number of the reporting device, the flight number recorded in the data +and either '.telem' for telemetry data or '.eeprom' for eeprom data. +.SH AUTHOR +Keith Packard diff --git a/altosui/altusmetrum.jpg b/altosui/altusmetrum.jpg new file mode 100644 index 00000000..04027921 Binary files /dev/null and b/altosui/altusmetrum.jpg differ diff --git a/altosui/libaltos/.gitignore b/altosui/libaltos/.gitignore new file mode 100644 index 00000000..c490e6f8 --- /dev/null +++ b/altosui/libaltos/.gitignore @@ -0,0 +1,12 @@ +*.so +*.lo +*.la +*.java +*.class +.libs/ +classlibaltos.stamp +libaltos_wrap.c +libaltosJNI +cjnitest +libaltos.swig +swig_bindings/ diff --git a/altosui/libaltos/Makefile-standalone b/altosui/libaltos/Makefile-standalone new file mode 100644 index 00000000..4e438050 --- /dev/null +++ b/altosui/libaltos/Makefile-standalone @@ -0,0 +1,126 @@ +OS:=$(shell uname) + +# +# Linux +# +ifeq ($(OS),Linux) + +JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include + +OS_LIB_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) + +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) + +OS_LDFLAGS= + +LIBNAME=libaltos.so +EXEEXT= +endif + +# +# Darwin (Mac OS X) +# +ifeq ($(OS),Darwin) + +OS_LIB_CFLAGS=\ + -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ + --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ + -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ + -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ + -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) + +OS_LDFLAGS =\ + -framework IOKit -framework CoreFoundation + +LIBNAME=libaltos.dylib +EXEEXT= + +endif + +# +# Windows +# +ifneq (,$(findstring MINGW,$(OS))) + +CC=gcc + +OS_LIB_CFLAGS = -DWINDOWS -mconsole -DBUILD_DLL +OS_APP_CFLAGS = -DWINDOWS -mconsole + +OS_LDFLAGS = -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lole32 \ + -ladvapi32 -lcomctl32 -mconsole -Wl,--add-stdcall-alias + +LIBNAME=altos.dll + +EXEEXT=.exe + +endif + +.SUFFIXES: .java .class + +CLASSPATH=".:jnitest/*:libaltosJNI:/usr/share/java/*" + +SWIG_DIR=swig_bindings/java +SWIG_FILE=$(SWIG_DIR)/libaltos.swig +SWIG_WRAP=$(SWIG_DIR)/libaltos_wrap.c + +JNI_DIR=libaltosJNI +JNI_FILE=$(JNI_DIR)/libaltosJNI.java +JNI_SRCS=$(JNI_FILE) \ + $(JNI_DIR)/SWIGTYPE_p_altos_file.java \ + $(JNI_DIR)/SWIGTYPE_p_altos_list.java \ + $(JNI_DIR)/altos_device.java \ + $(JNI_DIR)/libaltos.java + +JAVAFILES=\ + $(JNI_SRCS) + +CLASSFILES = $(JAVAFILES:%.java=%.class) + +JAVAFLAGS=-Xlint:unchecked + +CJNITEST=cjnitest$(EXEEXT) + +all: $(LIBNAME) $(CJNITEST) $(CLASSFILES) + +.java.class: + javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java + +CFLAGS=$(OS_LIB_CFLAGS) -O -I. + +LDFLAGS=$(OS_LDFLAGS) + +HEADERS=libaltos.h +SRCS = libaltos.c $(SWIG_WRAP) +OBJS = $(SRCS:%.c=%.o) +LIBS = $(DARWIN_LIBS) + +$(CJNITEST): cjnitest.c $(LIBNAME) + $(CC) -o $@ $(OS_APP_CFLAGS) cjnitest.c $(LIBNAME) $(LIBS) $(LDFLAGS) + +$(LIBNAME): $(OBJS) + $(CC) -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) + +clean: + rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o + rm -rf swig_bindings libaltosJNI + +distclean: clean + +$(JNI_FILE): libaltos.i0 $(HEADERS) + mkdir -p $(SWIG_DIR) + mkdir -p libaltosJNI + sed 's;//%;%;' libaltos.i0 $(HEADERS) > $(SWIG_FILE) + swig -java -package libaltosJNI $(SWIG_FILE) + cp swig_bindings/java/*.java libaltosJNI + +$(SWIG_WRAP): $(JNI_FILE) + +ifeq ($(OS),Linux) +install: $(LIBNAME) + install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) + +endif + +.NOTPARALLEL: diff --git a/altosui/libaltos/Makefile.am b/altosui/libaltos/Makefile.am new file mode 100644 index 00000000..388d2104 --- /dev/null +++ b/altosui/libaltos/Makefile.am @@ -0,0 +1,41 @@ +JAVAC=javac +AM_CFLAGS=-DLINUX -DPOSIX_TTY -I$(JVM_INCLUDE) +AM_JAVACFLAGS=-encoding UTF-8 + +altoslibdir=$(libdir)/altos + +altoslib_LTLIBRARIES=libaltos.la + +libaltos_la_LDFLAGS = -version-info 1:0:1 + +libaltos_la_SOURCES=\ + libaltos.c \ + libaltos_wrap.c + +noinst_PROGRAMS=cjnitest + +cjnitest_LDADD=libaltos.la + +LIBS= + +HFILES=libaltos.h + +SWIG_FILE=libaltos.swig + +CLASSDIR=libaltosJNI + +$(SWIG_FILE): libaltos.i0 $(HFILES) + sed 's;//%;%;' libaltos.i0 $(HFILES) > $(SWIG_FILE) + +all-local: classlibaltos.stamp + +libaltos_wrap.c: classlibaltos.stamp + +classlibaltos.stamp: $(SWIG_FILE) + swig -java -package libaltosJNI $(SWIG_FILE) + mkdir -p libaltosJNI + $(JAVAC) -d . $(AM_JAVACFLAGS) $(JAVACFLAGS) *.java && \ + touch classlibaltos.stamp + +clean-local: + -rm -rf libaltosJNI *.class *.java classlibaltos.stamp $(SWIG_FILE) libaltos_wrap.c diff --git a/altosui/libaltos/altos.dll b/altosui/libaltos/altos.dll new file mode 100755 index 00000000..28e9b4ad Binary files /dev/null and b/altosui/libaltos/altos.dll differ diff --git a/altosui/libaltos/cjnitest.c b/altosui/libaltos/cjnitest.c new file mode 100644 index 00000000..c6d6e069 --- /dev/null +++ b/altosui/libaltos/cjnitest.c @@ -0,0 +1,43 @@ +#include +#include "libaltos.h" + +static void +altos_puts(struct altos_file *file, char *string) +{ + char c; + + while ((c = *string++)) + altos_putchar(file, c); +} + +main () +{ + struct altos_device device; + struct altos_list *list; + + altos_init(); + list = altos_list_start(); + while (altos_list_next(list, &device)) { + struct altos_file *file; + int c; + + printf ("%04x:%04x %-20s %4d %s\n", device.vendor, device.product, + device.name, device.serial, device.path); + + file = altos_open(&device); + if (!file) { + printf("altos_open failed\n"); + continue; + } + altos_puts(file,"v\nc s\n"); + altos_flush(file); + while ((c = altos_getchar(file, 100)) >= 0) { + putchar (c); + } + if (c != LIBALTOS_TIMEOUT) + printf ("getchar returns %d\n", c); + altos_close(file); + } + altos_list_finish(list); + altos_fini(); +} diff --git a/altosui/libaltos/libaltos.c b/altosui/libaltos/libaltos.c new file mode 100644 index 00000000..465f0ac8 --- /dev/null +++ b/altosui/libaltos/libaltos.c @@ -0,0 +1,1028 @@ +/* + * Copyright © 2010 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 "libaltos.h" +#include +#include +#include + +#define USE_POLL + +PUBLIC int +altos_init(void) +{ + return LIBALTOS_SUCCESS; +} + +PUBLIC void +altos_fini(void) +{ +} + +#ifdef DARWIN + +#undef USE_POLL + +/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */ +static char * +altos_strndup (const char *s, size_t n) +{ + size_t len = strlen (s); + char *ret; + + if (len <= n) + return strdup (s); + ret = malloc(n + 1); + strncpy(ret, s, n); + ret[n] = '\0'; + return ret; +} + +#else +#define altos_strndup strndup +#endif + +/* + * Scan for Altus Metrum devices by looking through /sys + */ + +#ifdef LINUX + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +static char * +cc_fullname (char *dir, char *file) +{ + char *new; + int dlen = strlen (dir); + int flen = strlen (file); + int slen = 0; + + if (dir[dlen-1] != '/') + slen = 1; + new = malloc (dlen + slen + flen + 1); + if (!new) + return 0; + strcpy(new, dir); + if (slen) + strcat (new, "/"); + strcat(new, file); + return new; +} + +static char * +cc_basename(char *file) +{ + char *b; + + b = strrchr(file, '/'); + if (!b) + return file; + return b + 1; +} + +static char * +load_string(char *dir, char *file) +{ + char *full = cc_fullname(dir, file); + char line[4096]; + char *r; + FILE *f; + int rlen; + + f = fopen(full, "r"); + free(full); + if (!f) + return NULL; + r = fgets(line, sizeof (line), f); + fclose(f); + if (!r) + return NULL; + rlen = strlen(r); + if (r[rlen-1] == '\n') + r[rlen-1] = '\0'; + return strdup(r); +} + +static int +load_hex(char *dir, char *file) +{ + char *line; + char *end; + long i; + + line = load_string(dir, file); + if (!line) + return -1; + i = strtol(line, &end, 16); + free(line); + if (end == line) + return -1; + return i; +} + +static int +load_dec(char *dir, char *file) +{ + char *line; + char *end; + long i; + + line = load_string(dir, file); + if (!line) + return -1; + i = strtol(line, &end, 10); + free(line); + if (end == line) + return -1; + return i; +} + +static int +dir_filter_tty_colon(const struct dirent *d) +{ + return strncmp(d->d_name, "tty:", 4) == 0; +} + +static int +dir_filter_tty(const struct dirent *d) +{ + return strncmp(d->d_name, "tty", 3) == 0; +} + +struct altos_usbdev { + char *sys; + char *tty; + char *manufacturer; + char *product_name; + int serial; /* AltOS always uses simple integer serial numbers */ + int idProduct; + int idVendor; +}; + +static char * +usb_tty(char *sys) +{ + char *base; + int num_configs; + int config; + struct dirent **namelist; + int interface; + int num_interfaces; + char endpoint_base[20]; + char *endpoint_full; + char *tty_dir; + int ntty; + char *tty; + + base = cc_basename(sys); + num_configs = load_hex(sys, "bNumConfigurations"); + num_interfaces = load_hex(sys, "bNumInterfaces"); + for (config = 1; config <= num_configs; config++) { + for (interface = 0; interface < num_interfaces; interface++) { + sprintf(endpoint_base, "%s:%d.%d", + base, config, interface); + endpoint_full = cc_fullname(sys, endpoint_base); + + /* Check for tty:ttyACMx style names + */ + ntty = scandir(endpoint_full, &namelist, + dir_filter_tty_colon, + alphasort); + if (ntty > 0) { + free(endpoint_full); + tty = cc_fullname("/dev", namelist[0]->d_name + 4); + free(namelist); + return tty; + } + + /* Check for tty/ttyACMx style names + */ + tty_dir = cc_fullname(endpoint_full, "tty"); + free(endpoint_full); + ntty = scandir(tty_dir, &namelist, + dir_filter_tty, + alphasort); + free (tty_dir); + if (ntty > 0) { + tty = cc_fullname("/dev", namelist[0]->d_name); + free(namelist); + return tty; + } + } + } + return NULL; +} + +static struct altos_usbdev * +usb_scan_device(char *sys) +{ + struct altos_usbdev *usbdev; + + usbdev = calloc(1, sizeof (struct altos_usbdev)); + if (!usbdev) + return NULL; + usbdev->sys = strdup(sys); + usbdev->manufacturer = load_string(sys, "manufacturer"); + usbdev->product_name = load_string(sys, "product"); + usbdev->serial = load_dec(sys, "serial"); + usbdev->idProduct = load_hex(sys, "idProduct"); + usbdev->idVendor = load_hex(sys, "idVendor"); + usbdev->tty = usb_tty(sys); + return usbdev; +} + +static void +usbdev_free(struct altos_usbdev *usbdev) +{ + free(usbdev->sys); + free(usbdev->manufacturer); + free(usbdev->product_name); + /* this can get used as a return value */ + if (usbdev->tty) + free(usbdev->tty); + free(usbdev); +} + +#define USB_DEVICES "/sys/bus/usb/devices" + +static int +dir_filter_dev(const struct dirent *d) +{ + const char *n = d->d_name; + char c; + + while ((c = *n++)) { + if (isdigit(c)) + continue; + if (c == '-') + continue; + if (c == '.' && n != d->d_name + 1) + continue; + return 0; + } + return 1; +} + +struct altos_list { + struct altos_usbdev **dev; + int current; + int ndev; +}; + +struct altos_list * +altos_list_start(void) +{ + int e; + struct dirent **ents; + char *dir; + struct altos_usbdev *dev; + struct altos_list *devs; + int n; + + devs = calloc(1, sizeof (struct altos_list)); + if (!devs) + return NULL; + + n = scandir (USB_DEVICES, &ents, + dir_filter_dev, + alphasort); + if (!n) + return 0; + for (e = 0; e < n; e++) { + dir = cc_fullname(USB_DEVICES, ents[e]->d_name); + dev = usb_scan_device(dir); + free(dir); + if (USB_IS_ALTUSMETRUM(dev->idVendor, dev->idProduct)) { + if (devs->dev) + devs->dev = realloc(devs->dev, + devs->ndev + 1 * sizeof (struct usbdev *)); + else + devs->dev = malloc (sizeof (struct usbdev *)); + devs->dev[devs->ndev++] = dev; + } + } + free(ents); + devs->current = 0; + return devs; +} + +int +altos_list_next(struct altos_list *list, struct altos_device *device) +{ + struct altos_usbdev *dev; + if (list->current >= list->ndev) + return 0; + dev = list->dev[list->current]; + strcpy(device->name, dev->product_name); + device->vendor = dev->idVendor; + device->product = dev->idProduct; + strcpy(device->path, dev->tty); + device->serial = dev->serial; + list->current++; + return 1; +} + +void +altos_list_finish(struct altos_list *usbdevs) +{ + int i; + + if (!usbdevs) + return; + for (i = 0; i < usbdevs->ndev; i++) + usbdev_free(usbdevs->dev[i]); + free(usbdevs); +} + +#endif + +#ifdef DARWIN + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct altos_list { + io_iterator_t iterator; +}; + +static int +get_string(io_object_t object, CFStringRef entry, char *result, int result_len) +{ + CFTypeRef entry_as_string; + Boolean got_string; + + entry_as_string = IORegistryEntrySearchCFProperty (object, + kIOServicePlane, + entry, + kCFAllocatorDefault, + kIORegistryIterateRecursively); + if (entry_as_string) { + got_string = CFStringGetCString(entry_as_string, + result, result_len, + kCFStringEncodingASCII); + + CFRelease(entry_as_string); + if (got_string) + return 1; + } + return 0; +} + +static int +get_number(io_object_t object, CFStringRef entry, int *result) +{ + CFTypeRef entry_as_number; + Boolean got_number; + + entry_as_number = IORegistryEntrySearchCFProperty (object, + kIOServicePlane, + entry, + kCFAllocatorDefault, + kIORegistryIterateRecursively); + if (entry_as_number) { + got_number = CFNumberGetValue(entry_as_number, + kCFNumberIntType, + result); + if (got_number) + return 1; + } + return 0; +} + +struct altos_list * +altos_list_start(void) +{ + struct altos_list *list = calloc (sizeof (struct altos_list), 1); + CFMutableDictionaryRef matching_dictionary = IOServiceMatching("IOUSBDevice"); + io_iterator_t tdIterator; + io_object_t tdObject; + kern_return_t ret; + int i; + + ret = IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dictionary, &list->iterator); + if (ret != kIOReturnSuccess) + return NULL; + return list; +} + +int +altos_list_next(struct altos_list *list, struct altos_device *device) +{ + io_object_t object; + char serial_string[128]; + + for (;;) { + object = IOIteratorNext(list->iterator); + if (!object) + return 0; + + if (!get_number (object, CFSTR(kUSBVendorID), &device->vendor) || + !get_number (object, CFSTR(kUSBProductID), &device->product)) + continue; + if (device->vendor != 0xfffe) + continue; + if (device->product < 0x000a || 0x0013 < device->product) + continue; + if (get_string (object, CFSTR("IOCalloutDevice"), device->path, sizeof (device->path)) && + get_string (object, CFSTR("USB Product Name"), device->name, sizeof (device->name)) && + get_string (object, CFSTR("USB Serial Number"), serial_string, sizeof (serial_string))) { + device->serial = atoi(serial_string); + return 1; + } + } +} + +void +altos_list_finish(struct altos_list *list) +{ + IOObjectRelease (list->iterator); + free(list); +} + +#endif + +#ifdef POSIX_TTY + +#include +#include +#include +#include +#include + +#define USB_BUF_SIZE 64 + +struct altos_file { + int fd; +#ifdef USE_POLL + int pipe[2]; +#else + int out_fd; +#endif + unsigned char out_data[USB_BUF_SIZE]; + int out_used; + unsigned char in_data[USB_BUF_SIZE]; + int in_used; + int in_read; +}; + +PUBLIC struct altos_file * +altos_open(struct altos_device *device) +{ + struct altos_file *file = calloc (sizeof (struct altos_file), 1); + int ret; + struct termios term; + + if (!file) + return NULL; + + file->fd = open(device->path, O_RDWR | O_NOCTTY); + if (file->fd < 0) { + perror(device->path); + free(file); + return NULL; + } +#ifdef USE_POLL + pipe(file->pipe); +#else + file->out_fd = open(device->path, O_RDWR | O_NOCTTY); + if (file->out_fd < 0) { + perror(device->path); + close(file->fd); + free(file); + return NULL; + } +#endif + ret = tcgetattr(file->fd, &term); + if (ret < 0) { + perror("tcgetattr"); + close(file->fd); +#ifndef USE_POLL + close(file->out_fd); +#endif + free(file); + return NULL; + } + cfmakeraw(&term); +#ifdef USE_POLL + term.c_cc[VMIN] = 1; + term.c_cc[VTIME] = 0; +#else + term.c_cc[VMIN] = 0; + term.c_cc[VTIME] = 1; +#endif + ret = tcsetattr(file->fd, TCSAFLUSH, &term); + if (ret < 0) { + perror("tcsetattr"); + close(file->fd); +#ifndef USE_POLL + close(file->out_fd); +#endif + free(file); + return NULL; + } + return file; +} + +PUBLIC void +altos_close(struct altos_file *file) +{ + if (file->fd != -1) { + int fd = file->fd; + file->fd = -1; +#ifdef USE_POLL + write(file->pipe[1], "\r", 1); +#else + close(file->out_fd); + file->out_fd = -1; +#endif + close(fd); + } +} + +PUBLIC void +altos_free(struct altos_file *file) +{ + altos_close(file); + free(file); +} + +PUBLIC int +altos_flush(struct altos_file *file) +{ + if (file->out_used && 0) { + printf ("flush \""); + fwrite(file->out_data, 1, file->out_used, stdout); + printf ("\"\n"); + } + while (file->out_used) { + int ret; + + if (file->fd < 0) + return -EBADF; +#ifdef USE_POLL + ret = write (file->fd, file->out_data, file->out_used); +#else + ret = write (file->out_fd, file->out_data, file->out_used); +#endif + if (ret < 0) + return -errno; + if (ret) { + memmove(file->out_data, file->out_data + ret, + file->out_used - ret); + file->out_used -= ret; + } + } + return 0; +} + +PUBLIC int +altos_putchar(struct altos_file *file, char c) +{ + int ret; + + if (file->out_used == USB_BUF_SIZE) { + ret = altos_flush(file); + if (ret) { + return ret; + } + } + file->out_data[file->out_used++] = c; + ret = 0; + if (file->out_used == USB_BUF_SIZE) + ret = altos_flush(file); + return 0; +} + +#ifdef USE_POLL +#include +#endif + +static int +altos_fill(struct altos_file *file, int timeout) +{ + int ret; +#ifdef USE_POLL + struct pollfd fd[2]; +#endif + + if (timeout == 0) + timeout = -1; + while (file->in_read == file->in_used) { + if (file->fd < 0) + return LIBALTOS_ERROR; +#ifdef USE_POLL + fd[0].fd = file->fd; + fd[0].events = POLLIN|POLLERR|POLLHUP|POLLNVAL; + fd[1].fd = file->pipe[0]; + fd[1].events = POLLIN; + ret = poll(fd, 2, timeout); + if (ret < 0) { + perror("altos_getchar"); + return LIBALTOS_ERROR; + } + if (ret == 0) + return LIBALTOS_TIMEOUT; + + if (fd[0].revents & (POLLHUP|POLLERR|POLLNVAL)) + return LIBALTOS_ERROR; + if (fd[0].revents & POLLIN) +#endif + { + ret = read(file->fd, file->in_data, USB_BUF_SIZE); + if (ret < 0) { + perror("altos_getchar"); + return LIBALTOS_ERROR; + } + file->in_read = 0; + file->in_used = ret; +#ifndef USE_POLL + if (ret == 0 && timeout > 0) + return LIBALTOS_TIMEOUT; +#endif + } + } + if (file->in_used && 0) { + printf ("fill \""); + fwrite(file->in_data, 1, file->in_used, stdout); + printf ("\"\n"); + } + return 0; +} + +PUBLIC int +altos_getchar(struct altos_file *file, int timeout) +{ + int ret; + while (file->in_read == file->in_used) { + if (file->fd < 0) + return LIBALTOS_ERROR; + ret = altos_fill(file, timeout); + if (ret) + return ret; + } + return file->in_data[file->in_read++]; +} + +#endif /* POSIX_TTY */ + +#ifdef WINDOWS + +#include +#include +#include + +struct altos_list { + HDEVINFO dev_info; + int index; +}; + +#define USB_BUF_SIZE 64 + +struct altos_file { + HANDLE handle; + unsigned char out_data[USB_BUF_SIZE]; + int out_used; + unsigned char in_data[USB_BUF_SIZE]; + int in_used; + int in_read; + OVERLAPPED ov_read; + BOOL pend_read; + OVERLAPPED ov_write; +}; + +PUBLIC struct altos_list * +altos_list_start(void) +{ + struct altos_list *list = calloc(1, sizeof (struct altos_list)); + + if (!list) + return NULL; + list->dev_info = SetupDiGetClassDevs(NULL, "USB", NULL, + DIGCF_ALLCLASSES|DIGCF_PRESENT); + if (list->dev_info == INVALID_HANDLE_VALUE) { + printf("SetupDiGetClassDevs failed %d\n", GetLastError()); + free(list); + return NULL; + } + list->index = 0; + return list; +} + +PUBLIC int +altos_list_next(struct altos_list *list, struct altos_device *device) +{ + SP_DEVINFO_DATA dev_info_data; + char port[128]; + DWORD port_len; + char friendlyname[256]; + char symbolic[256]; + DWORD symbolic_len; + HKEY dev_key; + int vid, pid; + int serial; + HRESULT result; + DWORD friendlyname_type; + DWORD friendlyname_len; + + dev_info_data.cbSize = sizeof (SP_DEVINFO_DATA); + while(SetupDiEnumDeviceInfo(list->dev_info, list->index, + &dev_info_data)) + { + list->index++; + + dev_key = SetupDiOpenDevRegKey(list->dev_info, &dev_info_data, + DICS_FLAG_GLOBAL, 0, DIREG_DEV, + KEY_READ); + if (dev_key == INVALID_HANDLE_VALUE) { + printf("cannot open device registry key\n"); + continue; + } + + /* Fetch symbolic name for this device and parse out + * the vid/pid/serial info */ + symbolic_len = sizeof(symbolic); + result = RegQueryValueEx(dev_key, "SymbolicName", NULL, NULL, + symbolic, &symbolic_len); + if (result != 0) { + printf("cannot find SymbolicName value\n"); + RegCloseKey(dev_key); + continue; + } + vid = pid = serial = 0; + sscanf(symbolic + sizeof("\\??\\USB#VID_") - 1, + "%04X", &vid); + sscanf(symbolic + sizeof("\\??\\USB#VID_XXXX&PID_") - 1, + "%04X", &pid); + sscanf(symbolic + sizeof("\\??\\USB#VID_XXXX&PID_XXXX#") - 1, + "%d", &serial); + if (!USB_IS_ALTUSMETRUM(vid, pid)) { + RegCloseKey(dev_key); + continue; + } + + /* Fetch the com port name */ + port_len = sizeof (port); + result = RegQueryValueEx(dev_key, "PortName", NULL, NULL, + port, &port_len); + RegCloseKey(dev_key); + if (result != 0) { + printf("failed to get PortName\n"); + continue; + } + + /* Fetch the device description which is the device name, + * with firmware that has unique USB ids */ + friendlyname_len = sizeof (friendlyname); + if(!SetupDiGetDeviceRegistryProperty(list->dev_info, + &dev_info_data, + SPDRP_FRIENDLYNAME, + &friendlyname_type, + (BYTE *)friendlyname, + sizeof(friendlyname), + &friendlyname_len)) + { + printf("Failed to get friendlyname\n"); + continue; + } + device->vendor = vid; + device->product = pid; + device->serial = serial; + strcpy(device->name, friendlyname); + + strcpy(device->path, port); + return 1; + } + result = GetLastError(); + if (result != ERROR_NO_MORE_ITEMS) + printf ("SetupDiEnumDeviceInfo failed error %d\n", result); + return 0; +} + +PUBLIC void +altos_list_finish(struct altos_list *list) +{ + SetupDiDestroyDeviceInfoList(list->dev_info); + free(list); +} + +static int +altos_queue_read(struct altos_file *file) +{ + DWORD got; + if (file->pend_read) + return LIBALTOS_SUCCESS; + + if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, &file->ov_read)) { + if (GetLastError() != ERROR_IO_PENDING) + return LIBALTOS_ERROR; + file->pend_read = TRUE; + } else { + file->pend_read = FALSE; + file->in_read = 0; + file->in_used = got; + } + return LIBALTOS_SUCCESS; +} + +static int +altos_wait_read(struct altos_file *file, int timeout) +{ + DWORD ret; + DWORD got; + + if (!file->pend_read) + return LIBALTOS_SUCCESS; + + if (!timeout) + timeout = INFINITE; + + ret = WaitForSingleObject(file->ov_read.hEvent, timeout); + switch (ret) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(file->handle, &file->ov_read, &got, FALSE)) + return LIBALTOS_ERROR; + file->pend_read = FALSE; + file->in_read = 0; + file->in_used = got; + break; + case WAIT_TIMEOUT: + return LIBALTOS_TIMEOUT; + break; + default: + return LIBALTOS_ERROR; + } + return LIBALTOS_SUCCESS; +} + +static int +altos_fill(struct altos_file *file, int timeout) +{ + int ret; + + if (file->in_read < file->in_used) + return LIBALTOS_SUCCESS; + + file->in_read = file->in_used = 0; + + ret = altos_queue_read(file); + if (ret) + return ret; + ret = altos_wait_read(file, timeout); + if (ret) + return ret; + + return LIBALTOS_SUCCESS; +} + +PUBLIC int +altos_flush(struct altos_file *file) +{ + DWORD put; + char *data = file->out_data; + char used = file->out_used; + DWORD ret; + + while (used) { + if (!WriteFile(file->handle, data, used, &put, &file->ov_write)) { + if (GetLastError() != ERROR_IO_PENDING) + return LIBALTOS_ERROR; + ret = WaitForSingleObject(file->ov_write.hEvent, INFINITE); + switch (ret) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(file->handle, &file->ov_write, &put, FALSE)) + return LIBALTOS_ERROR; + break; + default: + return LIBALTOS_ERROR; + } + } + data += put; + used -= put; + } + file->out_used = 0; + return LIBALTOS_SUCCESS; +} + +PUBLIC struct altos_file * +altos_open(struct altos_device *device) +{ + struct altos_file *file = calloc (1, sizeof (struct altos_file)); + char full_name[64]; + DCB dcbSerialParams = {0}; + COMMTIMEOUTS timeouts; + + if (!file) + return NULL; + + strcpy(full_name, "\\\\.\\"); + strcat(full_name, device->path); + file->handle = CreateFile(full_name, GENERIC_READ|GENERIC_WRITE, + 0, NULL, OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, NULL); + if (file->handle == INVALID_HANDLE_VALUE) { + free(file); + return NULL; + } + file->ov_read.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + file->ov_write.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; + timeouts.ReadTotalTimeoutConstant = 1 << 30; /* almost forever */ + timeouts.WriteTotalTimeoutMultiplier = 0; + timeouts.WriteTotalTimeoutConstant = 0; + SetCommTimeouts(file->handle, &timeouts); + + dcbSerialParams.DCBlength = sizeof(dcbSerialParams); + if (!GetCommState(file->handle, &dcbSerialParams)) { + CloseHandle(file->handle); + free(file); + return NULL; + } + dcbSerialParams.BaudRate = CBR_9600; + dcbSerialParams.ByteSize = 8; + dcbSerialParams.StopBits = ONESTOPBIT; + dcbSerialParams.Parity = NOPARITY; + if (!SetCommState(file->handle, &dcbSerialParams)) { + CloseHandle(file->handle); + free(file); + return NULL; + } + + return file; +} + +PUBLIC void +altos_close(struct altos_file *file) +{ + if (file->handle != INVALID_HANDLE_VALUE) { + CloseHandle(file->handle); + file->handle = INVALID_HANDLE_VALUE; + } +} + +PUBLIC void +altos_free(struct altos_file *file) +{ + altos_close(file); + free(file); +} + +int +altos_putchar(struct altos_file *file, char c) +{ + int ret; + + if (file->out_used == USB_BUF_SIZE) { + ret = altos_flush(file); + if (ret) + return ret; + } + file->out_data[file->out_used++] = c; + if (file->out_used == USB_BUF_SIZE) + return altos_flush(file); + return LIBALTOS_SUCCESS; +} + +int +altos_getchar(struct altos_file *file, int timeout) +{ + int ret; + while (file->in_read == file->in_used) { + if (file->handle == INVALID_HANDLE_VALUE) + return LIBALTOS_ERROR; + ret = altos_fill(file, timeout); + if (ret) + return ret; + } + return file->in_data[file->in_read++]; +} + +#endif diff --git a/altosui/libaltos/libaltos.dylib b/altosui/libaltos/libaltos.dylib new file mode 100755 index 00000000..89aa12e7 Binary files /dev/null and b/altosui/libaltos/libaltos.dylib differ diff --git a/altosui/libaltos/libaltos.h b/altosui/libaltos/libaltos.h new file mode 100644 index 00000000..6e94899e --- /dev/null +++ b/altosui/libaltos/libaltos.h @@ -0,0 +1,102 @@ +/* + * Copyright © 2010 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. + */ + +#ifndef _LIBALTOS_H_ +#define _LIBALTOS_H_ + +#include + +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# ifndef BUILD_STATIC +# ifdef BUILD_DLL +# define PUBLIC __declspec(dllexport) +# else +# define PUBLIC __declspec(dllimport) +# endif +# endif /* BUILD_STATIC */ +#endif + +#ifndef PUBLIC +# define PUBLIC +#endif + +#define USB_VENDOR_FSF 0xfffe +#define USB_VENDOR_ALTUSMETRUM USB_VENDOR_FSF +#define USB_PRODUCT_ALTUSMETRUM 0x000a +#define USB_PRODUCT_TELEMETRUM 0x000b +#define USB_PRODUCT_TELEDONGLE 0x000c +#define USB_PRODUCT_TELETERRA 0x000d +#define USB_PRODUCT_ALTUSMETRUM_MIN 0x000a +#define USB_PRODUCT_ALTUSMETRUM_MAX 0x0013 + +#define USB_IS_ALTUSMETRUM(v,p) ((v) == USB_VENDOR_ALTUSMETRUM && \ + (USB_PRODUCT_ALTUSMETRUM_MIN <= (p) && \ + (p) <= USB_PRODUCT_ALTUSMETRUM_MAX)) + +struct altos_device { + //%immutable; + int vendor; + int product; + int serial; + char name[256]; + char path[256]; + //%mutable; +}; + +#define LIBALTOS_SUCCESS 0 +#define LIBALTOS_ERROR -1 +#define LIBALTOS_TIMEOUT -2 + +/* Returns 0 for success, < 0 on error */ +PUBLIC int +altos_init(void); + +PUBLIC void +altos_fini(void); + +PUBLIC struct altos_list * +altos_list_start(void); + +/* Returns 1 for success, zero on end of list */ +PUBLIC int +altos_list_next(struct altos_list *list, struct altos_device *device); + +PUBLIC void +altos_list_finish(struct altos_list *list); + +PUBLIC struct altos_file * +altos_open(struct altos_device *device); + +PUBLIC void +altos_close(struct altos_file *file); + +PUBLIC void +altos_free(struct altos_file *file); + +/* Returns < 0 for error */ +PUBLIC int +altos_putchar(struct altos_file *file, char c); + +/* Returns < 0 for error */ +PUBLIC int +altos_flush(struct altos_file *file); + +/* Returns < 0 for error or timeout. timeout of 0 == wait forever */ +PUBLIC int +altos_getchar(struct altos_file *file, int timeout); + +#endif /* _LIBALTOS_H_ */ diff --git a/altosui/libaltos/libaltos.i0 b/altosui/libaltos/libaltos.i0 new file mode 100644 index 00000000..d06468f5 --- /dev/null +++ b/altosui/libaltos/libaltos.i0 @@ -0,0 +1,5 @@ +%module libaltos +%{ +#include "libaltos.h" +%} + diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 54dc777a..2850e909 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-dumplog ao-bitbang ao-eeprom ao-list ao-load ao-postflight ao-view libaltos altosui +SUBDIRS=lib ao-rawload ao-dbg ao-dumplog ao-bitbang ao-eeprom ao-list ao-load ao-postflight ao-view diff --git a/ao-tools/altosui/.gitignore b/ao-tools/altosui/.gitignore deleted file mode 100644 index 89be1d53..00000000 --- a/ao-tools/altosui/.gitignore +++ /dev/null @@ -1,19 +0,0 @@ -windows/ -linux/ -macosx/ -fat/ -Manifest.txt -Manifest-fat.txt -libaltosJNI -classes -altosui -altosui-test -classaltosui.stamp -Altos-Linux-*.tar.bz2 -Altos-Mac-*.zip -Altos-Windows-*.exe -*.dll -*.dylib -*.so -*.jar -*.class diff --git a/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml b/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml deleted file mode 100644 index 18e00fe4..00000000 --- a/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui-contents.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml b/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml deleted file mode 100644 index 6170931b..00000000 --- a/ao-tools/altosui/AltOS Package Configuration.pmdoc/01altosui.xml +++ /dev/null @@ -1 +0,0 @@ -org.altusmetrum.altosUi.AltosUI.pkg0.7AltosUI.app/Applications/AltosUI.appinstallTo.pathinstallFrom.isRelativeTypeversionparentrequireAuthorizationinstallTo01altosui-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ \ No newline at end of file diff --git a/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml b/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml deleted file mode 100644 index fabe54a6..00000000 --- a/ao-tools/altosui/AltOS Package Configuration.pmdoc/index.xml +++ /dev/null @@ -1 +0,0 @@ -AltOS UI/Users/keithp/altos/ao-tools/altosui/AltosUI.pkgorg.altusmetrumInstall AltOS User Interfacealtusmetrum.jpg01altosui.xmlproperties.anywhereDomainproperties.titleproperties.customizeOptiondescriptionproperties.userDomainproperties.systemDomain \ No newline at end of file diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java deleted file mode 100644 index 8ee94e04..00000000 --- a/ao-tools/altosui/Altos.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.util.*; -import java.text.*; - -public class Altos { - /* EEProm command letters */ - static final int AO_LOG_FLIGHT = 'F'; - static final int AO_LOG_SENSOR = 'A'; - static final int AO_LOG_TEMP_VOLT = 'T'; - static final int AO_LOG_DEPLOY = 'D'; - static final int AO_LOG_STATE = 'S'; - static final int AO_LOG_GPS_TIME = 'G'; - static final int AO_LOG_GPS_LAT = 'N'; - static final int AO_LOG_GPS_LON = 'W'; - static final int AO_LOG_GPS_ALT = 'H'; - static final int AO_LOG_GPS_SAT = 'V'; - static final int AO_LOG_GPS_DATE = 'Y'; - - /* Added for header fields in eeprom files */ - static final int AO_LOG_CONFIG_VERSION = 1000; - static final int AO_LOG_MAIN_DEPLOY = 1001; - static final int AO_LOG_APOGEE_DELAY = 1002; - static final int AO_LOG_RADIO_CHANNEL = 1003; - static final int AO_LOG_CALLSIGN = 1004; - static final int AO_LOG_ACCEL_CAL = 1005; - static final int AO_LOG_RADIO_CAL = 1006; - static final int AO_LOG_MANUFACTURER = 1007; - static final int AO_LOG_PRODUCT = 1008; - static final int AO_LOG_SERIAL_NUMBER = 1009; - static final int AO_LOG_SOFTWARE_VERSION = 1010; - - /* Added to flag invalid records */ - static final int AO_LOG_INVALID = -1; - - /* Flight state numbers and names */ - static final int ao_flight_startup = 0; - static final int ao_flight_idle = 1; - static final int ao_flight_pad = 2; - static final int ao_flight_boost = 3; - static final int ao_flight_fast = 4; - static final int ao_flight_coast = 5; - static final int ao_flight_drogue = 6; - static final int ao_flight_main = 7; - static final int ao_flight_landed = 8; - static final int ao_flight_invalid = 9; - - static HashMap string_to_state = new HashMap(); - - static boolean map_initialized = false; - - static final int tab_elt_pad = 5; - - static final Font label_font = new Font("Dialog", Font.PLAIN, 22); - static final Font value_font = new Font("Monospaced", Font.PLAIN, 22); - static final Font status_font = new Font("SansSerif", Font.BOLD, 24); - - static final int text_width = 16; - - static void initialize_map() - { - string_to_state.put("startup", ao_flight_startup); - string_to_state.put("idle", ao_flight_idle); - string_to_state.put("pad", ao_flight_pad); - string_to_state.put("boost", ao_flight_boost); - string_to_state.put("fast", ao_flight_fast); - string_to_state.put("coast", ao_flight_coast); - string_to_state.put("drogue", ao_flight_drogue); - string_to_state.put("main", ao_flight_main); - string_to_state.put("landed", ao_flight_landed); - string_to_state.put("invalid", ao_flight_invalid); - map_initialized = true; - } - - static String[] state_to_string = { - "startup", - "idle", - "pad", - "boost", - "fast", - "coast", - "drogue", - "main", - "landed", - "invalid", - }; - - static public int state(String state) { - if (!map_initialized) - initialize_map(); - if (string_to_state.containsKey(state)) - return string_to_state.get(state); - return ao_flight_invalid; - } - - static public String state_name(int state) { - if (state < 0 || state_to_string.length <= state) - return "invalid"; - return state_to_string[state]; - } - - 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_NUM_SAT_SHIFT = 0; - static final int AO_GPS_NUM_SAT_MASK = 0xf; - - static boolean isspace(int c) { - switch (c) { - case ' ': - case '\t': - return true; - } - return false; - } - - static boolean ishex(int c) { - if ('0' <= c && c <= '9') - return true; - if ('a' <= c && c <= 'f') - return true; - if ('A' <= c && c <= 'F') - return true; - return false; - } - - static boolean ishex(String s) { - for (int i = 0; i < s.length(); i++) - if (!ishex(s.charAt(i))) - return false; - return true; - } - - static int fromhex(int c) { - if ('0' <= c && c <= '9') - return c - '0'; - if ('a' <= c && c <= 'f') - return c - 'a' + 10; - if ('A' <= c && c <= 'F') - return c - 'A' + 10; - return -1; - } - - static int fromhex(String s) throws NumberFormatException { - int c, v = 0; - for (int i = 0; i < s.length(); i++) { - c = s.charAt(i); - if (!ishex(c)) { - if (i == 0) - throw new NumberFormatException(String.format("invalid hex \"%s\"", s)); - return v; - } - v = v * 16 + fromhex(c); - } - return v; - } - - static boolean isdec(int c) { - if ('0' <= c && c <= '9') - return true; - return false; - } - - static boolean isdec(String s) { - for (int i = 0; i < s.length(); i++) - if (!isdec(s.charAt(i))) - return false; - return true; - } - - static int fromdec(int c) { - if ('0' <= c && c <= '9') - return c - '0'; - return -1; - } - - static int fromdec(String s) throws NumberFormatException { - int c, v = 0; - int sign = 1; - for (int i = 0; i < s.length(); i++) { - c = s.charAt(i); - if (i == 0 && c == '-') { - sign = -1; - } else if (!isdec(c)) { - if (i == 0) - throw new NumberFormatException(String.format("invalid number \"%s\"", s)); - return v; - } else - v = v * 10 + fromdec(c); - } - return v * sign; - } - - static String replace_extension(String input, String extension) { - int dot = input.lastIndexOf("."); - if (dot > 0) - input = input.substring(0,dot); - return input.concat(extension); - } -} diff --git a/ao-tools/altosui/AltosAscent.java b/ao-tools/altosui/AltosAscent.java deleted file mode 100644 index 64bdcf30..00000000 --- a/ao-tools/altosui/AltosAscent.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosAscent extends JComponent implements AltosFlightDisplay { - GridBagLayout layout; - - public class AscentStatus { - JLabel label; - JTextField value; - AltosLights lights; - - void show(AltosState state, int crc_errors) {} - void reset() { - value.setText(""); - lights.set(false); - } - - public AscentStatus (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - lights = new AltosLights(); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(lights, c); - add(lights); - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.gridwidth = 2; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - - } - } - - public class AscentValue { - JLabel label; - JTextField value; - void show(AltosState state, int crc_errors) {} - - void reset() { - value.setText(""); - } - public AscentValue (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.gridwidth = 2; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - } - } - - public class AscentValueHold { - JLabel label; - JTextField value; - JTextField max_value; - double max; - - void show(AltosState state, int crc_errors) {} - - void reset() { - value.setText(""); - max_value.setText(""); - max = 0; - } - - void show(String format, double v) { - value.setText(String.format(format, v)); - if (v > max) { - max_value.setText(String.format(format, v)); - max = v; - } - } - public AscentValueHold (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - - max_value = new JTextField(Altos.text_width); - max_value.setFont(Altos.value_font); - max_value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 3; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(max_value, c); - add(max_value); - } - } - - - class Height extends AscentValueHold { - void show (AltosState state, int crc_errors) { - show("%6.0f m", state.height); - } - public Height (GridBagLayout layout, int y) { - super (layout, y, "Height"); - } - } - - Height height; - - class Speed extends AscentValueHold { - void show (AltosState state, int crc_errors) { - double speed = state.speed; - if (!state.ascent) - speed = state.baro_speed; - show("%6.0f m/s", speed); - } - public Speed (GridBagLayout layout, int y) { - super (layout, y, "Speed"); - } - } - - Speed speed; - - class Accel extends AscentValueHold { - void show (AltosState state, int crc_errors) { - show("%6.0f m/s²", state.acceleration); - } - public Accel (GridBagLayout layout, int y) { - super (layout, y, "Acceleration"); - } - } - - Accel accel; - - String pos(double p, String pos, String neg) { - String h = pos; - if (p < 0) { - h = neg; - p = -p; - } - int deg = (int) Math.floor(p); - double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %4d° %9.6f", h, deg, min); - } - - class Apogee extends AscentStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.2f V", state.drogue_sense)); - lights.set(state.drogue_sense > 3.2); - } - public Apogee (GridBagLayout layout, int y) { - super(layout, y, "Apogee Igniter Voltage"); - } - } - - Apogee apogee; - - class Main extends AscentStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.2f V", state.main_sense)); - lights.set(state.main_sense > 3.2); - } - public Main (GridBagLayout layout, int y) { - super(layout, y, "Main Igniter Voltage"); - } - } - - Main main; - - class Lat extends AscentValue { - void show (AltosState state, int crc_errors) { - if (state.gps != null) - value.setText(pos(state.gps.lat,"N", "S")); - else - value.setText("???"); - } - public Lat (GridBagLayout layout, int y) { - super (layout, y, "Latitude"); - } - } - - Lat lat; - - class Lon extends AscentValue { - void show (AltosState state, int crc_errors) { - if (state.gps != null) - value.setText(pos(state.gps.lon,"E", "W")); - else - value.setText("???"); - } - public Lon (GridBagLayout layout, int y) { - super (layout, y, "Longitude"); - } - } - - Lon lon; - - public void reset() { - lat.reset(); - lon.reset(); - main.reset(); - apogee.reset(); - height.reset(); - speed.reset(); - accel.reset(); - } - - public void show(AltosState state, int crc_errors) { - lat.show(state, crc_errors); - lon.show(state, crc_errors); - height.show(state, crc_errors); - main.show(state, crc_errors); - apogee.show(state, crc_errors); - speed.show(state, crc_errors); - accel.show(state, crc_errors); - } - - public void labels(GridBagLayout layout, int y) { - GridBagConstraints c; - JLabel cur, max; - - cur = new JLabel("Current"); - cur.setFont(Altos.label_font); - c = new GridBagConstraints(); - c.gridx = 2; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - layout.setConstraints(cur, c); - add(cur); - - max = new JLabel("Maximum"); - max.setFont(Altos.label_font); - c.gridx = 3; c.gridy = y; - layout.setConstraints(max, c); - add(max); - } - - public AltosAscent() { - layout = new GridBagLayout(); - - setLayout(layout); - - /* Elements in ascent display: - * - * lat - * lon - * height - */ - labels(layout, 0); - height = new Height(layout, 1); - speed = new Speed(layout, 2); - accel = new Accel(layout, 3); - lat = new Lat(layout, 4); - lon = new Lon(layout, 5); - apogee = new Apogee(layout, 6); - main = new Main(layout, 7); - } -} diff --git a/ao-tools/altosui/AltosCRCException.java b/ao-tools/altosui/AltosCRCException.java deleted file mode 100644 index 4a529bcf..00000000 --- a/ao-tools/altosui/AltosCRCException.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -public class AltosCRCException extends Exception { - public int rssi; - - public AltosCRCException (int in_rssi) { - rssi = in_rssi; - } -} diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java deleted file mode 100644 index df98b2b4..00000000 --- a/ao-tools/altosui/AltosCSV.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.io.*; -import java.text.*; -import java.util.*; - -public class AltosCSV implements AltosWriter { - File name; - PrintStream out; - boolean header_written; - boolean seen_boost; - int boost_tick; - LinkedList pad_records; - AltosState state; - - static final int ALTOS_CSV_VERSION = 2; - - /* Version 2 format: - * - * General info - * version number - * serial number - * flight number - * callsign - * time (seconds since boost) - * rssi - * link quality - * - * Flight status - * state - * state name - * - * Basic sensors - * acceleration (m/s²) - * pressure (mBar) - * altitude (m) - * height (m) - * accelerometer speed (m/s) - * barometer speed (m/s) - * temp (°C) - * battery (V) - * drogue (V) - * main (V) - * - * GPS data - * connected (1/0) - * locked (1/0) - * nsat (used for solution) - * latitude (°) - * longitude (°) - * altitude (m) - * year (e.g. 2010) - * month (1-12) - * day (1-31) - * hour (0-23) - * minute (0-59) - * second (0-59) - * from_pad_dist (m) - * from_pad_azimuth (deg true) - * from_pad_range (m) - * from_pad_elevation (deg from horizon) - * hdop - * - * GPS Sat data - * C/N0 data for all 32 valid SDIDs - */ - - void write_general_header() { - out.printf("version,serial,flight,call,time,rssi,lqi"); - } - - void write_general(AltosRecord record) { - out.printf("%s, %d, %d, %s, %8.2f, %4d, %3d", - ALTOS_CSV_VERSION, record.serial, record.flight, record.callsign, - (double) record.time, - record.rssi, - record.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_basic_header() { - out.printf("acceleration,pressure,altitude,height,accel_speed,baro_speed,temperature,battery_voltage,drogue_voltage,main_voltage"); - } - - void write_basic(AltosRecord record) { - 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.raw_pressure(), - record.raw_altitude(), - record.raw_height(), - record.accel_speed(), - state.baro_speed, - record.temperature(), - record.battery_voltage(), - record.drogue_voltage(), - record.main_voltage()); - } - - void write_gps_header() { - out.printf("connected,locked,nsat,latitude,longitude,altitude,year,month,day,hour,minute,second,pad_dist,pad_range,pad_az,pad_el,hdop"); - } - - void write_gps(AltosRecord record) { - AltosGPS gps = record.gps; - if (gps == null) - gps = new AltosGPS(); - - AltosGreatCircle from_pad = state.from_pad; - 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", - gps.connected?1:0, - gps.locked?1:0, - gps.nsat, - gps.lat, - gps.lon, - gps.alt, - gps.year, - gps.month, - gps.day, - gps.hour, - gps.minute, - gps.second, - from_pad.distance, - state.range, - from_pad.bearing, - state.elevation, - gps.hdop); - } - - void write_gps_sat_header() { - for(int i = 1; i <= 32; i++) { - out.printf("sat%02d", i); - if (i != 32) - out.printf(","); - } - } - - void write_gps_sat(AltosRecord record) { - AltosGPS gps = record.gps; - for(int i = 1; i <= 32; i++) { - int c_n0 = 0; - if (gps != null && gps.cc_gps_sat != null) { - for(int j = 0; j < gps.cc_gps_sat.length; j++) - if (gps.cc_gps_sat[j].svid == i) { - c_n0 = gps.cc_gps_sat[j].c_n0; - break; - } - } - out.printf ("%3d", c_n0); - if (i != 32) - out.printf(","); - } - } - - void write_header() { - out.printf("#"); write_general_header(); - out.printf(","); write_flight_header(); - out.printf(","); write_basic_header(); - out.printf(","); write_gps_header(); - out.printf(","); write_gps_sat_header(); - 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(","); - write_gps(record); out.printf(","); - write_gps_sat(record); - out.printf ("\n"); - } - - void flush_pad() { - while (!pad_records.isEmpty()) { - write_one (pad_records.remove()); - } - } - - public void write(AltosRecord record) { - if (!header_written) { - write_header(); - header_written = true; - } - if (!seen_boost) { - if (record.state >= Altos.ao_flight_boost) { - seen_boost = true; - boost_tick = record.tick; - flush_pad(); - } - } - if (seen_boost) - write_one(record); - else - pad_records.add(record); - } - - public PrintStream out() { - return out; - } - - public void close() { - if (!pad_records.isEmpty()) { - boost_tick = pad_records.element().tick; - flush_pad(); - } - out.close(); - } - - public void write(AltosRecordIterable iterable) { - iterable.write_comments(out()); - for (AltosRecord r : iterable) - write(r); - } - - public AltosCSV(File in_name) throws FileNotFoundException { - name = in_name; - out = new PrintStream(name); - pad_records = new LinkedList(); - } - - public AltosCSV(String in_string) throws FileNotFoundException { - this(new File(in_string)); - } -} diff --git a/ao-tools/altosui/AltosCSVUI.java b/ao-tools/altosui/AltosCSVUI.java deleted file mode 100644 index e1b6002d..00000000 --- a/ao-tools/altosui/AltosCSVUI.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosCSVUI - extends JDialog - implements ActionListener -{ - JFileChooser csv_chooser; - JPanel accessory; - JComboBox combo_box; - AltosRecordIterable iterable; - AltosWriter writer; - - static String[] combo_box_items = { "Comma Separated Values (.CSV)", "Googleearth Data (.KML)" }; - - void set_default_file() { - File current = csv_chooser.getSelectedFile(); - String current_name = current.getName(); - String new_name = null; - String selected = (String) combo_box.getSelectedItem(); - - if (selected.contains("CSV")) - new_name = Altos.replace_extension(current_name, ".csv"); - else if (selected.contains("KML")) - new_name = Altos.replace_extension(current_name, ".kml"); - if (new_name != null) - csv_chooser.setSelectedFile(new File(new_name)); - } - - public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals("comboBoxChanged")) - set_default_file(); - } - - public AltosCSVUI(JFrame frame, AltosRecordIterable in_iterable, File source_file) { - iterable = in_iterable; - csv_chooser = new JFileChooser(source_file); - - accessory = new JPanel(); - accessory.setLayout(new GridBagLayout()); - - GridBagConstraints c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.weightx = 1; - c.weighty = 0; - c.insets = new Insets (4, 4, 4, 4); - - JLabel accessory_label = new JLabel("Export File Type"); - c.gridx = 0; - c.gridy = 0; - accessory.add(accessory_label, c); - - combo_box = new JComboBox(combo_box_items); - combo_box.addActionListener(this); - c.gridx = 0; - c.gridy = 1; - accessory.add(combo_box, c); - - csv_chooser.setAccessory(accessory); - csv_chooser.setSelectedFile(source_file); - set_default_file(); - int ret = csv_chooser.showSaveDialog(frame); - if (ret == JFileChooser.APPROVE_OPTION) { - File file = csv_chooser.getSelectedFile(); - String type = (String) combo_box.getSelectedItem(); - try { - if (type.contains("CSV")) - writer = new AltosCSV(file); - else - writer = new AltosKML(file); - writer.write(iterable); - writer.close(); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(frame, - file.getName(), - "Cannot open file", - JOptionPane.ERROR_MESSAGE); - } - } - } -} diff --git a/ao-tools/altosui/AltosChannelMenu.java b/ao-tools/altosui/AltosChannelMenu.java deleted file mode 100644 index abbb86f4..00000000 --- a/ao-tools/altosui/AltosChannelMenu.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosChannelMenu extends JComboBox implements ActionListener { - int channel; - - public AltosChannelMenu(int current_channel) { - - channel = current_channel; - - for (int c = 0; c <= 9; c++) - addItem(String.format("Channel %1d (%7.3fMHz)", c, 434.550 + c * 0.1)); - setSelectedIndex(channel); - setMaximumRowCount(10); - } - -} diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java deleted file mode 100644 index 1c42870f..00000000 --- a/ao-tools/altosui/AltosConfig.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; - -import libaltosJNI.*; - -public class AltosConfig implements Runnable, ActionListener { - - class int_ref { - int value; - - public int get() { - return value; - } - public void set(int i) { - value = i; - } - public int_ref(int i) { - value = i; - } - } - - class string_ref { - String value; - - public String get() { - return value; - } - public void set(String i) { - value = i; - } - public string_ref(String i) { - value = i; - } - } - - JFrame owner; - AltosDevice device; - AltosSerial serial_line; - boolean remote; - Thread config_thread; - int_ref serial; - int_ref main_deploy; - int_ref apogee_delay; - int_ref radio_channel; - int_ref radio_calibration; - string_ref version; - string_ref product; - string_ref callsign; - AltosConfigUI config_ui; - boolean serial_started; - - boolean get_int(String line, String label, int_ref x) { - if (line.startsWith(label)) { - try { - String tail = line.substring(label.length()).trim(); - String[] tokens = tail.split("\\s+"); - if (tokens.length > 0) { - int i = Integer.parseInt(tokens[0]); - x.set(i); - return true; - } - } catch (NumberFormatException ne) { - } - } - return false; - } - - boolean get_string(String line, String label, string_ref s) { - if (line.startsWith(label)) { - String quoted = line.substring(label.length()).trim(); - - if (quoted.startsWith("\"")) - quoted = quoted.substring(1); - if (quoted.endsWith("\"")) - quoted = quoted.substring(0,quoted.length()-1); - s.set(quoted); - return true; - } else { - return false; - } - } - - void start_serial() throws InterruptedException { - serial_started = true; - if (remote) { - serial_line.set_radio(); - serial_line.printf("p\nE 0\n"); - serial_line.flush_input(); - } - } - - void stop_serial() throws InterruptedException { - if (!serial_started) - return; - serial_started = false; - if (remote) { - serial_line.printf("~"); - serial_line.flush_output(); - } - } - - void get_data() throws InterruptedException, TimeoutException { - try { - start_serial(); - serial_line.printf("c s\nv\n"); - for (;;) { - String line = serial_line.get_reply(5000); - if (line == null) - throw new TimeoutException(); - get_int(line, "serial-number", serial); - get_int(line, "Main deploy:", main_deploy); - get_int(line, "Apogee delay:", apogee_delay); - get_int(line, "Radio channel:", radio_channel); - get_int(line, "Radio cal:", radio_calibration); - get_string(line, "Callsign:", callsign); - get_string(line,"software-version", version); - get_string(line,"product", product); - - /* signals the end of the version info */ - if (line.startsWith("software-version")) - break; - } - } finally { - stop_serial(); - } - } - - void init_ui () throws InterruptedException, TimeoutException { - config_ui = new AltosConfigUI(owner, remote); - config_ui.addActionListener(this); - set_ui(); - } - - void abort() { - JOptionPane.showMessageDialog(owner, - String.format("Connection to \"%s\" failed", - device.toShortString()), - "Connection Failed", - JOptionPane.ERROR_MESSAGE); - try { - stop_serial(); - } catch (InterruptedException ie) { - } - serial_line.close(); - serial_line = null; - } - - void set_ui() throws InterruptedException, TimeoutException { - if (serial_line != null) - get_data(); - config_ui.set_serial(serial.get()); - config_ui.set_product(product.get()); - config_ui.set_version(version.get()); - config_ui.set_main_deploy(main_deploy.get()); - config_ui.set_apogee_delay(apogee_delay.get()); - config_ui.set_radio_channel(radio_channel.get()); - config_ui.set_radio_calibration(radio_calibration.get()); - config_ui.set_callsign(callsign.get()); - config_ui.set_clean(); - } - - void run_dialog() { - } - - void save_data() { - main_deploy.set(config_ui.main_deploy()); - apogee_delay.set(config_ui.apogee_delay()); - radio_channel.set(config_ui.radio_channel()); - radio_calibration.set(config_ui.radio_calibration()); - callsign.set(config_ui.callsign()); - try { - start_serial(); - serial_line.printf("c m %d\n", main_deploy.get()); - serial_line.printf("c d %d\n", apogee_delay.get()); - if (!remote) { - serial_line.printf("c r %d\n", radio_channel.get()); - serial_line.printf("c f %d\n", radio_calibration.get()); - } - serial_line.printf("c c %s\n", callsign.get()); - serial_line.printf("c w\n"); - } catch (InterruptedException ie) { - } finally { - try { - stop_serial(); - } catch (InterruptedException ie) { - } - } - } - - public void actionPerformed(ActionEvent e) { - String cmd = e.getActionCommand(); - try { - if (cmd.equals("Save")) { - save_data(); - set_ui(); - } else if (cmd.equals("Reset")) { - set_ui(); - } else if (cmd.equals("Reboot")) { - if (serial_line != null) { - start_serial(); - serial_line.printf("r eboot\n"); - serial_line.flush_output(); - stop_serial(); - serial_line.close(); - } - } else if (cmd.equals("Close")) { - if (serial_line != null) - serial_line.close(); - } - } catch (InterruptedException ie) { - abort(); - } catch (TimeoutException te) { - abort(); - } - } - - public void run () { - try { - init_ui(); - config_ui.make_visible(); - } catch (InterruptedException ie) { - abort(); - } catch (TimeoutException te) { - abort(); - } - } - - public AltosConfig(JFrame given_owner) { - owner = given_owner; - - serial = new int_ref(0); - main_deploy = new int_ref(250); - apogee_delay = new int_ref(0); - radio_channel = new int_ref(0); - radio_calibration = new int_ref(1186611); - callsign = new string_ref("N0CALL"); - version = new string_ref("unknown"); - product = new string_ref("unknown"); - - device = AltosDeviceDialog.show(owner, AltosDevice.product_any); - if (device != null) { - try { - serial_line = new AltosSerial(device); - if (!device.matchProduct(AltosDevice.product_telemetrum)) - remote = true; - config_thread = new Thread(this); - config_thread.start(); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(owner, - String.format("Cannot open device \"%s\"", - device.toShortString()), - "Cannot open target device", - JOptionPane.ERROR_MESSAGE); - } catch (AltosSerialInUseException si) { - JOptionPane.showMessageDialog(owner, - String.format("Device \"%s\" already in use", - device.toShortString()), - "Device in use", - JOptionPane.ERROR_MESSAGE); - } catch (IOException ee) { - JOptionPane.showMessageDialog(owner, - device.toShortString(), - ee.getLocalizedMessage(), - JOptionPane.ERROR_MESSAGE); - } - } - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java deleted file mode 100644 index cfa5d7b9..00000000 --- a/ao-tools/altosui/AltosConfigUI.java +++ /dev/null @@ -1,466 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import javax.swing.event.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -import libaltosJNI.*; - -public class AltosConfigUI - extends JDialog - implements ActionListener, ItemListener, DocumentListener -{ - - Container pane; - Box box; - JLabel product_label; - JLabel version_label; - JLabel serial_label; - JLabel main_deploy_label; - JLabel apogee_delay_label; - JLabel radio_channel_label; - JLabel radio_calibration_label; - JLabel callsign_label; - - public boolean dirty; - - JFrame owner; - JLabel product_value; - JLabel version_value; - JLabel serial_value; - JComboBox main_deploy_value; - JComboBox apogee_delay_value; - JComboBox radio_channel_value; - JTextField radio_calibration_value; - JTextField callsign_value; - - JButton save; - JButton reset; - JButton reboot; - JButton close; - - ActionListener listener; - - static String[] main_deploy_values = { - "100", "150", "200", "250", "300", "350", - "400", "450", "500" - }; - - static String[] apogee_delay_values = { - "0", "1", "2", "3", "4", "5" - }; - - static String[] radio_channel_values = new String[10]; - { - for (int i = 0; i <= 9; i++) - radio_channel_values[i] = String.format("Channel %1d (%7.3fMHz)", - i, 434.550 + i * 0.1); - } - - /* A window listener to catch closing events and tell the config code */ - class ConfigListener extends WindowAdapter { - AltosConfigUI ui; - - public ConfigListener(AltosConfigUI this_ui) { - ui = this_ui; - } - - public void windowClosing(WindowEvent e) { - ui.actionPerformed(new ActionEvent(e.getSource(), - ActionEvent.ACTION_PERFORMED, - "Close")); - } - } - - /* Build the UI using a grid bag */ - public AltosConfigUI(JFrame in_owner, boolean remote) { - super (in_owner, "Configure TeleMetrum", false); - - owner = in_owner; - GridBagConstraints c; - - Insets il = new Insets(4,4,4,4); - Insets ir = new Insets(4,4,4,4); - - pane = getContentPane(); - pane.setLayout(new GridBagLayout()); - - /* Product */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 0; - c.gridwidth = 4; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - product_label = new JLabel("Product:"); - pane.add(product_label, c); - - c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 0; - c.gridwidth = 4; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - product_value = new JLabel(""); - pane.add(product_value, c); - - /* Version */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 1; - c.gridwidth = 4; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - c.ipady = 5; - version_label = new JLabel("Software version:"); - pane.add(version_label, c); - - c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 1; - c.gridwidth = 4; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - c.ipady = 5; - version_value = new JLabel(""); - pane.add(version_value, c); - - /* Serial */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 2; - c.gridwidth = 4; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - c.ipady = 5; - serial_label = new JLabel("Serial:"); - pane.add(serial_label, c); - - c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 2; - c.gridwidth = 4; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - c.ipady = 5; - serial_value = new JLabel(""); - pane.add(serial_value, c); - - /* Main deploy */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 3; - c.gridwidth = 4; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - c.ipady = 5; - main_deploy_label = new JLabel("Main Deploy Altitude(m):"); - pane.add(main_deploy_label, c); - - c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 3; - c.gridwidth = 4; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - c.ipady = 5; - main_deploy_value = new JComboBox(main_deploy_values); - main_deploy_value.setEditable(true); - main_deploy_value.addItemListener(this); - pane.add(main_deploy_value, c); - - /* Apogee delay */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 4; - c.gridwidth = 4; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - c.ipady = 5; - apogee_delay_label = new JLabel("Apogee Delay(s):"); - pane.add(apogee_delay_label, c); - - c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 4; - c.gridwidth = 4; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - c.ipady = 5; - apogee_delay_value = new JComboBox(apogee_delay_values); - apogee_delay_value.setEditable(true); - apogee_delay_value.addItemListener(this); - pane.add(apogee_delay_value, c); - - /* Radio channel */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 5; - c.gridwidth = 4; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - c.ipady = 5; - radio_channel_label = new JLabel("Radio Channel:"); - pane.add(radio_channel_label, c); - - c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 5; - c.gridwidth = 4; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - c.ipady = 5; - radio_channel_value = new JComboBox(radio_channel_values); - radio_channel_value.setEditable(false); - radio_channel_value.addItemListener(this); - if (remote) - radio_channel_value.setEnabled(false); - pane.add(radio_channel_value, c); - - /* Radio Calibration */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 6; - c.gridwidth = 4; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - c.ipady = 5; - radio_calibration_label = new JLabel("RF Calibration:"); - pane.add(radio_calibration_label, c); - - c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 6; - c.gridwidth = 4; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - c.ipady = 5; - radio_calibration_value = new JTextField(String.format("%d", 1186611)); - radio_calibration_value.getDocument().addDocumentListener(this); - if (remote) - radio_calibration_value.setEnabled(false); - pane.add(radio_calibration_value, c); - - /* Callsign */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 7; - c.gridwidth = 4; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - c.ipady = 5; - callsign_label = new JLabel("Callsign:"); - pane.add(callsign_label, c); - - c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 7; - c.gridwidth = 4; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - c.ipady = 5; - callsign_value = new JTextField(AltosPreferences.callsign()); - callsign_value.getDocument().addDocumentListener(this); - pane.add(callsign_value, c); - - /* Buttons */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 8; - c.gridwidth = 2; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - save = new JButton("Save"); - pane.add(save, c); - save.addActionListener(this); - save.setActionCommand("Save"); - - c = new GridBagConstraints(); - c.gridx = 2; c.gridy = 8; - c.gridwidth = 2; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = il; - reset = new JButton("Reset"); - pane.add(reset, c); - reset.addActionListener(this); - reset.setActionCommand("Reset"); - - c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 8; - c.gridwidth = 2; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = il; - reboot = new JButton("Reboot"); - pane.add(reboot, c); - reboot.addActionListener(this); - reboot.setActionCommand("Reboot"); - - c = new GridBagConstraints(); - c.gridx = 6; c.gridy = 8; - c.gridwidth = 2; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_END; - c.insets = il; - close = new JButton("Close"); - pane.add(close, c); - close.addActionListener(this); - close.setActionCommand("Close"); - - addWindowListener(new ConfigListener(this)); - } - - /* Once the initial values are set, the config code will show the dialog */ - public void make_visible() { - pack(); - setLocationRelativeTo(owner); - setVisible(true); - } - - /* If any values have been changed, confirm before closing */ - public boolean check_dirty(String operation) { - if (dirty) { - Object[] options = { String.format("%s anyway", operation), "Keep editing" }; - int i; - i = JOptionPane.showOptionDialog(this, - String.format("Configuration modified. %s anyway?", operation), - "Configuration Modified", - JOptionPane.DEFAULT_OPTION, - JOptionPane.WARNING_MESSAGE, - null, options, options[1]); - if (i != 0) - return false; - } - return true; - } - - /* Listen for events from our buttons */ - public void actionPerformed(ActionEvent e) { - String cmd = e.getActionCommand(); - - if (cmd.equals("Close") || cmd.equals("Reboot")) - if (!check_dirty(cmd)) - return; - listener.actionPerformed(e); - if (cmd.equals("Close") || cmd.equals("Reboot")) { - setVisible(false); - dispose(); - } - dirty = false; - } - - /* ItemListener interface method */ - public void itemStateChanged(ItemEvent e) { - dirty = true; - } - - /* DocumentListener interface methods */ - public void changedUpdate(DocumentEvent e) { - dirty = true; - } - - public void insertUpdate(DocumentEvent e) { - dirty = true; - } - - public void removeUpdate(DocumentEvent e) { - dirty = true; - } - - /* Let the config code hook on a listener */ - public void addActionListener(ActionListener l) { - listener = l; - } - - /* set and get all of the dialog values */ - public void set_product(String product) { - product_value.setText(product); - } - - public void set_version(String version) { - version_value.setText(version); - } - - public void set_serial(int serial) { - serial_value.setText(String.format("%d", serial)); - } - - public void set_main_deploy(int new_main_deploy) { - main_deploy_value.setSelectedItem(Integer.toString(new_main_deploy)); - } - - public int main_deploy() { - return Integer.parseInt(main_deploy_value.getSelectedItem().toString()); - } - - public void set_apogee_delay(int new_apogee_delay) { - apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay)); - } - - public int apogee_delay() { - return Integer.parseInt(apogee_delay_value.getSelectedItem().toString()); - } - - public void set_radio_channel(int new_radio_channel) { - radio_channel_value.setSelectedIndex(new_radio_channel); - } - - public int radio_channel() { - return radio_channel_value.getSelectedIndex(); - } - - public void set_radio_calibration(int new_radio_calibration) { - radio_calibration_value.setText(String.format("%d", new_radio_calibration)); - } - - public int radio_calibration() { - return Integer.parseInt(radio_calibration_value.getText()); - } - - public void set_callsign(String new_callsign) { - callsign_value.setText(new_callsign); - } - - public String callsign() { - return callsign_value.getText(); - } - - public void set_clean() { - dirty = false; - } - - } \ No newline at end of file diff --git a/ao-tools/altosui/AltosConfigureUI.java b/ao-tools/altosui/AltosConfigureUI.java deleted file mode 100644 index 153c59fd..00000000 --- a/ao-tools/altosui/AltosConfigureUI.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import javax.swing.event.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosConfigureUI - extends JDialog - implements DocumentListener -{ - JFrame owner; - AltosVoice voice; - Container pane; - - JRadioButton enable_voice; - JButton test_voice; - JButton close; - - JButton configure_log; - JTextField log_directory; - - JLabel callsign_label; - JTextField callsign_value; - - /* DocumentListener interface methods */ - public void changedUpdate(DocumentEvent e) { - AltosPreferences.set_callsign(callsign_value.getText()); - } - - public void insertUpdate(DocumentEvent e) { - changedUpdate(e); - } - - public void removeUpdate(DocumentEvent e) { - changedUpdate(e); - } - - public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) { - super(in_owner, "Configure AltosUI", false); - - GridBagConstraints c; - - Insets insets = new Insets(4, 4, 4, 4); - - owner = in_owner; - voice = in_voice; - pane = getContentPane(); - pane.setLayout(new GridBagLayout()); - - c = new GridBagConstraints(); - c.insets = insets; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - - /* Nice label at the top */ - c.gridx = 0; - c.gridy = 0; - c.gridwidth = 3; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - pane.add(new JLabel ("Configure AltOS UI"), c); - - /* Voice settings */ - c.gridx = 0; - c.gridy = 1; - c.gridwidth = 1; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - pane.add(new JLabel("Voice"), c); - - enable_voice = new JRadioButton("Enable", AltosPreferences.voice()); - enable_voice.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - JRadioButton item = (JRadioButton) e.getSource(); - boolean enabled = item.isSelected(); - AltosPreferences.set_voice(enabled); - if (enabled) - voice.speak_always("Enable voice."); - else - voice.speak_always("Disable voice."); - } - }); - c.gridx = 1; - c.gridy = 1; - c.gridwidth = 1; - c.weightx = 1; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - pane.add(enable_voice, c); - - c.gridx = 2; - c.gridy = 1; - c.gridwidth = 1; - c.weightx = 1; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.EAST; - test_voice = new JButton("Test Voice"); - test_voice.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - voice.speak("That's one small step for man; one giant leap for mankind."); - } - }); - pane.add(test_voice, c); - - /* Log directory settings */ - c.gridx = 0; - c.gridy = 2; - c.gridwidth = 1; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - pane.add(new JLabel("Log Directory"), c); - - configure_log = new JButton(AltosPreferences.logdir().getPath()); - configure_log.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - AltosPreferences.ConfigureLog(); - configure_log.setText(AltosPreferences.logdir().getPath()); - } - }); - c.gridx = 1; - c.gridy = 2; - c.gridwidth = 2; - c.fill = GridBagConstraints.BOTH; - c.anchor = GridBagConstraints.WEST; - pane.add(configure_log, c); - - /* Callsign setting */ - c.gridx = 0; - c.gridy = 3; - c.gridwidth = 1; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - pane.add(new JLabel("Callsign"), c); - - callsign_value = new JTextField(AltosPreferences.callsign()); - callsign_value.getDocument().addDocumentListener(this); - c.gridx = 1; - c.gridy = 3; - c.gridwidth = 2; - c.fill = GridBagConstraints.BOTH; - c.anchor = GridBagConstraints.WEST; - pane.add(callsign_value, c); - - /* And a close button at the bottom */ - close = new JButton("Close"); - close.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - setVisible(false); - } - }); - c.gridx = 0; - c.gridy = 4; - c.gridwidth = 3; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - pane.add(close, c); - - pack(); - setLocationRelativeTo(owner); - setVisible(true); - } -} diff --git a/ao-tools/altosui/AltosConvert.java b/ao-tools/altosui/AltosConvert.java deleted file mode 100644 index 8cc1df27..00000000 --- a/ao-tools/altosui/AltosConvert.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -/* - * Sensor data conversion functions - */ -package altosui; - -public class AltosConvert { - /* - * Pressure Sensor Model, version 1.1 - * - * written by Holly Grimes - * - * Uses the International Standard Atmosphere as described in - * "A Quick Derivation relating altitude to air pressure" (version 1.03) - * from the Portland State Aerospace Society, except that the atmosphere - * is divided into layers with each layer having a different lapse rate. - * - * Lapse rate data for each layer was obtained from Wikipedia on Sept. 1, 2007 - * at site MAXIMUM_ALTITUDE) /* FIX ME: use sensor data to improve model */ - return 0; - - /* calculate the base temperature and pressure for the atmospheric layer - associated with the inputted altitude */ - for(layer_number = 0; layer_number < NUMBER_OF_LAYERS - 1 && altitude > base_altitude[layer_number + 1]; layer_number++) { - delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number]; - if (lapse_rate[layer_number] == 0.0) { - exponent = GRAVITATIONAL_ACCELERATION * delta_z - / AIR_GAS_CONSTANT / base_temperature; - base_pressure *= Math.exp(exponent); - } - else { - base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; - exponent = GRAVITATIONAL_ACCELERATION / - (AIR_GAS_CONSTANT * lapse_rate[layer_number]); - base_pressure *= Math.pow(base, exponent); - } - base_temperature += delta_z * lapse_rate[layer_number]; - } - - /* calculate the pressure at the inputted altitude */ - delta_z = altitude - base_altitude[layer_number]; - if (lapse_rate[layer_number] == 0.0) { - exponent = GRAVITATIONAL_ACCELERATION * delta_z - / AIR_GAS_CONSTANT / base_temperature; - pressure = base_pressure * Math.exp(exponent); - } - else { - base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; - exponent = GRAVITATIONAL_ACCELERATION / - (AIR_GAS_CONSTANT * lapse_rate[layer_number]); - pressure = base_pressure * Math.pow(base, exponent); - } - - return pressure; - } - - -/* outputs the altitude associated with the given pressure. the altitude - returned is measured with respect to the mean sea level */ - static double - pressure_to_altitude(double pressure) - { - - double next_base_temperature = LAYER0_BASE_TEMPERATURE; - double next_base_pressure = LAYER0_BASE_PRESSURE; - - double altitude; - double base_pressure; - double base_temperature; - double base; /* base for function to determine base pressure of next layer */ - double exponent; /* exponent for function to determine base pressure - of next layer */ - double coefficient; - int layer_number; /* identifies layer in the atmosphere */ - int delta_z; /* difference between two altitudes */ - - if (pressure < 0) /* illegal pressure */ - return -1; - if (pressure < MINIMUM_PRESSURE) /* FIX ME: use sensor data to improve model */ - return MAXIMUM_ALTITUDE; - - /* calculate the base temperature and pressure for the atmospheric layer - associated with the inputted pressure. */ - layer_number = -1; - do { - layer_number++; - base_pressure = next_base_pressure; - base_temperature = next_base_temperature; - delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number]; - if (lapse_rate[layer_number] == 0.0) { - exponent = GRAVITATIONAL_ACCELERATION * delta_z - / AIR_GAS_CONSTANT / base_temperature; - next_base_pressure *= Math.exp(exponent); - } - else { - base = (lapse_rate[layer_number] * delta_z / base_temperature) + 1.0; - exponent = GRAVITATIONAL_ACCELERATION / - (AIR_GAS_CONSTANT * lapse_rate[layer_number]); - next_base_pressure *= Math.pow(base, exponent); - } - next_base_temperature += delta_z * lapse_rate[layer_number]; - } - while(layer_number < NUMBER_OF_LAYERS - 1 && pressure < next_base_pressure); - - /* calculate the altitude associated with the inputted pressure */ - if (lapse_rate[layer_number] == 0.0) { - coefficient = (AIR_GAS_CONSTANT / GRAVITATIONAL_ACCELERATION) - * base_temperature; - altitude = base_altitude[layer_number] - + coefficient * Math.log(pressure / base_pressure); - } - else { - base = pressure / base_pressure; - exponent = AIR_GAS_CONSTANT * lapse_rate[layer_number] - / GRAVITATIONAL_ACCELERATION; - coefficient = base_temperature / lapse_rate[layer_number]; - altitude = base_altitude[layer_number] - + coefficient * (Math.pow(base, exponent) - 1); - } - - return altitude; - } - - static double - cc_battery_to_voltage(double battery) - { - return battery / 32767.0 * 5.0; - } - - static double - cc_ignitor_to_voltage(double ignite) - { - return ignite / 32767 * 15.0; - } -} diff --git a/ao-tools/altosui/AltosDataChooser.java b/ao-tools/altosui/AltosDataChooser.java deleted file mode 100644 index 15de05c2..00000000 --- a/ao-tools/altosui/AltosDataChooser.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; - -public class AltosDataChooser extends JFileChooser { - JFrame frame; - String filename; - File file; - - public String filename() { - return filename; - } - - public File file() { - return file; - } - - public AltosRecordIterable runDialog() { - int ret; - - ret = showOpenDialog(frame); - if (ret == APPROVE_OPTION) { - file = getSelectedFile(); - if (file == null) - return null; - filename = file.getName(); - try { - if (filename.endsWith("eeprom")) { - FileInputStream in = new FileInputStream(file); - return new AltosEepromIterable(in); - } else if (filename.endsWith("telem")) { - FileInputStream in = new FileInputStream(file); - return new AltosTelemetryIterable(in); - } else { - throw new FileNotFoundException(); - } - } catch (FileNotFoundException fe) { - JOptionPane.showMessageDialog(frame, - filename, - "Cannot open file", - JOptionPane.ERROR_MESSAGE); - } - } - return null; - } - - public AltosDataChooser(JFrame in_frame) { - frame = in_frame; - setDialogTitle("Select Flight Record File"); - setFileFilter(new FileNameExtensionFilter("Flight data file", - "telem", "eeprom")); - setCurrentDirectory(AltosPreferences.logdir()); - } -} diff --git a/ao-tools/altosui/AltosDataPoint.java b/ao-tools/altosui/AltosDataPoint.java deleted file mode 100644 index 66313e03..00000000 --- a/ao-tools/altosui/AltosDataPoint.java +++ /dev/null @@ -1,29 +0,0 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later - -package altosui; - -interface AltosDataPoint { - int version(); - int serial(); - int flight(); - String callsign(); - double time(); - double rssi(); - - int state(); - String state_name(); - - double acceleration(); - double pressure(); - double altitude(); - double height(); - double accel_speed(); - double baro_speed(); - double temperature(); - double battery_voltage(); - double drogue_voltage(); - double main_voltage(); -} - diff --git a/ao-tools/altosui/AltosDataPointReader.java b/ao-tools/altosui/AltosDataPointReader.java deleted file mode 100644 index 7704310b..00000000 --- a/ao-tools/altosui/AltosDataPointReader.java +++ /dev/null @@ -1,72 +0,0 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later - -package altosui; - -import java.io.IOException; -import java.text.ParseException; -import java.lang.UnsupportedOperationException; -import java.util.NoSuchElementException; -import java.util.Iterator; - -class AltosDataPointReader implements Iterable { - Iterator iter; - AltosState state; - AltosRecord record; - - public AltosDataPointReader(Iterable reader) { - this.iter = reader.iterator(); - this.state = null; - } - - private void read_next_record() - throws NoSuchElementException - { - record = iter.next(); - state = new AltosState(record, state); - } - - private AltosDataPoint current_dp() { - assert this.record != null; - - return new AltosDataPoint() { - public int version() { return record.version; } - public int serial() { return record.serial; } - public int flight() { return record.flight; } - public String callsign() { return record.callsign; } - public double time() { return record.time; } - public double rssi() { return record.rssi; } - - public int state() { return record.state; } - public String state_name() { return record.state(); } - - public double acceleration() { return record.acceleration(); } - public double pressure() { return record.raw_pressure(); } - public double altitude() { return record.raw_altitude(); } - public double height() { return record.raw_height(); } - public double accel_speed() { return record.accel_speed(); } - public double baro_speed() { return state.baro_speed; } - public double temperature() { return record.temperature(); } - public double battery_voltage() { return record.battery_voltage(); } - public double drogue_voltage() { return record.drogue_voltage(); } - public double main_voltage() { return record.main_voltage(); } - }; - } - - public Iterator iterator() { - return new Iterator() { - public void remove() { - throw new UnsupportedOperationException(); - } - public boolean hasNext() { - return iter.hasNext(); - } - public AltosDataPoint next() { - read_next_record(); - return current_dp(); - } - }; - } -} - diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java deleted file mode 100644 index 8d435b66..00000000 --- a/ao-tools/altosui/AltosDebug.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.io.*; -import java.util.concurrent.*; -import java.util.*; - -import libaltosJNI.*; - -public class AltosDebug extends AltosSerial { - - public static final byte WR_CONFIG = 0x1d; - public static final byte RD_CONFIG = 0x24; - public static final byte CONFIG_TIMERS_OFF = (1 << 3); - public static final byte CONFIG_DMA_PAUSE = (1 << 2); - public static final byte CONFIG_TIMER_SUSPEND = (1 << 1); - public static final byte SET_FLASH_INFO_PAGE = (1 << 0); - - public static final byte GET_PC = 0x28; - public static final byte READ_STATUS = 0x34; - public static final byte STATUS_CHIP_ERASE_DONE = (byte) (1 << 7); - public static final byte STATUS_PCON_IDLE = (1 << 6); - public static final byte STATUS_CPU_HALTED = (1 << 5); - public static final byte STATUS_POWER_MODE_0 = (1 << 4); - public static final byte STATUS_HALT_STATUS = (1 << 3); - public static final byte STATUS_DEBUG_LOCKED = (1 << 2); - public static final byte STATUS_OSCILLATOR_STABLE = (1 << 1); - public static final byte STATUS_STACK_OVERFLOW = (1 << 0); - - public static final byte SET_HW_BRKPNT = 0x3b; - public static byte HW_BRKPNT_N(byte n) { return (byte) ((n) << 3); } - public static final byte HW_BRKPNT_N_MASK = (0x3 << 3); - public static final byte HW_BRKPNT_ENABLE = (1 << 2); - - public static final byte HALT = 0x44; - public static final byte RESUME = 0x4c; - public static byte DEBUG_INSTR(byte n) { return (byte) (0x54|(n)); } - public static final byte STEP_INSTR = 0x5c; - public static byte STEP_REPLACE(byte n) { return (byte) (0x64|(n)); } - public static final byte GET_CHIP_ID = 0x68; - - - boolean debug_mode; - - void ensure_debug_mode() { - if (!debug_mode) { - printf("D\n"); - flush_input(); - debug_mode = true; - } - } - - void dump_memory(String header, int address, byte[] bytes, int start, int len) { - System.out.printf("%s\n", header); - for (int j = 0; j < len; j++) { - if ((j & 15) == 0) { - if (j != 0) - System.out.printf("\n"); - System.out.printf ("%04x:", address + j); - } - System.out.printf(" %02x", bytes[start + j]); - } - System.out.printf("\n"); - } - - /* - * Write target memory - */ - public void write_memory(int address, byte[] bytes, int start, int len) { - ensure_debug_mode(); -// dump_memory("write_memory", address, bytes, start, len); - printf("O %x %x\n", len, address); - for (int i = 0; i < len; i++) - printf("%02x", bytes[start + i]); - } - - public void write_memory(int address, byte[] bytes) { - write_memory(address, bytes, 0, bytes.length); - } - - /* - * Read target memory - */ - public byte[] read_memory(int address, int length) - throws IOException, InterruptedException { - byte[] data = new byte[length]; - - flush_input(); - ensure_debug_mode(); - printf("I %x %x\n", length, address); - int i = 0; - int start = 0; - while (i < length) { - String line = get_reply().trim(); - if (!Altos.ishex(line) || line.length() % 2 != 0) - throw new IOException( - String.format - ("Invalid reply \"%s\"", line)); - int this_time = line.length() / 2; - for (int j = 0; j < this_time; j++) - data[start + j] = (byte) ((Altos.fromhex(line.charAt(j*2)) << 4) + - Altos.fromhex(line.charAt(j*2+1))); - start += this_time; - i += this_time; - } -// dump_memory("read_memory", address, data, 0, length); - - return data; - } - - /* - * Write raw bytes to the debug link using the 'P' command - */ - public void write_bytes(byte[] bytes) throws IOException { - int i = 0; - ensure_debug_mode(); - while (i < bytes.length) { - int this_time = bytes.length - i; - if (this_time > 8) - this_time = 0; - printf("P"); - for (int j = 0; j < this_time; j++) - printf(" %02x", bytes[i+j]); - printf("\n"); - i += this_time; - } - } - - public void write_byte(byte b) throws IOException { - byte[] bytes = { b }; - write_bytes(bytes); - } - - /* - * Read raw bytes from the debug link using the 'G' command - */ - public byte[] read_bytes(int length) - throws IOException, InterruptedException { - - flush_input(); - ensure_debug_mode(); - printf("G %x\n", length); - int i = 0; - byte[] data = new byte[length]; - while (i < length) { - String line = get_reply().trim(); - String tokens[] = line.split("\\s+"); - for (int j = 0; j < tokens.length; j++) { - if (!Altos.ishex(tokens[j]) || - tokens[j].length() != 2) - throw new IOException( - String.format - ("Invalid read_bytes reply \"%s\"", line)); - try { - data[i + j] = (byte) Integer.parseInt(tokens[j], 16); - } catch (NumberFormatException ne) { - throw new IOException( - String.format - ("Invalid read_bytes reply \"%s\"", line)); - } - } - i += tokens.length; - } - return data; - } - - public byte read_byte() throws IOException, InterruptedException { - return read_bytes(1)[0]; - } - - public byte debug_instr(byte[] instruction) throws IOException, InterruptedException { - byte[] command = new byte[1 + instruction.length]; - command[0] = DEBUG_INSTR((byte) instruction.length); - for (int i = 0; i < instruction.length; i++) - command[i+1] = instruction[i]; - write_bytes(command); - return read_byte(); - } - - public byte resume() throws IOException, InterruptedException { - write_byte(RESUME); - return read_byte(); - } - - public int read_uint16() throws IOException, InterruptedException { - byte[] d = read_bytes(2); - return ((int) (d[0] & 0xff) << 8) | (d[1] & 0xff); - } - - public int read_uint8() throws IOException, InterruptedException { - byte[] d = read_bytes(1); - return (int) (d[0] & 0xff); - } - - public int get_chip_id() throws IOException, InterruptedException { - write_byte(GET_CHIP_ID); - return read_uint16(); - } - - public int get_pc() throws IOException, InterruptedException { - write_byte(GET_PC); - return read_uint16(); - } - - public byte read_status() throws IOException, InterruptedException { - write_byte(READ_STATUS); - return read_byte(); - } - - static final byte LJMP = 0x02; - - public void set_pc(int pc) throws IOException, InterruptedException { - byte high = (byte) (pc >> 8); - byte low = (byte) pc; - byte[] jump_mem = { LJMP, high, low }; - debug_instr(jump_mem); - } - - public boolean check_connection() throws IOException, InterruptedException { - byte reply = read_status(); - if ((reply & STATUS_CHIP_ERASE_DONE) == 0) - return false; - if ((reply & STATUS_PCON_IDLE) != 0) - return false; - if ((reply & STATUS_POWER_MODE_0) == 0) - return false; - return true; - } - - public AltosRomconfig romconfig() { - try { - byte[] bytes = read_memory(0xa0, 10); - return new AltosRomconfig(bytes, 0); - } catch (IOException ie) { - } catch (InterruptedException ie) { - } - return new AltosRomconfig(); - } - - /* - * Reset target - */ - public void reset() { - printf ("R\n"); - } - - public AltosDebug (AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { - super(in_device); - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosDescent.java b/ao-tools/altosui/AltosDescent.java deleted file mode 100644 index 16ccd458..00000000 --- a/ao-tools/altosui/AltosDescent.java +++ /dev/null @@ -1,353 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosDescent extends JComponent implements AltosFlightDisplay { - GridBagLayout layout; - - public abstract class DescentStatus { - JLabel label; - JTextField value; - AltosLights lights; - - abstract void show(AltosState state, int crc_errors); - void reset() { - value.setText(""); - lights.set(false); - } - - public DescentStatus (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - lights = new AltosLights(); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(lights, c); - add(lights); - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.gridwidth = 3; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 4; c.gridy = y; - c.gridwidth = 1; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - - } - } - - public abstract class DescentValue { - JLabel label; - JTextField value; - - void reset() { - value.setText(""); - } - - abstract void show(AltosState state, int crc_errors); - - void show(String format, double v) { - value.setText(String.format(format, v)); - } - - void show(String v) { - value.setText(v); - } - - public DescentValue (GridBagLayout layout, int x, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = x + 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - add(label, c); - - value = new JTextField(Altos.text_width); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 2; c.gridy = y; - c.gridwidth = 1; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - add(value, c); - } - } - - public abstract class DescentDualValue { - JLabel label; - JTextField value1; - JTextField value2; - - void reset() { - value1.setText(""); - value2.setText(""); - } - - abstract void show(AltosState state, int crc_errors); - void show(String v1, String v2) { - value1.setText(v1); - value2.setText(v2); - } - void show(String f1, double v1, String f2, double v2) { - value1.setText(String.format(f1, v1)); - value2.setText(String.format(f2, v2)); - } - - public DescentDualValue (GridBagLayout layout, int x, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = x + 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value1 = new JTextField(Altos.text_width); - value1.setFont(Altos.value_font); - value1.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 2; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value1, c); - add(value1); - - value2 = new JTextField(Altos.text_width); - value2.setFont(Altos.value_font); - value2.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 4; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - c.gridwidth = 1; - layout.setConstraints(value2, c); - add(value2); - } - } - - class Height extends DescentValue { - void show (AltosState state, int crc_errors) { - show("%6.0f m", state.height); - } - public Height (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Height"); - } - } - - Height height; - - class Speed extends DescentValue { - void show (AltosState state, int crc_errors) { - double speed = state.speed; - if (!state.ascent) - speed = state.baro_speed; - show("%6.0f m/s", speed); - } - public Speed (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Speed"); - } - } - - Speed speed; - - String pos(double p, String pos, String neg) { - String h = pos; - if (p < 0) { - h = neg; - p = -p; - } - int deg = (int) Math.floor(p); - double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %d° %9.6f", h, deg, min); - } - - class Lat extends DescentValue { - void show (AltosState state, int crc_errors) { - if (state.gps != null) - show(pos(state.gps.lat,"N", "S")); - else - show("???"); - } - public Lat (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Latitude"); - } - } - - Lat lat; - - class Lon extends DescentValue { - void show (AltosState state, int crc_errors) { - if (state.gps != null) - show(pos(state.gps.lon,"W", "E")); - else - show("???"); - } - public Lon (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Longitude"); - } - } - - Lon lon; - - class Apogee extends DescentStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.2f V", state.drogue_sense)); - lights.set(state.drogue_sense > 3.2); - } - public Apogee (GridBagLayout layout, int y) { - super(layout, y, "Apogee Igniter Voltage"); - } - } - - Apogee apogee; - - class Main extends DescentStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.2f V", state.main_sense)); - lights.set(state.main_sense > 3.2); - } - public Main (GridBagLayout layout, int y) { - super(layout, y, "Main Igniter Voltage"); - } - } - - Main main; - - class Bearing extends DescentDualValue { - void show (AltosState state, int crc_errors) { - if (state.from_pad != null) { - show( String.format("%3.0f°", state.from_pad.bearing), - state.from_pad.bearing_words( - AltosGreatCircle.BEARING_LONG)); - } else { - show("???", "???"); - } - } - public Bearing (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Bearing"); - } - } - - Bearing bearing; - - class Range extends DescentValue { - void show (AltosState state, int crc_errors) { - show("%6.0f m", state.range); - } - public Range (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Range"); - } - } - - Range range; - - class Elevation extends DescentValue { - void show (AltosState state, int crc_errors) { - show("%3.0f°", state.elevation); - } - public Elevation (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Elevation"); - } - } - - Elevation elevation; - - public void reset() { - lat.reset(); - lon.reset(); - height.reset(); - speed.reset(); - bearing.reset(); - range.reset(); - elevation.reset(); - main.reset(); - apogee.reset(); - } - - public void show(AltosState state, int crc_errors) { - height.show(state, crc_errors); - speed.show(state, crc_errors); - bearing.show(state, crc_errors); - range.show(state, crc_errors); - elevation.show(state, crc_errors); - lat.show(state, crc_errors); - lon.show(state, crc_errors); - main.show(state, crc_errors); - apogee.show(state, crc_errors); - } - - public AltosDescent() { - layout = new GridBagLayout(); - - setLayout(layout); - - /* Elements in descent display */ - speed = new Speed(layout, 0, 0); - height = new Height(layout, 2, 0); - elevation = new Elevation(layout, 0, 1); - range = new Range(layout, 2, 1); - bearing = new Bearing(layout, 0, 2); - lat = new Lat(layout, 0, 3); - lon = new Lon(layout, 2, 3); - - apogee = new Apogee(layout, 4); - main = new Main(layout, 5); - } -} diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java deleted file mode 100644 index f0fda57b..00000000 --- a/ao-tools/altosui/AltosDevice.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; -import java.lang.*; -import java.util.*; -import libaltosJNI.*; - -public class AltosDevice extends altos_device { - - static public boolean initialized = false; - static public boolean loaded_library = false; - - public static boolean load_library() { - if (!initialized) { - try { - System.loadLibrary("altos"); - libaltos.altos_init(); - loaded_library = true; - } catch (UnsatisfiedLinkError e) { - loaded_library = false; - } - initialized = true; - } - return loaded_library; - } - - static int usb_vendor_altusmetrum() { - if (load_library()) - return libaltosConstants.USB_VENDOR_ALTUSMETRUM; - return 0x000a; - } - - static int usb_product_altusmetrum() { - if (load_library()) - return libaltosConstants.USB_PRODUCT_ALTUSMETRUM; - return 0x000a; - } - - static int usb_product_altusmetrum_min() { - if (load_library()) - return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MIN; - return 0x000a; - } - - static int usb_product_altusmetrum_max() { - if (load_library()) - return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MAX; - return 0x000d; - } - - static int usb_product_telemetrum() { - if (load_library()) - return libaltosConstants.USB_PRODUCT_TELEMETRUM; - return 0x000b; - } - - static int usb_product_teledongle() { - if (load_library()) - return libaltosConstants.USB_PRODUCT_TELEDONGLE; - return 0x000c; - } - - static int usb_product_teleterra() { - if (load_library()) - return libaltosConstants.USB_PRODUCT_TELETERRA; - return 0x000d; - } - - public final static int vendor_altusmetrum = usb_vendor_altusmetrum(); - public final static int product_altusmetrum = usb_product_altusmetrum(); - public final static int product_telemetrum = usb_product_telemetrum(); - public final static int product_teledongle = usb_product_teledongle(); - public final static int product_teleterra = usb_product_teleterra(); - public final static int product_altusmetrum_min = usb_product_altusmetrum_min(); - public final static int product_altusmetrum_max = usb_product_altusmetrum_max(); - - - public final static int product_any = 0x10000; - public final static int product_basestation = 0x10000 + 1; - - public String toString() { - String name = getName(); - if (name == null) - name = "Altus Metrum"; - return String.format("%-20.20s %4d %s", - getName(), getSerial(), getPath()); - } - - public String toShortString() { - String name = getName(); - if (name == null) - name = "Altus Metrum"; - return String.format("%s %d %s", - name, getSerial(), getPath()); - - } - - public boolean isAltusMetrum() { - if (getVendor() != vendor_altusmetrum) - return false; - if (getProduct() < product_altusmetrum_min) - return false; - if (getProduct() > product_altusmetrum_max) - return false; - return true; - } - - public boolean matchProduct(int want_product) { - - if (!isAltusMetrum()) - return false; - - if (want_product == product_any) - return true; - - if (want_product == product_basestation) - return matchProduct(product_teledongle) || matchProduct(product_teleterra); - - int have_product = getProduct(); - - if (have_product == product_altusmetrum) /* old devices match any request */ - return true; - - if (want_product == have_product) - return true; - - return false; - } - - static AltosDevice[] list(int product) { - if (!load_library()) - return null; - - SWIGTYPE_p_altos_list list = libaltos.altos_list_start(); - - ArrayList device_list = new ArrayList(); - if (list != null) { - SWIGTYPE_p_altos_file file; - - for (;;) { - AltosDevice device = new AltosDevice(); - if (libaltos.altos_list_next(list, device) == 0) - break; - if (device.matchProduct(product)) - device_list.add(device); - } - libaltos.altos_list_finish(list); - } - - AltosDevice[] devices = new AltosDevice[device_list.size()]; - for (int i = 0; i < device_list.size(); i++) - devices[i] = device_list.get(i); - return devices; - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java deleted file mode 100644 index 2966ad1e..00000000 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.util.*; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import libaltosJNI.libaltos; -import libaltosJNI.altos_device; -import libaltosJNI.SWIGTYPE_p_altos_file; -import libaltosJNI.SWIGTYPE_p_altos_list; - -public class AltosDeviceDialog extends JDialog implements ActionListener { - - private static AltosDeviceDialog dialog; - private static AltosDevice value = null; - private JList list; - - public static AltosDevice show (Component frameComp, int product) { - - Frame frame = JOptionPane.getFrameForComponent(frameComp); - AltosDevice[] devices; - devices = AltosDevice.list(product); - - if (devices != null && devices.length > 0) { - value = null; - dialog = new AltosDeviceDialog(frame, frameComp, - devices, - devices[0]); - - dialog.setVisible(true); - return value; - } else { - /* check for missing altos JNI library, which - * will put up its own error dialog - */ - if (AltosUI.load_library(frame)) { - JOptionPane.showMessageDialog(frame, - "No AltOS devices available", - "No AltOS devices", - JOptionPane.ERROR_MESSAGE); - } - return null; - } - } - - private AltosDeviceDialog (Frame frame, Component location, - AltosDevice[] devices, - AltosDevice initial) { - super(frame, "Device Selection", true); - - value = null; - - JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(this); - - final JButton selectButton = new JButton("Select"); - selectButton.setActionCommand("select"); - selectButton.addActionListener(this); - getRootPane().setDefaultButton(selectButton); - - list = new JList(devices) { - //Subclass JList to workaround bug 4832765, which can cause the - //scroll pane to not let the user easily scroll up to the beginning - //of the list. An alternative would be to set the unitIncrement - //of the JScrollBar to a fixed value. You wouldn't get the nice - //aligned scrolling, but it should work. - public int getScrollableUnitIncrement(Rectangle visibleRect, - int orientation, - int direction) { - int row; - if (orientation == SwingConstants.VERTICAL && - direction < 0 && (row = getFirstVisibleIndex()) != -1) { - Rectangle r = getCellBounds(row, row); - if ((r.y == visibleRect.y) && (row != 0)) { - Point loc = r.getLocation(); - loc.y--; - int prevIndex = locationToIndex(loc); - Rectangle prevR = getCellBounds(prevIndex, prevIndex); - - if (prevR == null || prevR.y >= r.y) { - return 0; - } - return prevR.height; - } - } - return super.getScrollableUnitIncrement( - visibleRect, orientation, direction); - } - }; - - list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - list.setLayoutOrientation(JList.HORIZONTAL_WRAP); - list.setVisibleRowCount(-1); - list.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() == 2) { - selectButton.doClick(); //emulate button click - } - } - }); - JScrollPane listScroller = new JScrollPane(list); - listScroller.setPreferredSize(new Dimension(400, 80)); - listScroller.setAlignmentX(LEFT_ALIGNMENT); - - //Create a container so that we can add a title around - //the scroll pane. Can't add a title directly to the - //scroll pane because its background would be white. - //Lay out the label and scroll pane from top to bottom. - JPanel listPane = new JPanel(); - listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); - - JLabel label = new JLabel("Select Device"); - label.setLabelFor(list); - listPane.add(label); - listPane.add(Box.createRigidArea(new Dimension(0,5))); - listPane.add(listScroller); - listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); - - //Lay out the buttons from left to right. - JPanel buttonPane = new JPanel(); - buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); - buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); - buttonPane.add(Box.createHorizontalGlue()); - buttonPane.add(cancelButton); - buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); - buttonPane.add(selectButton); - - //Put everything together, using the content pane's BorderLayout. - Container contentPane = getContentPane(); - contentPane.add(listPane, BorderLayout.CENTER); - contentPane.add(buttonPane, BorderLayout.PAGE_END); - - //Initialize values. - list.setSelectedValue(initial, true); - pack(); - setLocationRelativeTo(location); - } - - //Handle clicks on the Set and Cancel buttons. - public void actionPerformed(ActionEvent e) { - if ("select".equals(e.getActionCommand())) - AltosDeviceDialog.value = (AltosDevice)(list.getSelectedValue()); - AltosDeviceDialog.dialog.setVisible(false); - } - -} diff --git a/ao-tools/altosui/AltosDisplayThread.java b/ao-tools/altosui/AltosDisplayThread.java deleted file mode 100644 index 3e719130..00000000 --- a/ao-tools/altosui/AltosDisplayThread.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosDisplayThread extends Thread { - - Frame parent; - IdleThread idle_thread; - AltosVoice voice; - String name; - AltosFlightReader reader; - int crc_errors; - AltosFlightDisplay display; - - synchronized void show(AltosState state, int crc_errors) { - if (state != null) - display.show(state, crc_errors); - } - - 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 < Altos.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 (Altos.ao_flight_drogue <= state.state && - state.state < Altos.ao_flight_landed && - state.range >= 0) - { - voice.speak("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 > Altos.ao_flight_pad) { - voice.speak("%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 >= Altos.ao_flight_drogue && - (last || - System.currentTimeMillis() - state.report_time >= 15000 || - state.state == Altos.ao_flight_landed)) - { - if (Math.abs(state.baro_speed) < 20 && state.height < 100) - voice.speak("rocket landed safely"); - else - voice.speak("rocket may have crashed"); - if (state.from_pad != null) - voice.speak("Bearing %d degrees, range %d meters.", - (int) (state.from_pad.bearing + 0.5), - (int) (state.from_pad.distance + 0.5)); - ++reported_landing; - if (state.state != Altos.ao_flight_landed) { - state.state = Altos.ao_flight_landed; - show(state, 0); - } - } - } - - long now () { - return System.currentTimeMillis(); - } - - void set_report_time() { - report_time = now() + report_interval; - } - - public void run () { - try { - for (;;) { - set_report_time(); - for (;;) { - voice.drain(); - synchronized (this) { - long sleep_time = report_time - now(); - if (sleep_time <= 0) - break; - wait(sleep_time); - } - } - report(false); - } - } catch (InterruptedException ie) { - try { - voice.drain(); - } catch (InterruptedException iie) { } - } - } - - public synchronized void notice(AltosState new_state, boolean spoken) { - AltosState old_state = state; - state = new_state; - if (!started && state.state > Altos.ao_flight_pad) { - started = true; - start(); - } - - if (state.state < Altos.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; - } - } - - boolean tell(AltosState state, AltosState old_state) { - boolean ret = false; - if (old_state == null || old_state.state != state.state) { - voice.speak(state.data.state()); - if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && - state.state > Altos.ao_flight_boost) { - voice.speak("max speed: %d meters per second.", - (int) (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: %d meters.", - (int) (state.max_height + 0.5)); - ret = true; - } - } - if (old_state == null || old_state.gps_ready != state.gps_ready) { - if (state.gps_ready) { - voice.speak("GPS ready"); - ret = true; - } - else if (old_state != null) { - voice.speak("GPS lost"); - ret = true; - } - } - old_state = state; - return ret; - } - - public void run() { - boolean interrupted = false; - String line; - AltosState state = null; - AltosState old_state = null; - boolean told; - - idle_thread = new IdleThread(); - - display.reset(); - try { - for (;;) { - try { - AltosRecord record = reader.read(); - if (record == null) - break; - old_state = state; - state = new AltosState(record, state); - reader.update(state); - show(state, crc_errors); - told = tell(state, old_state); - idle_thread.notice(state, told); - } catch (ParseException pp) { - System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); - } catch (AltosCRCException ce) { - ++crc_errors; - show(state, crc_errors); - } - } - } catch (InterruptedException ee) { - interrupted = true; - } catch (IOException ie) { - JOptionPane.showMessageDialog(parent, - String.format("Error reading from \"%s\"", name), - "Telemetry Read Error", - JOptionPane.ERROR_MESSAGE); - } finally { - if (!interrupted) - idle_thread.report(true); - reader.close(interrupted); - idle_thread.interrupt(); - try { - idle_thread.join(); - } catch (InterruptedException ie) {} - } - } - - public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosFlightDisplay in_display, AltosFlightReader in_reader) { - parent = in_parent; - voice = in_voice; - display = in_display; - reader = in_reader; - } -} diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java deleted file mode 100644 index 02fc36f2..00000000 --- a/ao-tools/altosui/AltosEepromDownload.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; - -import libaltosJNI.*; - -public class AltosEepromDownload implements Runnable { - - static final String[] state_names = { - "startup", - "idle", - "pad", - "boost", - "fast", - "coast", - "drogue", - "main", - "landed", - "invalid", - }; - - int[] ParseHex(String line) { - String[] tokens = line.split("\\s+"); - int[] array = new int[tokens.length]; - - for (int i = 0; i < tokens.length; i++) - try { - array[i] = Integer.parseInt(tokens[i], 16); - } catch (NumberFormatException ne) { - return null; - } - return array; - } - - int checksum(int[] line) { - int csum = 0x5a; - for (int i = 1; i < line.length; i++) - csum += line[i]; - return csum & 0xff; - } - - void FlushPending(FileWriter file, LinkedList pending) throws IOException { - while (!pending.isEmpty()) { - file.write(pending.remove()); - } - } - - JFrame frame; - AltosDevice device; - AltosSerial serial_line; - boolean remote; - Thread eeprom_thread; - AltosEepromMonitor monitor; - - void CaptureLog() throws IOException, InterruptedException, TimeoutException { - int serial = 0; - int block, state_block = 0; - int addr; - int flight = 0; - int year = 0, month = 0, day = 0; - int state = 0; - boolean done = false; - boolean want_file = false; - boolean any_valid; - FileWriter eeprom_file = null; - AltosFile eeprom_name; - LinkedList eeprom_pending = new LinkedList(); - - serial_line.printf("\nc s\nv\n"); - - /* Pull the serial number out of the version information */ - - for (;;) { - String line = serial_line.get_reply(5000); - - if (line == null) - throw new TimeoutException(); - if (line.startsWith("serial-number")) { - try { - serial = Integer.parseInt(line.substring(13).trim()); - } catch (NumberFormatException ne) { - serial = 0; - } - } - - eeprom_pending.add(String.format("%s\n", line)); - - /* signals the end of the version info */ - if (line.startsWith("software-version")) - break; - } - if (serial == 0) - throw new IOException("no serial number found"); - - monitor.set_serial(serial); - /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */ - - state = 0; state_block = 0; - for (block = 0; !done && block < 511; block++) { - serial_line.printf("e %x\n", block); - any_valid = false; - monitor.set_value(state_names[state], state, block - state_block); - for (addr = 0; addr < 0x100;) { - String line = serial_line.get_reply(5000); - if (line == null) - throw new TimeoutException(); - int[] values = ParseHex(line); - - if (values == null) { - System.out.printf("invalid line: %s\n", line); - continue; - } else if (values[0] != addr) { - System.out.printf("data address out of sync at 0x%x\n", - block * 256 + values[0]); - } else if (checksum(values) != 0) { - System.out.printf("invalid checksum at 0x%x\n", - block * 256 + values[0]); - } else { - any_valid = true; - int cmd = values[1]; - int tick = values[3] + (values[4] << 8); - int a = values[5] + (values[6] << 8); - int b = values[7] + (values[8] << 8); - - if (cmd == Altos.AO_LOG_FLIGHT) { - flight = b; - monitor.set_flight(flight); - } - - /* Monitor state transitions to update display */ - if (cmd == Altos.AO_LOG_STATE && a <= Altos.ao_flight_landed) { - if (a > Altos.ao_flight_pad) - want_file = true; - if (a > state) - state_block = block; - state = a; - } - - if (cmd == Altos.AO_LOG_GPS_DATE) { - year = 2000 + (a & 0xff); - month = (a >> 8) & 0xff; - day = (b & 0xff); - want_file = true; - } - - if (eeprom_file == null) { - if (serial != 0 && flight != 0 && want_file) { - if (year != 0 && month != 0 && day != 0) - eeprom_name = new AltosFile(year, month, day, serial, flight, "eeprom"); - else - eeprom_name = new AltosFile(serial, flight, "eeprom"); - - monitor.set_file(eeprom_name.getName()); - eeprom_file = new FileWriter(eeprom_name); - if (eeprom_file != null) { - FlushPending(eeprom_file, eeprom_pending); - eeprom_pending = null; - } - } - } - - String log_line = String.format("%c %4x %4x %4x\n", - cmd, tick, a, b); - if (eeprom_file != null) - eeprom_file.write(log_line); - else - eeprom_pending.add(log_line); - - if (cmd == Altos.AO_LOG_STATE && a == Altos.ao_flight_landed) { - done = true; - } - } - addr += 8; - } - if (!any_valid) - done = true; - } - if (eeprom_file == null) { - eeprom_name = new AltosFile(serial,flight,"eeprom"); - eeprom_file = new FileWriter(eeprom_name); - if (eeprom_file != null) { - FlushPending(eeprom_file, eeprom_pending); - } - } - if (eeprom_file != null) { - eeprom_file.flush(); - eeprom_file.close(); - } - } - - public void run () { - if (remote) { - serial_line.set_radio(); - serial_line.printf("p\nE 0\n"); - serial_line.flush_input(); - } - - monitor = new AltosEepromMonitor(frame, Altos.ao_flight_boost, Altos.ao_flight_landed); - monitor.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - eeprom_thread.interrupt(); - } - }); - try { - CaptureLog(); - } catch (IOException ee) { - JOptionPane.showMessageDialog(frame, - device.toShortString(), - ee.getLocalizedMessage(), - JOptionPane.ERROR_MESSAGE); - } catch (InterruptedException ie) { - } catch (TimeoutException te) { - JOptionPane.showMessageDialog(frame, - String.format("Connection to \"%s\" failed", - device.toShortString()), - "Connection Failed", - JOptionPane.ERROR_MESSAGE); - } - if (remote) - serial_line.printf("~"); - monitor.done(); - serial_line.flush_output(); - serial_line.close(); - } - - public AltosEepromDownload(JFrame given_frame) { - frame = given_frame; - device = AltosDeviceDialog.show(frame, AltosDevice.product_any); - - remote = false; - - if (device != null) { - try { - serial_line = new AltosSerial(device); - if (!device.matchProduct(AltosDevice.product_telemetrum)) - remote = true; - eeprom_thread = new Thread(this); - eeprom_thread.start(); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(frame, - String.format("Cannot open device \"%s\"", - device.toShortString()), - "Cannot open target device", - JOptionPane.ERROR_MESSAGE); - } catch (AltosSerialInUseException si) { - JOptionPane.showMessageDialog(frame, - String.format("Device \"%s\" already in use", - device.toShortString()), - "Device in use", - JOptionPane.ERROR_MESSAGE); - } catch (IOException ee) { - JOptionPane.showMessageDialog(frame, - device.toShortString(), - ee.getLocalizedMessage(), - JOptionPane.ERROR_MESSAGE); - } - } - } -} diff --git a/ao-tools/altosui/AltosEepromIterable.java b/ao-tools/altosui/AltosEepromIterable.java deleted file mode 100644 index f8e6d7e5..00000000 --- a/ao-tools/altosui/AltosEepromIterable.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -/* - * 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 { - - 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 int compareTo(AltosOrderedRecord o) { - int tick_diff = tick - o.tick; - if (tick_diff != 0) - return tick_diff; - return index - o.index; - } -} - -public class AltosEepromIterable 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|seen_temp_volt|seen_deploy; - - AltosEepromRecord flight_record; - AltosEepromRecord gps_date_record; - - TreeSet records; - - LinkedList list; - - class EepromState { - int seen; - int n_pad_samples; - double ground_pres; - int gps_tick; - int boost_tick; - - EepromState() { - seen = 0; - n_pad_samples = 0; - ground_pres = 0.0; - gps_tick = 0; - } - } - - void update_state(AltosRecord state, AltosEepromRecord record, EepromState eeprom) { - state.tick = record.tick; - switch (record.cmd) { - case Altos.AO_LOG_FLIGHT: - eeprom.seen |= seen_flight; - state.ground_accel = record.a; - state.flight_accel = record.a; - state.flight = record.b; - eeprom.boost_tick = record.tick; - break; - case Altos.AO_LOG_SENSOR: - state.accel = record.a; - state.pres = record.b; - if (state.state < Altos.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; - state.flight_vel += (state.accel_plus_g - state.accel); - } - eeprom.seen |= seen_sensor; - break; - case Altos.AO_LOG_TEMP_VOLT: - state.temp = record.a; - state.batt = record.b; - eeprom.seen |= seen_temp_volt; - break; - case Altos.AO_LOG_DEPLOY: - state.drogue = record.a; - state.main = record.b; - eeprom.seen |= seen_deploy; - break; - case Altos.AO_LOG_STATE: - state.state = record.a; - break; - case Altos.AO_LOG_GPS_TIME: - eeprom.gps_tick = state.tick; - AltosGPS old = state.gps; - state.gps = new AltosGPS(); - - /* 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); - - int flags = (record.b >> 8); - state.gps.connected = (flags & Altos.AO_GPS_RUNNING) != 0; - state.gps.locked = (flags & Altos.AO_GPS_VALID) != 0; - state.gps.date_valid = (flags & Altos.AO_GPS_DATE_VALID) != 0; - state.gps.nsat = (flags & Altos.AO_GPS_NUM_SAT_MASK) >> - Altos.AO_GPS_NUM_SAT_SHIFT; - break; - case Altos.AO_LOG_GPS_LAT: - int lat32 = record.a | (record.b << 16); - state.gps.lat = (double) lat32 / 1e7; - break; - case Altos.AO_LOG_GPS_LON: - int lon32 = record.a | (record.b << 16); - state.gps.lon = (double) lon32 / 1e7; - break; - case Altos.AO_LOG_GPS_ALT: - state.gps.alt = record.a; - break; - case Altos.AO_LOG_GPS_SAT: - if (state.tick == eeprom.gps_tick) { - int svid = record.a; - int c_n0 = record.b >> 8; - state.gps.add_sat(svid, c_n0); - } - break; - case Altos.AO_LOG_GPS_DATE: - state.gps.year = (record.a & 0xff) + 2000; - state.gps.month = record.a >> 8; - state.gps.day = record.b & 0xff; - break; - - case Altos.AO_LOG_CONFIG_VERSION: - break; - case Altos.AO_LOG_MAIN_DEPLOY: - break; - case Altos.AO_LOG_APOGEE_DELAY: - break; - case Altos.AO_LOG_RADIO_CHANNEL: - break; - case Altos.AO_LOG_CALLSIGN: - state.callsign = record.data; - break; - case Altos.AO_LOG_ACCEL_CAL: - state.accel_plus_g = record.a; - state.accel_minus_g = record.b; - break; - case Altos.AO_LOG_RADIO_CAL: - break; - case Altos.AO_LOG_MANUFACTURER: - break; - case Altos.AO_LOG_PRODUCT: - break; - case Altos.AO_LOG_SERIAL_NUMBER: - state.serial = record.a; - break; - case Altos.AO_LOG_SOFTWARE_VERSION: - break; - } - } - - LinkedList make_list() { - LinkedList list = new LinkedList(); - Iterator iterator = records.iterator(); - AltosOrderedRecord record = null; - AltosRecord state = new AltosRecord(); - boolean last_reported = false; - EepromState eeprom = new EepromState(); - - state.state = Altos.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) { - AltosRecord r = new AltosRecord(state); - r.time = (r.tick - eeprom.boost_tick) / 100.0; - list.add(r); - } - update_state(state, record, eeprom); - } - AltosRecord r = new AltosRecord(state); - r.time = (r.tick - eeprom.boost_tick) / 100.0; - list.add(r); - return list; - } - - public Iterator iterator() { - if (list == null) - list = make_list(); - return list.iterator(); - } - - public void write_comments(PrintStream out) { - Iterator iterator = records.iterator(); - out.printf("# Comments\n"); - while (iterator.hasNext()) { - AltosOrderedRecord record = iterator.next(); - switch (record.cmd) { - case Altos.AO_LOG_CONFIG_VERSION: - out.printf("# Config version: %s\n", record.data); - break; - case Altos.AO_LOG_MAIN_DEPLOY: - out.printf("# Main deploy: %s\n", record.a); - break; - case Altos.AO_LOG_APOGEE_DELAY: - out.printf("# Apogee delay: %s\n", record.a); - break; - case Altos.AO_LOG_RADIO_CHANNEL: - out.printf("# Radio channel: %s\n", record.a); - break; - case Altos.AO_LOG_CALLSIGN: - out.printf("# Callsign: %s\n", record.data); - break; - case Altos.AO_LOG_ACCEL_CAL: - out.printf ("# Accel cal: %d %d\n", record.a, record.b); - break; - case Altos.AO_LOG_RADIO_CAL: - out.printf ("# Radio cal: %d\n", record.a); - break; - case Altos.AO_LOG_MANUFACTURER: - out.printf ("# Manufacturer: %s\n", record.data); - break; - case Altos.AO_LOG_PRODUCT: - out.printf ("# Product: %s\n", record.data); - break; - case Altos.AO_LOG_SERIAL_NUMBER: - out.printf ("# Serial number: %d\n", record.a); - break; - case Altos.AO_LOG_SOFTWARE_VERSION: - out.printf ("# Software version: %s\n", record.data); - break; - } - } - } - - /* - * 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 & Altos.AO_GPS_NUM_SAT_MASK) >> Altos.AO_GPS_NUM_SAT_SHIFT < 4) - flags = (flags & ~Altos.AO_GPS_NUM_SAT_MASK) | (4 << Altos.AO_GPS_NUM_SAT_SHIFT); - flags |= Altos.AO_GPS_RUNNING; - flags |= Altos.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); - } - - /* - * 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 last_gps_time = null; - - int index = 0; - int prev_tick = 0; - boolean prev_tick_valid = false; - boolean missing_time = false; - - try { - for (;;) { - String line = AltosRecord.gets(input); - if (line == null) - break; - AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick, prev_tick_valid); - if (record == null) - break; - if (record.cmd == Altos.AO_LOG_INVALID) - continue; - prev_tick = record.tick; - if (record.cmd < Altos.AO_LOG_CONFIG_VERSION) - prev_tick_valid = true; - if (record.cmd == Altos.AO_LOG_FLIGHT) { - flight_record = record; - continue; - } - - /* 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 == Altos.AO_LOG_GPS_DATE) { - gps_date_record = record; - continue; - } - - /* go back and fix up any missing time values */ - if (record.cmd == Altos.AO_LOG_GPS_TIME) { - last_gps_time = record; - if (missing_time) { - Iterator iterator = records.iterator(); - while (iterator.hasNext()) { - AltosOrderedRecord old = iterator.next(); - if (old.cmd == Altos.AO_LOG_GPS_TIME && - old.a == -1 && old.b == -1) - { - update_time(record, old); - } - } - missing_time = false; - } - } - - if (record.cmd == Altos.AO_LOG_GPS_LAT) { - if (last_gps_time == null || last_gps_time.tick != record.tick) { - AltosOrderedRecord add_gps_time = new AltosOrderedRecord(Altos.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; - - records.add(add_gps_time); - record.index = index++; - } - } - records.add(record); - - /* Bail after reading the 'landed' record; we're all done */ - if (record.cmd == Altos.AO_LOG_STATE && - record.a == Altos.ao_flight_landed) - break; - } - } catch (IOException io) { - } catch (ParseException pe) { - } - try { - input.close(); - } catch (IOException ie) { - } - } -} diff --git a/ao-tools/altosui/AltosEepromMonitor.java b/ao-tools/altosui/AltosEepromMonitor.java deleted file mode 100644 index 7ff00ead..00000000 --- a/ao-tools/altosui/AltosEepromMonitor.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosEepromMonitor extends JDialog { - - Container pane; - Box box; - JLabel serial_label; - JLabel flight_label; - JLabel file_label; - JLabel serial_value; - JLabel flight_value; - JLabel file_value; - JButton cancel; - JProgressBar pbar; - int min_state, max_state; - - public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) { - super (owner, "Download Flight Data", false); - - GridBagConstraints c; - Insets il = new Insets(4,4,4,4); - Insets ir = new Insets(4,4,4,4); - - pane = getContentPane(); - pane.setLayout(new GridBagLayout()); - - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 0; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - serial_label = new JLabel("Serial:"); - pane.add(serial_label, c); - - c = new GridBagConstraints(); - c.gridx = 1; c.gridy = 0; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - serial_value = new JLabel(""); - pane.add(serial_value, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.gridx = 0; c.gridy = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - flight_label = new JLabel("Flight:"); - pane.add(flight_label, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.gridx = 1; c.gridy = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - flight_value = new JLabel(""); - pane.add(flight_value, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.gridx = 0; c.gridy = 2; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - file_label = new JLabel("File:"); - pane.add(file_label, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.gridx = 1; c.gridy = 2; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - file_value = new JLabel(""); - pane.add(file_value, c); - - min_state = in_min_state; - max_state = in_max_state; - pbar = new JProgressBar(); - pbar.setMinimum(0); - pbar.setMaximum((max_state - min_state) * 100); - pbar.setValue(0); - pbar.setString("startup"); - pbar.setStringPainted(true); - pbar.setPreferredSize(new Dimension(600, 20)); - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 0; c.gridy = 3; - c.gridwidth = GridBagConstraints.REMAINDER; - Insets ib = new Insets(4,4,4,4); - c.insets = ib; - pane.add(pbar, c); - - - cancel = new JButton("Cancel"); - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 0; c.gridy = 4; - c.gridwidth = GridBagConstraints.REMAINDER; - Insets ic = new Insets(4,4,4,4); - c.insets = ic; - pane.add(cancel, c); - - pack(); - setLocationRelativeTo(owner); - setVisible(true); - } - - public void addActionListener (ActionListener l) { - cancel.addActionListener(l); - } - - public void set_value(String state_name, int in_state, int in_block) { - int block = in_block; - int state = in_state; - - if (block > 100) - block = 100; - if (state < min_state) state = min_state; - if (state >= max_state) state = max_state - 1; - state -= min_state; - - int pos = state * 100 + block; - - pbar.setString(state_name); - pbar.setValue(pos); - } - - public void set_serial(int serial) { - serial_value.setText(String.format("%d", serial)); - } - - public void set_flight(int flight) { - flight_value.setText(String.format("%d", flight)); - } - - public void set_file(String file) { - file_value.setText(String.format("%s", file)); - } - - public void done() { - setVisible(false); - dispose(); - } -} diff --git a/ao-tools/altosui/AltosEepromRecord.java b/ao-tools/altosui/AltosEepromRecord.java deleted file mode 100644 index 5a673817..00000000 --- a/ao-tools/altosui/AltosEepromRecord.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosEepromRecord { - public int cmd; - public int tick; - public int a; - public int b; - public String data; - public boolean tick_valid; - - public AltosEepromRecord (String line) { - tick_valid = false; - tick = 0; - a = 0; - b = 0; - data = null; - if (line == null) { - cmd = Altos.AO_LOG_INVALID; - data = ""; - } else { - try { - String[] tokens = line.split("\\s+"); - - if (tokens[0].length() == 1) { - if (tokens.length != 4) { - cmd = Altos.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 = Altos.AO_LOG_CONFIG_VERSION; - data = tokens[2]; - } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { - cmd = Altos.AO_LOG_MAIN_DEPLOY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { - cmd = Altos.AO_LOG_APOGEE_DELAY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { - cmd = Altos.AO_LOG_RADIO_CHANNEL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Callsign:")) { - cmd = Altos.AO_LOG_CALLSIGN; - data = tokens[1].replaceAll("\"",""); - } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { - cmd = Altos.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 = Altos.AO_LOG_RADIO_CAL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("manufacturer")) { - cmd = Altos.AO_LOG_MANUFACTURER; - data = tokens[1]; - } else if (tokens[0].equals("product")) { - cmd = Altos.AO_LOG_PRODUCT; - data = tokens[1]; - } else if (tokens[0].equals("serial-number")) { - cmd = Altos.AO_LOG_SERIAL_NUMBER; - a = Integer.parseInt(tokens[1]); - } else if (tokens[0].equals("software-version")) { - cmd = Altos.AO_LOG_SOFTWARE_VERSION; - data = tokens[1]; - } else { - cmd = Altos.AO_LOG_INVALID; - data = line; - } - } catch (NumberFormatException ne) { - cmd = Altos.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/ao-tools/altosui/AltosFile.java b/ao-tools/altosui/AltosFile.java deleted file mode 100644 index 06360572..00000000 --- a/ao-tools/altosui/AltosFile.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.io.File; -import java.util.*; - -class AltosFile extends File { - - public AltosFile(int year, int month, int day, int serial, int flight, String extension) { - super (AltosPreferences.logdir(), - String.format("%04d-%02d-%02d-serial-%03d-flight-%03d.%s", - year, month, day, serial, flight, extension)); - } - - public AltosFile(int serial, int flight, String extension) { - this(Calendar.getInstance().get(Calendar.YEAR), - Calendar.getInstance().get(Calendar.MONTH) + 1, - Calendar.getInstance().get(Calendar.DAY_OF_MONTH), - serial, - flight, - extension); - } - - public AltosFile(AltosTelemetry telem) { - this(telem.serial, telem.flight, "telem"); - } -} diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java deleted file mode 100644 index 3af25c23..00000000 --- a/ao-tools/altosui/AltosFlash.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosFlash { - File file; - FileInputStream input; - AltosHexfile image; - JFrame frame; - AltosDevice debug_dongle; - AltosDebug debug; - AltosRomconfig rom_config; - ActionListener listener; - boolean aborted; - - static final byte MOV_direct_data = (byte) 0x75; - static final byte MOV_DPTR_data16 = (byte) 0x90; - static final byte MOV_A_data = (byte) 0x74; - static final byte MOVX_atDPTR_A = (byte) 0xf0; - static final byte MOVX_A_atDPTR = (byte) 0xe0; - static final byte INC_DPTR = (byte) 0xa3; - static final byte TRAP = (byte) 0xa5; - - static final byte JB = (byte) 0x20; - - static final byte MOV_A_direct = (byte) 0xe5; - static final byte MOV_direct1_direct2 = (byte) 0x85; - static final byte MOV_direct_A = (byte) 0xf5; - static final byte MOV_R0_data = (byte) (0x78 | 0); - static final byte MOV_R1_data = (byte) (0x78 | 1); - static final byte MOV_R2_data = (byte) (0x78 | 2); - static final byte MOV_R3_data = (byte) (0x78 | 3); - static final byte MOV_R4_data = (byte) (0x78 | 4); - static final byte MOV_R5_data = (byte) (0x78 | 5); - static final byte MOV_R6_data = (byte) (0x78 | 6); - static final byte MOV_R7_data = (byte) (0x78 | 7); - static final byte DJNZ_R0_rel = (byte) (0xd8 | 0); - static final byte DJNZ_R1_rel = (byte) (0xd8 | 1); - static final byte DJNZ_R2_rel = (byte) (0xd8 | 2); - static final byte DJNZ_R3_rel = (byte) (0xd8 | 3); - static final byte DJNZ_R4_rel = (byte) (0xd8 | 4); - static final byte DJNZ_R5_rel = (byte) (0xd8 | 5); - static final byte DJNZ_R6_rel = (byte) (0xd8 | 6); - static final byte DJNZ_R7_rel = (byte) (0xd8 | 7); - - static final byte P1DIR = (byte) 0xFE; - static final byte P1 = (byte) 0x90; - - /* flash controller */ - static final byte FWT = (byte) 0xAB; - static final byte FADDRL = (byte) 0xAC; - static final byte FADDRH = (byte) 0xAD; - static final byte FCTL = (byte) 0xAE; - static final byte FCTL_BUSY = (byte) 0x80; - static final byte FCTL_BUSY_BIT = (byte) 7; - static final byte FCTL_SWBSY = (byte) 0x40; - static final byte FCTL_SWBSY_BIT = (byte) 6; - static final byte FCTL_CONTRD = (byte) 0x10; - static final byte FCTL_WRITE = (byte) 0x02; - static final byte FCTL_ERASE = (byte) 0x01; - static final byte FWDATA = (byte) 0xAF; - - static final byte ACC = (byte) 0xE0; - - /* offsets within the flash_page program */ - static final int FLASH_ADDR_HIGH = 8; - static final int FLASH_ADDR_LOW = 11; - static final int RAM_ADDR_HIGH = 13; - static final int RAM_ADDR_LOW = 14; - static final int FLASH_WORDS_HIGH = 16; - static final int FLASH_WORDS_LOW = 18; - static final int FLASH_TIMING = 21; - - /* sleep mode control */ - static final int SLEEP = (byte) 0xbe; - static final int SLEEP_USB_EN = (byte) 0x80; - static final int SLEEP_XOSC_STB = (byte) 0x40; - static final int SLEEP_HFRC_STB = (byte) 0x20; - static final int SLEEP_RST_MASK = (byte) 0x18; - static final int SLEEP_RST_POWERON = (byte) 0x00; - static final int SLEEP_RST_EXTERNAL = (byte) 0x10; - static final int SLEEP_RST_WATCHDOG = (byte) 0x08; - static final int SLEEP_OSC_PD = (byte) 0x04; - static final int SLEEP_MODE_MASK = (byte) 0x03; - static final int SLEEP_MODE_PM0 = (byte) 0x00; - static final int SLEEP_MODE_PM1 = (byte) 0x01; - static final int SLEEP_MODE_PM2 = (byte) 0x02; - static final int SLEEP_MODE_PM3 = (byte) 0x03; - - /* clock controller */ - static final byte CLKCON = (byte) 0xC6; - static final byte CLKCON_OSC32K = (byte) 0x80; - static final byte CLKCON_OSC = (byte) 0x40; - static final byte CLKCON_TICKSPD = (byte) 0x38; - static final byte CLKCON_CLKSPD = (byte) 0x07; - - static final byte[] flash_page_proto = { - - MOV_direct_data, P1DIR, (byte) 0x02, - MOV_direct_data, P1, (byte) 0xFF, - - MOV_direct_data, FADDRH, 0, /* FLASH_ADDR_HIGH */ - - MOV_direct_data, FADDRL, 0, /* FLASH_ADDR_LOW */ - - MOV_DPTR_data16, 0, 0, /* RAM_ADDR_HIGH, RAM_ADDR_LOW */ - - MOV_R7_data, 0, /* FLASH_WORDS_HIGH */ - - MOV_R6_data, 0, /* FLASH_WORDS_LOW */ - - - MOV_direct_data, FWT, 0x20, /* FLASH_TIMING */ - - MOV_direct_data, FCTL, FCTL_ERASE, -/* eraseWaitLoop: */ - MOV_A_direct, FCTL, - JB, ACC|FCTL_BUSY_BIT, (byte) 0xfb, - - MOV_direct_data, P1, (byte) 0xfd, - - MOV_direct_data, FCTL, FCTL_WRITE, -/* writeLoop: */ - MOV_R5_data, 2, -/* writeWordLoop: */ - MOVX_A_atDPTR, - INC_DPTR, - MOV_direct_A, FWDATA, - DJNZ_R5_rel, (byte) 0xfa, /* writeWordLoop */ -/* writeWaitLoop: */ - MOV_A_direct, FCTL, - JB, ACC|FCTL_SWBSY_BIT, (byte) 0xfb, /* writeWaitLoop */ - DJNZ_R6_rel, (byte) 0xf1, /* writeLoop */ - DJNZ_R7_rel, (byte) 0xef, /* writeLoop */ - - MOV_direct_data, P1DIR, (byte) 0x00, - MOV_direct_data, P1, (byte) 0xFF, - TRAP, - }; - - public byte[] make_flash_page(int flash_addr, int ram_addr, int byte_count) { - int flash_word_addr = flash_addr >> 1; - int flash_word_count = ((byte_count + 1) >> 1); - - byte[] flash_page = new byte[flash_page_proto.length]; - for (int i = 0; i < flash_page.length; i++) - flash_page[i] = flash_page_proto[i]; - - flash_page[FLASH_ADDR_HIGH] = (byte) (flash_word_addr >> 8); - flash_page[FLASH_ADDR_LOW] = (byte) (flash_word_addr); - flash_page[RAM_ADDR_HIGH] = (byte) (ram_addr >> 8); - flash_page[RAM_ADDR_LOW] = (byte) (ram_addr); - - byte flash_words_low = (byte) (flash_word_count); - byte flash_words_high = (byte) (flash_word_count >> 8); - /* the flashing code has a minor 'bug' */ - if (flash_words_low != 0) - flash_words_high++; - - flash_page[FLASH_WORDS_HIGH] = (byte) flash_words_high; - flash_page[FLASH_WORDS_LOW] = (byte) flash_words_low; - return flash_page; - } - - static byte[] set_clkcon_fast = { - MOV_direct_data, CLKCON, 0x00 - }; - - static byte[] get_sleep = { - MOV_A_direct, SLEEP - }; - - public void clock_init() throws IOException, InterruptedException { - debug.debug_instr(set_clkcon_fast); - - byte status; - for (int times = 0; times < 20; times++) { - Thread.sleep(1); - status = debug.debug_instr(get_sleep); - if ((status & SLEEP_XOSC_STB) != 0) - return; - } - throw new IOException("Failed to initialize target clock"); - } - - void action(String s, int percent) { - if (listener != null && !aborted) - listener.actionPerformed(new ActionEvent(this, - percent, - s)); - } - - void action(int part, int total) { - int percent = 100 * part / total; - action(String.format("%d/%d (%d%%)", - part, total, percent), - percent); - } - - void run(int pc) throws IOException, InterruptedException { - debug.set_pc(pc); - int set_pc = debug.get_pc(); - if (pc != set_pc) - throw new IOException("Failed to set target program counter"); - debug.resume(); - - for (int times = 0; times < 20; times++) { - byte status = debug.read_status(); - if ((status & AltosDebug.STATUS_CPU_HALTED) != 0) - return; - } - - throw new IOException("Failed to execute program on target"); - } - - public void flash() throws IOException, FileNotFoundException, InterruptedException { - if (!check_rom_config()) - throw new IOException("Invalid rom config settings"); - if (image.address + image.data.length > 0x8000) - throw new IOException(String.format("Flash image too long %d", - image.address + - image.data.length)); - if ((image.address & 0x3ff) != 0) - throw new IOException(String.format("Flash image must start on page boundary (is 0x%x)", - image.address)); - int ram_address = 0xf000; - int flash_prog = 0xf400; - - /* - * Store desired config values into image - */ - rom_config.write(image); - /* - * Bring up the clock - */ - clock_init(); - - int remain = image.data.length; - int 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 > 0x400) - this_time = 0x400; - - /* write the data */ - debug.write_memory(ram_address, image.data, - image_start, this_time); - - /* write the flash program */ - byte[] flash_page = make_flash_page(flash_addr, - ram_address, - this_time); - debug.write_memory(flash_prog, flash_page); - - run(flash_prog); - - byte[] check = debug.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])); - remain -= this_time; - flash_addr += this_time; - image_start += this_time; - - action(image.data.length - remain, image.data.length); - } - if (!aborted) { - action("done", 100); - debug.set_pc(image.address); - debug.resume(); - } - debug.close(); - } - - public void abort() { - aborted = true; - debug.close(); - } - - public void addActionListener(ActionListener l) { - listener = l; - } - - public boolean check_rom_config() { - 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 in_file, AltosDevice in_debug_dongle) - throws IOException, FileNotFoundException, AltosSerialInUseException, InterruptedException { - file = in_file; - debug_dongle = in_debug_dongle; - debug = new AltosDebug(in_debug_dongle); - input = new FileInputStream(file); - image = new AltosHexfile(input); - if (!debug.check_connection()) { - debug.close(); - throw new IOException("Debug port not connected"); - } - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java deleted file mode 100644 index f63097ac..00000000 --- a/ao-tools/altosui/AltosFlashUI.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosFlashUI - extends JDialog - implements Runnable, ActionListener -{ - Container pane; - Box box; - JLabel serial_label; - JLabel serial_value; - JLabel file_label; - JLabel file_value; - JProgressBar pbar; - JButton cancel; - - File file; - Thread thread; - JFrame frame; - AltosDevice debug_dongle; - AltosFlash flash; - - public void actionPerformed(ActionEvent e) { - if (e.getSource() == cancel) { - abort(); - dispose(); - } else { - String cmd = e.getActionCommand(); - if (cmd.equals("done")) - ; - else if (cmd.equals("start")) { - setVisible(true); - } else { - pbar.setValue(e.getID()); - pbar.setString(cmd); - } - } - } - - public void run() { - try { - flash = new AltosFlash(file, debug_dongle); - flash.addActionListener(this); - AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); - - romconfig_ui.set(flash.romconfig()); - AltosRomconfig romconfig = romconfig_ui.showDialog(); - - if (romconfig != null && romconfig.valid()) { - flash.set_romconfig(romconfig); - serial_value.setText(String.format("%d", - flash.romconfig().serial_number)); - file_value.setText(file.toString()); - setVisible(true); - flash.flash(); - flash = null; - } - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(frame, - "Cannot open image", - file.toString(), - JOptionPane.ERROR_MESSAGE); - } catch (AltosSerialInUseException si) { - JOptionPane.showMessageDialog(frame, - String.format("Device \"%s\" already in use", - debug_dongle.toShortString()), - "Device in use", - JOptionPane.ERROR_MESSAGE); - } catch (IOException e) { - JOptionPane.showMessageDialog(frame, - e.getMessage(), - file.toString(), - JOptionPane.ERROR_MESSAGE); - } catch (InterruptedException ie) { - } finally { - abort(); - } - dispose(); - } - - public void abort() { - if (flash != null) - flash.abort(); - } - - public void build_dialog() { - GridBagConstraints c; - Insets il = new Insets(4,4,4,4); - Insets ir = new Insets(4,4,4,4); - - pane = getContentPane(); - pane.setLayout(new GridBagLayout()); - - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 0; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - serial_label = new JLabel("Serial:"); - pane.add(serial_label, c); - - c = new GridBagConstraints(); - c.gridx = 1; c.gridy = 0; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - serial_value = new JLabel(""); - pane.add(serial_value, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.gridx = 0; c.gridy = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - file_label = new JLabel("File:"); - pane.add(file_label, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.gridx = 1; c.gridy = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - file_value = new JLabel(""); - pane.add(file_value, c); - - pbar = new JProgressBar(); - pbar.setMinimum(0); - pbar.setMaximum(100); - pbar.setValue(0); - pbar.setString(""); - pbar.setStringPainted(true); - pbar.setPreferredSize(new Dimension(600, 20)); - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 0; c.gridy = 2; - c.gridwidth = GridBagConstraints.REMAINDER; - Insets ib = new Insets(4,4,4,4); - c.insets = ib; - pane.add(pbar, c); - - cancel = new JButton("Cancel"); - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 0; c.gridy = 3; - c.gridwidth = GridBagConstraints.REMAINDER; - Insets ic = new Insets(4,4,4,4); - c.insets = ic; - pane.add(cancel, c); - cancel.addActionListener(this); - pack(); - setLocationRelativeTo(frame); - } - - public AltosFlashUI(JFrame in_frame) { - super(in_frame, "Program Altusmetrum Device", false); - - frame = in_frame; - - build_dialog(); - - debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.product_any); - - if (debug_dongle == null) - return; - - JFileChooser hexfile_chooser = new JFileChooser(); - - File firmwaredir = AltosPreferences.firmwaredir(); - if (firmwaredir != null) - hexfile_chooser.setCurrentDirectory(firmwaredir); - - hexfile_chooser.setDialogTitle("Select Flash Image"); - hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx")); - int returnVal = hexfile_chooser.showOpenDialog(frame); - - if (returnVal != JFileChooser.APPROVE_OPTION) - return; - - file = hexfile_chooser.getSelectedFile(); - - if (file != null) - AltosPreferences.set_firmwaredir(file.getParentFile()); - - thread = new Thread(this); - thread.start(); - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosFlightDisplay.java b/ao-tools/altosui/AltosFlightDisplay.java deleted file mode 100644 index d18d1d1f..00000000 --- a/ao-tools/altosui/AltosFlightDisplay.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -public interface AltosFlightDisplay { - void reset(); - - void show(AltosState state, int crc_errors); -} diff --git a/ao-tools/altosui/AltosFlightInfoTableModel.java b/ao-tools/altosui/AltosFlightInfoTableModel.java deleted file mode 100644 index e23eff68..00000000 --- a/ao-tools/altosui/AltosFlightInfoTableModel.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosFlightInfoTableModel extends AbstractTableModel { - final static private String[] columnNames = {"Field", "Value"}; - - int rows; - int cols; - private String[][] data; - - public int getColumnCount() { return cols; } - public int getRowCount() { return rows; } - public String getColumnName(int col) { return columnNames[col & 1]; } - - public Object getValueAt(int row, int col) { - if (row >= rows || col >= cols) - return ""; - return data[row][col]; - } - - int[] current_row; - - public void reset() { - for (int i = 0; i < cols / 2; i++) - current_row[i] = 0; - } - - public void clear() { - reset(); - for (int c = 0; c < cols; c++) - for (int r = 0; r < rows; r++) - data[r][c] = ""; - fireTableDataChanged(); - } - - public void addRow(int col, String name, String value) { - if (current_row[col] < rows) { - data[current_row[col]][col * 2] = name; - data[current_row[col]][col * 2 + 1] = value; - } - current_row[col]++; - } - - public void finish() { - for (int c = 0; c < cols / 2; c++) - while (current_row[c] < rows) - addRow(c, "", ""); - fireTableDataChanged(); - } - - public AltosFlightInfoTableModel (int in_rows, int in_cols) { - rows = in_rows; - cols = in_cols * 2; - data = new String[rows][cols]; - current_row = new int[in_cols]; - } -} diff --git a/ao-tools/altosui/AltosFlightReader.java b/ao-tools/altosui/AltosFlightReader.java deleted file mode 100644 index 3d59de9a..00000000 --- a/ao-tools/altosui/AltosFlightReader.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.text.*; -import java.io.*; - -public class AltosFlightReader { - String name; - - int serial; - - void init() { } - - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } - - void close(boolean interrupted) { } - - void set_channel(int channel) { } - - void update(AltosState state) throws InterruptedException { } -} diff --git a/ao-tools/altosui/AltosFlightStatus.java b/ao-tools/altosui/AltosFlightStatus.java deleted file mode 100644 index 59c9e9db..00000000 --- a/ao-tools/altosui/AltosFlightStatus.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { - GridBagLayout layout; - - public class FlightValue { - JLabel label; - JTextField value; - - void show(AltosState state, int crc_errors) {} - - void reset() { - value.setText(""); - } - public FlightValue (GridBagLayout layout, int x, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.insets = new Insets(5, 5, 5, 5); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.status_font); - label.setHorizontalAlignment(SwingConstants.CENTER); - c.gridx = x; c.gridy = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(""); - value.setFont(Altos.status_font); - value.setHorizontalAlignment(SwingConstants.CENTER); - c.gridx = x; c.gridy = 1; - layout.setConstraints(value, c); - add(value); - } - } - - class Call extends FlightValue { - void show(AltosState state, int crc_errors) { - value.setText(state.data.callsign); - } - public Call (GridBagLayout layout, int x) { - super (layout, x, "Callsign"); - } - } - - Call call; - - class Serial extends FlightValue { - void show(AltosState state, int crc_errors) { - value.setText(String.format("%d", state.data.serial)); - } - public Serial (GridBagLayout layout, int x) { - super (layout, x, "Serial"); - } - } - - Serial serial; - - class Flight extends FlightValue { - void show(AltosState state, int crc_errors) { - value.setText(String.format("%d", state.data.flight)); - } - public Flight (GridBagLayout layout, int x) { - super (layout, x, "Flight"); - } - } - - Flight flight; - - class FlightState extends FlightValue { - void show(AltosState state, int crc_errors) { - value.setText(state.data.state()); - } - public FlightState (GridBagLayout layout, int x) { - super (layout, x, "State"); - } - } - - FlightState flight_state; - - class RSSI extends FlightValue { - void show(AltosState state, int crc_errors) { - value.setText(String.format("%d", state.data.rssi)); - } - public RSSI (GridBagLayout layout, int x) { - super (layout, x, "RSSI (dBm)"); - } - } - - RSSI rssi; - - public void reset () { - call.reset(); - serial.reset(); - flight.reset(); - flight_state.reset(); - rssi.reset(); - } - - public void show (AltosState state, int crc_errors) { - call.show(state, crc_errors); - serial.show(state, crc_errors); - flight.show(state, crc_errors); - flight_state.show(state, crc_errors); - rssi.show(state, crc_errors); - } - - public int height() { - Dimension d = layout.preferredLayoutSize(this); - return d.height; - } - - public AltosFlightStatus() { - layout = new GridBagLayout(); - - setLayout(layout); - - call = new Call(layout, 0); - serial = new Serial(layout, 1); - flight = new Flight(layout, 2); - flight_state = new FlightState(layout, 3); - rssi = new RSSI(layout, 4); - } -} diff --git a/ao-tools/altosui/AltosFlightStatusTableModel.java b/ao-tools/altosui/AltosFlightStatusTableModel.java deleted file mode 100644 index 4c24b6ac..00000000 --- a/ao-tools/altosui/AltosFlightStatusTableModel.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosFlightStatusTableModel extends AbstractTableModel { - private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; - private Object[] data = { 0, "idle", 0, 0 }; - - public int getColumnCount() { return columnNames.length; } - public int getRowCount() { return 2; } - public Object getValueAt(int row, int col) { - if (row == 0) - return columnNames[col]; - return data[col]; - } - - public void setValueAt(Object value, int col) { - data[col] = value; - fireTableCellUpdated(1, col); - } - - public void setValueAt(Object value, int row, int col) { - setValueAt(value, col); - } - - public void set(AltosState state) { - setValueAt(String.format("%1.0f", state.height), 0); - setValueAt(state.data.state(), 1); - setValueAt(state.data.rssi, 2); - double speed = state.baro_speed; - if (state.ascent) - speed = state.speed; - setValueAt(String.format("%1.0f", speed), 3); - } -} diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java deleted file mode 100644 index 24d25bd7..00000000 --- a/ao-tools/altosui/AltosFlightUI.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosFlightUI extends JFrame implements AltosFlightDisplay { - String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; - Object[][] statusData = { { "0", "pad", "-50", "0" } }; - - AltosVoice voice; - AltosFlightReader reader; - AltosDisplayThread thread; - - JTabbedPane pane; - - AltosPad pad; - AltosAscent ascent; - AltosDescent descent; - AltosLanded landed; - AltosSiteMap sitemap; - - private AltosFlightStatus flightStatus; - private AltosInfoTable flightInfo; - - static final int tab_pad = 1; - static final int tab_ascent = 2; - static final int tab_descent = 3; - static final int tab_landed = 4; - - int cur_tab = 0; - - boolean exit_on_close = false; - - int which_tab(AltosState state) { - if (state.state < Altos.ao_flight_boost) - return tab_pad; - if (state.state <= Altos.ao_flight_coast) - return tab_ascent; - if (state.state <= Altos.ao_flight_main) - return tab_descent; - return tab_landed; - } - - void stop_display() { - if (thread != null && thread.isAlive()) { - thread.interrupt(); - try { - thread.join(); - } catch (InterruptedException ie) {} - } - thread = null; - } - - void disconnect() { - stop_display(); - } - - public void reset() { - pad.reset(); - ascent.reset(); - descent.reset(); - landed.reset(); - flightInfo.clear(); - sitemap.reset(); - } - - public void show(AltosState state, int crc_errors) { - int tab = which_tab(state); - pad.show(state, crc_errors); - ascent.show(state, crc_errors); - descent.show(state, crc_errors); - landed.show(state, crc_errors); - if (tab != cur_tab) { - switch (tab) { - case tab_pad: - pane.setSelectedComponent(pad); - break; - case tab_ascent: - pane.setSelectedComponent(ascent); - break; - case tab_descent: - pane.setSelectedComponent(descent); - break; - case tab_landed: - pane.setSelectedComponent(landed); - } - cur_tab = tab; - } - flightStatus.show(state, crc_errors); - flightInfo.show(state, crc_errors); - sitemap.show(state, crc_errors); - } - - public void set_exit_on_close() { - exit_on_close = true; - } - - Container bag; - JComboBox channels; - - public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { - AltosPreferences.init(this); - - voice = in_voice; - reader = in_reader; - - bag = getContentPane(); - bag.setLayout(new GridBagLayout()); - - GridBagConstraints c = new GridBagConstraints(); - - java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg"); - if (imgURL != null) - setIconImage(new ImageIcon(imgURL).getImage()); - - setTitle(String.format("AltOS %s", reader.name)); - - /* Stick channel selector at top of table for telemetry monitoring */ - if (serial >= 0) { - // Channel menu - channels = new AltosChannelMenu(AltosPreferences.channel(serial)); - channels.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - int channel = channels.getSelectedIndex(); - reader.set_channel(channel); - } - }); - c.gridx = 0; - c.gridy = 0; - c.anchor = GridBagConstraints.WEST; - bag.add (channels, c); - } - - /* Flight status is always visible */ - flightStatus = new AltosFlightStatus(); - c.gridx = 0; - c.gridy = 1; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - bag.add(flightStatus, c); - - /* The rest of the window uses a tabbed pane to - * show one of the alternate data views - */ - pane = new JTabbedPane(); - - pad = new AltosPad(); - pane.add("Launch Pad", pad); - - ascent = new AltosAscent(); - pane.add("Ascent", ascent); - - descent = new AltosDescent(); - pane.add("Descent", descent); - - landed = new AltosLanded(); - pane.add("Landed", landed); - - flightInfo = new AltosInfoTable(); - pane.add("Table", new JScrollPane(flightInfo)); - - sitemap = new AltosSiteMap(); - pane.add("Site Map", sitemap); - - /* Make the tabbed pane use the rest of the window space */ - c.gridx = 0; - c.gridy = 2; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - c.weighty = 1; - bag.add(pane, c); - - setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - disconnect(); - setVisible(false); - dispose(); - if (exit_on_close) - System.exit(0); - } - }); - - pack(); - setVisible(true); - - thread = new AltosDisplayThread(this, voice, this, reader); - - thread.start(); - } - - public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) { - this(in_voice, in_reader, -1); - } -} diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java deleted file mode 100644 index 83821842..00000000 --- a/ao-tools/altosui/AltosGPS.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.text.*; - -public class AltosGPS { - public class AltosGPSSat { - int svid; - int c_n0; - } - - int nsat; - boolean locked; - boolean connected; - boolean date_valid; - double lat; /* degrees (+N -S) */ - double lon; /* degrees (+E -W) */ - int alt; /* m */ - int year; - int month; - int day; - int hour; - int minute; - int second; - - int gps_extended; /* has extra data */ - double ground_speed; /* m/s */ - int course; /* degrees */ - double climb_rate; /* m/s */ - double hdop; /* unitless? */ - int h_error; /* m */ - int v_error; /* m */ - - AltosGPSSat[] cc_gps_sat; /* tracking data */ - - void ParseGPSDate(String date) throws ParseException { - String[] ymd = date.split("-"); - if (ymd.length != 3) - throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); - year = AltosParse.parse_int(ymd[0]); - month = AltosParse.parse_int(ymd[1]); - day = AltosParse.parse_int(ymd[2]); - } - - void ParseGPSTime(String time) throws ParseException { - String[] hms = time.split(":"); - if (hms.length != 3) - throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); - hour = AltosParse.parse_int(hms[0]); - minute = AltosParse.parse_int(hms[1]); - second = AltosParse.parse_int(hms[2]); - } - - void ClearGPSTime() { - year = month = day = 0; - hour = minute = second = 0; - } - - public AltosGPS(String[] words, int i, int version) throws ParseException { - AltosParse.word(words[i++], "GPS"); - nsat = AltosParse.parse_int(words[i++]); - AltosParse.word(words[i++], "sat"); - - connected = false; - locked = false; - lat = lon = 0; - alt = 0; - ClearGPSTime(); - if ((words[i]).equals("unlocked")) { - connected = true; - i++; - } else if ((words[i]).equals("not-connected")) { - i++; - } else if (words.length >= 40) { - locked = true; - connected = true; - - if (version > 1) - ParseGPSDate(words[i++]); - else - year = month = day = 0; - ParseGPSTime(words[i++]); - lat = AltosParse.parse_coord(words[i++]); - lon = AltosParse.parse_coord(words[i++]); - alt = AltosParse.parse_int(words[i++]); - if (version > 1 || (i < words.length && !words[i].equals("SAT"))) { - ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)")); - course = AltosParse.parse_int(words[i++]); - climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)")); - hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)")); - h_error = AltosParse.parse_int(words[i++]); - v_error = AltosParse.parse_int(words[i++]); - } - } else { - i++; - } - if (i < words.length) { - AltosParse.word(words[i++], "SAT"); - int tracking_channels = 0; - if (words[i].equals("not-connected")) - tracking_channels = 0; - else - tracking_channels = AltosParse.parse_int(words[i]); - i++; - cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels]; - for (int chan = 0; chan < tracking_channels; chan++) { - cc_gps_sat[chan] = new AltosGPS.AltosGPSSat(); - cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]); - /* Older versions included SiRF status bits */ - if (version < 2) - i++; - cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]); - } - } else - cc_gps_sat = new AltosGPS.AltosGPSSat[0]; - } - - public void set_latitude(int in_lat) { - lat = in_lat / 10.0e7; - } - - public void set_longitude(int in_lon) { - lon = in_lon / 10.0e7; - } - - public void set_time(int hour, int minute, int second) { - hour = hour; - minute = minute; - second = second; - } - - public void set_date(int year, int month, int day) { - year = year; - month = month; - day = day; - } - - public void set_flags(int flags) { - flags = flags; - } - - public void set_altitude(int altitude) { - altitude = altitude; - } - - public void add_sat(int svid, int c_n0) { - if (cc_gps_sat == null) { - cc_gps_sat = new AltosGPS.AltosGPSSat[1]; - } else { - AltosGPSSat[] new_gps_sat = new AltosGPS.AltosGPSSat[cc_gps_sat.length + 1]; - for (int i = 0; i < cc_gps_sat.length; i++) - new_gps_sat[i] = cc_gps_sat[i]; - cc_gps_sat = new_gps_sat; - } - AltosGPS.AltosGPSSat sat = new AltosGPS.AltosGPSSat(); - sat.svid = svid; - sat.c_n0 = c_n0; - cc_gps_sat[cc_gps_sat.length - 1] = sat; - } - - public AltosGPS() { - ClearGPSTime(); - cc_gps_sat = null; - } - - public AltosGPS(AltosGPS old) { - nsat = old.nsat; - locked = old.locked; - connected = old.connected; - date_valid = old.date_valid; - lat = old.lat; /* degrees (+N -S) */ - lon = old.lon; /* degrees (+E -W) */ - alt = old.alt; /* m */ - year = old.year; - month = old.month; - day = old.day; - hour = old.hour; - minute = old.minute; - second = old.second; - - gps_extended = old.gps_extended; /* has extra data */ - ground_speed = old.ground_speed; /* m/s */ - course = old.course; /* degrees */ - climb_rate = old.climb_rate; /* m/s */ - hdop = old.hdop; /* unitless? */ - h_error = old.h_error; /* m */ - v_error = old.v_error; /* m */ - - if (old.cc_gps_sat != null) { - cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length]; - for (int i = 0; i < old.cc_gps_sat.length; i++) { - cc_gps_sat[i] = new AltosGPSSat(); - cc_gps_sat[i].svid = old.cc_gps_sat[i].svid; - cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0; - } - } - } -} diff --git a/ao-tools/altosui/AltosGraph.java b/ao-tools/altosui/AltosGraph.java deleted file mode 100644 index 58c27979..00000000 --- a/ao-tools/altosui/AltosGraph.java +++ /dev/null @@ -1,25 +0,0 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later - -package altosui; - -import java.io.*; - -import org.jfree.chart.JFreeChart; -import org.jfree.chart.ChartUtilities; - -abstract class AltosGraph { - public String filename; - public abstract void addData(AltosDataPoint d); - public abstract JFreeChart createChart(); - public void toPNG() throws java.io.IOException { toPNG(300, 500); } - public void toPNG(int width, int height) - throws java.io.IOException - { - File pngout = new File(filename); - JFreeChart chart = createChart(); - ChartUtilities.saveChartAsPNG(pngout, chart, width, height); - System.out.println("Created " + filename); - } -} diff --git a/ao-tools/altosui/AltosGraphTime.java b/ao-tools/altosui/AltosGraphTime.java deleted file mode 100644 index a5451280..00000000 --- a/ao-tools/altosui/AltosGraphTime.java +++ /dev/null @@ -1,233 +0,0 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later - -package altosui; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.HashMap; - -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.AxisLocation; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.labels.StandardXYToolTipGenerator; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.plot.ValueMarker; -import org.jfree.chart.renderer.xy.StandardXYItemRenderer; -import org.jfree.chart.renderer.xy.XYItemRenderer; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; -import org.jfree.ui.RectangleAnchor; -import org.jfree.ui.TextAnchor; - -class AltosGraphTime extends AltosGraph { - static interface Element { - void attachGraph(AltosGraphTime g); - void gotTimeData(double time, AltosDataPoint d); - void addToPlot(AltosGraphTime g, XYPlot plot); - } - - static class TimeAxis implements Element { - private int axis; - private Color color; - private String label; - private AxisLocation locn; - private double min_y = Double.NaN; - - public TimeAxis(int axis, String label, Color color, AxisLocation locn) - { - this.axis = axis; - this.color = color; - this.label = label; - this.locn = locn; - } - - public void setLowerBound(double min_y) { - this.min_y = min_y; - } - - public void attachGraph(AltosGraphTime g) { return; } - public void gotTimeData(double time, AltosDataPoint d) { return; } - - public void addToPlot(AltosGraphTime g, XYPlot plot) { - NumberAxis numAxis = new NumberAxis(label); - if (!Double.isNaN(min_y)) - numAxis.setLowerBound(min_y); - plot.setRangeAxis(axis, numAxis); - plot.setRangeAxisLocation(axis, locn); - numAxis.setLabelPaint(color); - numAxis.setTickLabelPaint(color); - numAxis.setAutoRangeIncludesZero(false); - } - } - - abstract static class TimeSeries implements Element { - protected XYSeries series; - private String axisName; - private Color color; - - public TimeSeries(String axisName, String label, Color color) { - this.series = new XYSeries(label); - this.axisName = axisName; - this.color = color; - } - - public void attachGraph(AltosGraphTime g) { - g.setAxis(this, axisName, color); - } - abstract public void gotTimeData(double time, AltosDataPoint d); - - public void addToPlot(AltosGraphTime g, XYPlot plot) { - XYSeriesCollection dataset = new XYSeriesCollection(); - dataset.addSeries(this.series); - - XYItemRenderer renderer = new StandardXYItemRenderer(); - renderer.setSeriesPaint(0, color); - - int dataNum = g.getDataNum(this); - int axisNum = g.getAxisNum(this); - - plot.setDataset(dataNum, dataset); - plot.mapDatasetToRangeAxis(dataNum, axisNum); - plot.setRenderer(dataNum, renderer); - } - } - - static class StateMarker implements Element { - private double val = Double.NaN; - private String name; - private int state; - - StateMarker(int state, String name) { - this.state = state; - this.name = name; - } - - public void attachGraph(AltosGraphTime g) { return; } - public void gotTimeData(double time, AltosDataPoint d) { - if (Double.isNaN(val) || time < val) { - if (d.state() == state) { - val = time; - } - } - } - - public void addToPlot(AltosGraphTime g, XYPlot plot) { - if (Double.isNaN(val)) - return; - - ValueMarker m = new ValueMarker(val); - m.setLabel(name); - m.setLabelAnchor(RectangleAnchor.TOP_RIGHT); - m.setLabelTextAnchor(TextAnchor.TOP_LEFT); - plot.addDomainMarker(m); - } - } - - private String callsign = null; - private Integer serial = null; - private Integer flight = null; - - private String title; - private ArrayList elements; - private HashMap axes; - private HashMap datasets; - private ArrayList datasetAxis; - - public AltosGraphTime(String title) { - this.filename = title.toLowerCase().replaceAll("[^a-z0-9]","_")+".png"; - this.title = title; - this.elements = new ArrayList(); - this.axes = new HashMap(); - this.datasets = new HashMap(); - this.datasetAxis = new ArrayList(); - } - - public AltosGraphTime addElement(Element e) { - e.attachGraph(this); - elements.add(e); - return this; - } - - public void setAxis(Element ds, String axisName, Color color) { - Integer axisNum = axes.get(axisName); - int dsNum = datasetAxis.size(); - if (axisNum == null) { - axisNum = newAxis(axisName, color); - } - datasets.put(ds, dsNum); - datasetAxis.add(axisNum); - } - - public int getAxisNum(Element ds) { - return datasetAxis.get( datasets.get(ds) ).intValue(); - } - public int getDataNum(Element ds) { - return datasets.get(ds).intValue(); - } - - private Integer newAxis(String name, Color color) { - int cnt = axes.size(); - AxisLocation locn = AxisLocation.BOTTOM_OR_LEFT; - if (cnt > 0) { - locn = AxisLocation.TOP_OR_RIGHT; - } - Integer res = new Integer(cnt); - axes.put(name, res); - this.addElement(new TimeAxis(cnt, name, color, locn)); - return res; - } - - public void addData(AltosDataPoint d) { - double time = d.time(); - for (Element e : elements) { - e.gotTimeData(time, d); - } - if (callsign == null) callsign = d.callsign(); - if (serial == null) serial = new Integer(d.serial()); - if (flight == null) flight = new Integer(d.flight()); - } - - public JFreeChart createChart() { - NumberAxis xAxis = new NumberAxis("Time (s)"); - xAxis.setAutoRangeIncludesZero(false); - XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); - XYPlot plot = new XYPlot(); - plot.setDomainAxis(xAxis); - plot.setRenderer(renderer); - plot.setOrientation(PlotOrientation.VERTICAL); - - if (serial != null && flight != null) { - title = serial + "/" + flight + ": " + title; - } - if (callsign != null) { - title = callsign + " - " + title; - } - - renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); - JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, - plot, true); - ChartUtilities.applyCurrentTheme(chart); - - plot.setDomainPannable(true); - plot.setRangePannable(true); - - for (Element e : elements) { - e.addToPlot(this, plot); - } - - return chart; - } - - public void toPNG() throws java.io.IOException { - if (axes.size() > 1) { - toPNG(800, 500); - } else { - toPNG(300, 500); - } - } -} diff --git a/ao-tools/altosui/AltosGraphUI.java b/ao-tools/altosui/AltosGraphUI.java deleted file mode 100644 index cd158651..00000000 --- a/ao-tools/altosui/AltosGraphUI.java +++ /dev/null @@ -1,274 +0,0 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later - -package altosui; - -import java.io.*; -import java.util.ArrayList; - -import javax.swing.JFrame; -import java.awt.Color; - -import org.jfree.chart.ChartPanel; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.AxisLocation; -import org.jfree.ui.ApplicationFrame; -import org.jfree.ui.RefineryUtilities; - -public class AltosGraphUI extends JFrame -{ - static final private Color red = new Color(194,31,31); - static final private Color green = new Color(31,194,31); - static final private Color blue = new Color(31,31,194); - static final private Color black = new Color(31,31,31); - - static private class OverallGraphs { - AltosGraphTime.Element height = - new AltosGraphTime.TimeSeries("Height (m)", "Height (AGL)", red) { - public void gotTimeData(double time, AltosDataPoint d) { - series.add(time, d.height()); - } - }; - - AltosGraphTime.Element speed = - new AltosGraphTime.TimeSeries("Speed (m/s)", "Vertical Speed", green) { - public void gotTimeData(double time, AltosDataPoint d) { - if (d.state() < Altos.ao_flight_drogue) { - series.add(time, d.accel_speed()); - } else { - series.add(time, d.baro_speed()); - } - } - }; - - AltosGraphTime.Element acceleration = - new AltosGraphTime.TimeSeries("Acceleration (m/s\u00B2)", - "Axial Acceleration", blue) - { - public void gotTimeData(double time, AltosDataPoint d) { - series.add(time, d.acceleration()); - } - }; - - AltosGraphTime.Element temperature = - new AltosGraphTime.TimeSeries("Temperature (\u00B0C)", - "Board temperature", red) - { - public void gotTimeData(double time, AltosDataPoint d) { - series.add(time, d.temperature()); - } - }; - - AltosGraphTime.Element drogue_voltage = - new AltosGraphTime.TimeSeries("Voltage (V)", "Drogue Continuity", blue) - { - public void gotTimeData(double time, AltosDataPoint d) { - series.add(time, d.drogue_voltage()); - } - }; - - AltosGraphTime.Element main_voltage = - new AltosGraphTime.TimeSeries("Voltage (V)", "Main Continuity", green) - { - public void gotTimeData(double time, AltosDataPoint d) { - series.add(time, d.main_voltage()); - } - }; - - AltosGraphTime.Element e_pad = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad"); - AltosGraphTime.Element e_boost = new AltosGraphTime.StateMarker(Altos.ao_flight_boost, "Boost"); - AltosGraphTime.Element e_fast = new AltosGraphTime.StateMarker(Altos.ao_flight_fast, "Fast"); - AltosGraphTime.Element e_coast = new AltosGraphTime.StateMarker(Altos.ao_flight_coast, "Coast"); - AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(Altos.ao_flight_drogue, "Drogue"); - AltosGraphTime.Element e_main = new AltosGraphTime.StateMarker(Altos.ao_flight_main, "Main"); - AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(Altos.ao_flight_landed, "Landed"); - - protected AltosGraphTime myAltosGraphTime(String suffix) { - return (new AltosGraphTime("Overall " + suffix)) - .addElement(e_boost) - .addElement(e_drogue) - .addElement(e_main) - .addElement(e_landed); - } - - public ArrayList graphs() { - ArrayList graphs = new ArrayList(); - - graphs.add( myAltosGraphTime("Summary") - .addElement(height) - .addElement(speed) - .addElement(acceleration) ); - - graphs.add( myAltosGraphTime("Altitude") - .addElement(height) ); - - graphs.add( myAltosGraphTime("Speed") - .addElement(speed) ); - - graphs.add( myAltosGraphTime("Acceleration") - .addElement(acceleration) ); - - graphs.add( myAltosGraphTime("Temperature") - .addElement(temperature) ); - - graphs.add( myAltosGraphTime("Continuity") - .addElement(drogue_voltage) - .addElement(main_voltage) ); - - return graphs; - } - } - - static private class AscentGraphs extends OverallGraphs { - protected AltosGraphTime myAltosGraphTime(String suffix) { - return (new AltosGraphTime("Ascent " + suffix) { - public void addData(AltosDataPoint d) { - int state = d.state(); - if (Altos.ao_flight_boost <= state && state <= Altos.ao_flight_coast) { - super.addData(d); - } - } - }).addElement(e_boost) - .addElement(e_fast) - .addElement(e_coast); - } - } - - static private class DescentGraphs extends OverallGraphs { - protected AltosGraphTime myAltosGraphTime(String suffix) { - return (new AltosGraphTime("Descent " + suffix) { - public void addData(AltosDataPoint d) { - int state = d.state(); - if (Altos.ao_flight_drogue <= state && state <= Altos.ao_flight_main) { - super.addData(d); - } - } - }).addElement(e_drogue) - .addElement(e_main); - // ((XYGraph)graph[8]).ymin = new Double(-50); - } - } - - public AltosGraphUI(AltosRecordIterable records) { - super("Altos Graph"); - - Iterable reader = new AltosDataPointReader (records); - if (reader == null) - return; - - init(reader, 0); - } - - public AltosGraphUI(Iterable data, int which) - { - super("Altos Graph"); - init(data, which); - } - - private void init(Iterable data, int which) { - AltosGraph graph = createGraph(data, which); - - JFreeChart chart = graph.createChart(); - ChartPanel chartPanel = new ChartPanel(chart); - chartPanel.setMouseWheelEnabled(true); - chartPanel.setPreferredSize(new java.awt.Dimension(800, 500)); - setContentPane(chartPanel); - - pack(); - - RefineryUtilities.centerFrameOnScreen(this); - - setDefaultCloseOperation(DISPOSE_ON_CLOSE); - setVisible(true); - } - - private static AltosGraph createGraph(Iterable data, - int which) - { - return createGraphsWhich(data, which).get(0); - } - - private static ArrayList createGraphs( - Iterable data) - { - return createGraphsWhich(data, -1); - } - - private static ArrayList createGraphsWhich( - Iterable data, int which) - { - ArrayList graph = new ArrayList(); - graph.addAll((new OverallGraphs()).graphs()); - graph.addAll((new AscentGraphs()).graphs()); - graph.addAll((new DescentGraphs()).graphs()); - - if (which > 0) { - if (which >= graph.size()) { - which = 0; - } - AltosGraph g = graph.get(which); - graph = new ArrayList(); - graph.add(g); - } - - for (AltosDataPoint dp : data) { - for (AltosGraph g : graph) { - g.addData(dp); - } - } - - return graph; - } -} - -/* gnuplot bits... - * -300x400 - --------------------------------------------------------- -TOO HARD! :) - -"ascent-gps-accuracy.png" "Vertical error margin to apogee - GPS v Baro (m)" - 5:($7 < 6 ? $24-$11 : 1/0) -"descent-gps-accuracy.png" "Vertical error margin during descent - GPS v Baro (m)" - 5:($7 < 6 ? 1/0 : $24-$11) - -set output "overall-gps-accuracy.png" -set ylabel "distance above sea level (m)" -plot "telemetry.csv" using 5:11 with lines ti "baro altitude" axis x1y1, \ - "telemetry.csv" using 5:24 with lines ti "gps altitude" axis x1y1 - -set term png tiny size 700,700 enhanced -set xlabel "m" -set ylabel "m" -set polar -set grid polar -set rrange[*:*] -set angles degrees - -set output "overall-gps-path.png" -#:30 with yerrorlines -plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0) with lines ti "pad", \ - "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0) with lines ti "boost", \ - "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0) with lines ti "fast", \ - "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0) with lines ti "coast", \ - "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \ - "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \ - "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed" - -set output "ascent-gps-path.png" -plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0):30 with lines ti "pad", \ - "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0):20 with lines ti "boost", \ - "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0):10 with lines ti "fast", \ - "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0):5 with lines ti "coast" - -set output "descent-gps-path.png" -plot "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \ - "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \ - "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed" - - */ - - diff --git a/ao-tools/altosui/AltosGreatCircle.java b/ao-tools/altosui/AltosGreatCircle.java deleted file mode 100644 index fb1b6ab3..00000000 --- a/ao-tools/altosui/AltosGreatCircle.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.Math; - -public class AltosGreatCircle { - double distance; - double bearing; - - double sqr(double a) { return a * a; } - - static final double rad = Math.PI / 180; - static final double earth_radius = 6371.2 * 1000; /* in meters */ - - static int BEARING_LONG = 0; - static int BEARING_SHORT = 1; - static int BEARING_VOICE = 2; - String bearing_words(int length) { - String [][] bearing_string = { - { - "North", "North North East", "North East", "East North East", - "East", "East South East", "South East", "South South East", - "South", "South South West", "South West", "West South West", - "West", "West North West", "North West", "North North West" - }, { - "N", "NNE", "NE", "ENE", - "E", "ESE", "SE", "SSE", - "S", "SSW", "SW", "WSW", - "W", "WNW", "NW", "NNW" - }, { - "north", "nor nor east", "north east", "east nor east", - "east", "east sow east", "south east", "sow sow east", - "south", "sow sow west", "south west", "west sow west", - "west", "west nor west", "north west", "nor nor west " - } - }; - return bearing_string[length][(int)((bearing / 90 * 8 + 1) / 2)%16]; - } - - public AltosGreatCircle (double start_lat, double start_lon, - double end_lat, double end_lon) - { - double lat1 = rad * start_lat; - double lon1 = rad * -start_lon; - double lat2 = rad * end_lat; - double lon2 = rad * -end_lon; - - double d_lon = lon2 - lon1; - - /* From http://en.wikipedia.org/wiki/Great-circle_distance */ - double vdn = Math.sqrt(sqr(Math.cos(lat2) * Math.sin(d_lon)) + - sqr(Math.cos(lat1) * Math.sin(lat2) - - Math.sin(lat1) * Math.cos(lat2) * Math.cos(d_lon))); - double vdd = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(d_lon); - double d = Math.atan2(vdn,vdd); - double course; - - if (Math.cos(lat1) < 1e-20) { - if (lat1 > 0) - course = Math.PI; - else - course = -Math.PI; - } else { - if (d < 1e-10) - course = 0; - else - course = Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(d)) / - (Math.sin(d)*Math.cos(lat1))); - if (Math.sin(lon2-lon1) > 0) - course = 2 * Math.PI-course; - } - distance = d * earth_radius; - bearing = course * 180/Math.PI; - } - - public AltosGreatCircle(AltosGPS start, AltosGPS end) { - this(start.lat, start.lon, end.lat, end.lon); - } - - public AltosGreatCircle() { - distance = 0; - bearing = 0; - } -} diff --git a/ao-tools/altosui/AltosHexfile.java b/ao-tools/altosui/AltosHexfile.java deleted file mode 100644 index 19e35ae1..00000000 --- a/ao-tools/altosui/AltosHexfile.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.io.*; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.LinkedList; -import java.util.Iterator; -import java.util.Arrays; - -class HexFileInputStream extends PushbackInputStream { - public int line; - - public HexFileInputStream(FileInputStream o) { - super(new BufferedInputStream(o)); - line = 1; - } - - public int read() throws IOException { - int c = super.read(); - if (c == '\n') - line++; - return c; - } - - public void unread(int c) throws IOException { - if (c == '\n') - line--; - if (c != -1) - super.unread(c); - } -} - -class HexRecord implements Comparable { - public int address; - public int type; - public byte checksum; - public byte[] data; - - static final int NORMAL = 0; - static final int EOF = 1; - static final int EXTENDED_ADDRESS = 2; - - enum read_state { - marker, - length, - address, - type, - data, - checksum, - newline, - white, - done, - } - - boolean ishex(int c) { - if ('0' <= c && c <= '9') - return true; - if ('a' <= c && c <= 'f') - return true; - if ('A' <= c && c <= 'F') - return true; - return false; - } - - boolean isspace(int c) { - switch (c) { - case ' ': - case '\t': - return true; - } - return false; - } - - int fromhex(int c) { - if ('0' <= c && c <= '9') - return c - '0'; - if ('a' <= c && c <= 'f') - return c - 'a' + 10; - if ('A' <= c && c <= 'F') - return c - 'A' + 10; - return -1; - } - - public byte checksum() { - byte got = 0; - - got += data.length; - got += (address >> 8) & 0xff; - got += (address ) & 0xff; - got += type; - for (int i = 0; i < data.length; i++) - got += data[i]; - return (byte) (-got); - } - - public int compareTo(Object other) { - HexRecord o = (HexRecord) other; - return address - o.address; - } - - public String toString() { - return String.format("%04x: %02x (%d)", address, type, data.length); - } - - public HexRecord(HexFileInputStream input) throws IOException { - read_state state = read_state.marker; - int nhexbytes = 0; - int hex = 0; - int ndata = 0; - byte got_checksum; - - while (state != read_state.done) { - int c = input.read(); - if (c < 0 && state != read_state.white) - throw new IOException(String.format("%d: Unexpected EOF", input.line)); - if (c == ' ') - continue; - switch (state) { - case marker: - if (c != ':') - throw new IOException("Missing ':'"); - state = read_state.length; - nhexbytes = 2; - hex = 0; - break; - case length: - case address: - case type: - case data: - case checksum: - if(!ishex(c)) - throw new IOException(String.format("Non-hex char '%c'", c)); - hex = hex << 4 | fromhex(c); - --nhexbytes; - if (nhexbytes != 0) - break; - - switch (state) { - case length: - data = new byte[hex]; - state = read_state.address; - nhexbytes = 4; - break; - case address: - address = hex; - state = read_state.type; - nhexbytes = 2; - break; - case type: - type = hex; - if (data.length > 0) - state = read_state.data; - else - state = read_state.checksum; - nhexbytes = 2; - ndata = 0; - break; - case data: - data[ndata] = (byte) hex; - ndata++; - nhexbytes = 2; - if (ndata == data.length) - state = read_state.checksum; - break; - case checksum: - checksum = (byte) hex; - state = read_state.newline; - break; - default: - break; - } - hex = 0; - break; - case newline: - if (c != '\n' && c != '\r') - throw new IOException("Missing newline"); - state = read_state.white; - break; - case white: - if (!isspace(c)) { - input.unread(c); - state = read_state.done; - } - break; - case done: - break; - } - } - got_checksum = checksum(); - if (got_checksum != checksum) - throw new IOException(String.format("Invalid checksum (read 0x%02x computed 0x%02x)\n", - checksum, got_checksum)); - } -} - -public class AltosHexfile { - public int address; - public byte[] data; - - public byte get_byte(int a) { - return data[a - address]; - } - - public AltosHexfile(FileInputStream file) throws IOException { - HexFileInputStream input = new HexFileInputStream(file); - LinkedList record_list = new LinkedList(); - boolean done = false; - - while (!done) { - HexRecord record = new HexRecord(input); - - if (record.type == HexRecord.EOF) - done = true; - else - record_list.add(record); - } - HexRecord[] records = record_list.toArray(new HexRecord[0]); - Arrays.sort(records); - if (records.length > 0) { - int base = records[0].address; - int bound = records[records.length-1].address + - records[records.length-1].data.length; - - data = new byte[bound - base]; - address = base; - Arrays.fill(data, (byte) 0xff); - - /* Paint the records into the new array */ - for (int i = 0; i < records.length; i++) { - for (int j = 0; j < records[i].data.length; j++) - data[records[i].address - base + j] = records[i].data[j]; - } - } - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosIgnite.java b/ao-tools/altosui/AltosIgnite.java deleted file mode 100644 index 3cbd8a75..00000000 --- a/ao-tools/altosui/AltosIgnite.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.io.*; -import java.util.concurrent.*; - -public class AltosIgnite { - AltosDevice device; - AltosSerial serial; - boolean remote; - boolean serial_started; - final static int None = 0; - final static int Apogee = 1; - final static int Main = 2; - - final static int Unknown = 0; - final static int Ready = 1; - final static int Active = 2; - final static int Open = 3; - - private void start_serial() throws InterruptedException { - serial_started = true; - if (remote) { - serial.set_radio(); - serial.printf("p\nE 0\n"); - serial.flush_input(); - } - } - - private void stop_serial() throws InterruptedException { - if (!serial_started) - return; - serial_started = false; - if (serial == null) - return; - if (remote) { - serial.printf("~"); - serial.flush_output(); - } - } - - class string_ref { - String value; - - public String get() { - return value; - } - public void set(String i) { - value = i; - } - public string_ref() { - value = null; - } - } - - private boolean get_string(String line, String label, string_ref s) { - if (line.startsWith(label)) { - String quoted = line.substring(label.length()).trim(); - - if (quoted.startsWith("\"")) - quoted = quoted.substring(1); - if (quoted.endsWith("\"")) - quoted = quoted.substring(0,quoted.length()-1); - s.set(quoted); - return true; - } else { - return false; - } - } - - private int status(String status_name) { - if (status_name.equals("unknown")) - return Unknown; - if (status_name.equals("ready")) - return Ready; - if (status_name.equals("active")) - return Active; - if (status_name.equals("open")) - return Open; - return Unknown; - } - - public int status(int igniter) throws InterruptedException, TimeoutException { - int status = Unknown; - if (serial == null) - return status; - string_ref status_name = new string_ref(); - start_serial(); - serial.printf("t\n"); - for (;;) { - String line = serial.get_reply(5000); - if (line == null) - throw new TimeoutException(); - if (get_string(line, "Igniter: drogue Status: ", status_name)) - if (igniter == Apogee) - status = status(status_name.get()); - if (get_string(line, "Igniter: main Status: ", status_name)) { - if (igniter == Main) - status = status(status_name.get()); - break; - } - } - stop_serial(); - return status; - } - - public String status_string(int status) { - switch (status) { - case Unknown: return "Unknown"; - case Ready: return "Ready"; - case Active: return "Active"; - case Open: return "Open"; - default: return "Unknown"; - } - } - - public void fire(int igniter) { - if (serial == null) - return; - try { - start_serial(); - switch (igniter) { - case Main: - serial.printf("i DoIt main\n"); - break; - case Apogee: - serial.printf("i DoIt drogue\n"); - break; - } - } catch (InterruptedException ie) { - } finally { - try { - stop_serial(); - } catch (InterruptedException ie) { - } - } - } - - public void close() { - try { - stop_serial(); - } catch (InterruptedException ie) { - } - serial.close(); - serial = null; - } - - public AltosIgnite(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { - - device = in_device; - serial = new AltosSerial(device); - remote = false; - - if (!device.matchProduct(AltosDevice.product_telemetrum)) - remote = true; - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosIgniteUI.java b/ao-tools/altosui/AltosIgniteUI.java deleted file mode 100644 index d542729c..00000000 --- a/ao-tools/altosui/AltosIgniteUI.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import javax.swing.event.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; - -public class AltosIgniteUI - extends JDialog - implements ActionListener -{ - AltosDevice device; - AltosIgnite ignite; - JFrame owner; - JLabel label; - JRadioButton apogee; - JLabel apogee_status_label; - JRadioButton main; - JLabel main_status_label; - JToggleButton arm; - JButton fire; - javax.swing.Timer timer; - - int apogee_status; - int main_status; - - final static int timeout = 1 * 1000; - - int time_remaining; - boolean timer_running; - - void set_arm_text() { - if (arm.isSelected()) - arm.setText(String.format("%d", time_remaining)); - else - arm.setText("Arm"); - } - - void start_timer() { - time_remaining = 10; - set_arm_text(); - timer_running = true; - } - - void stop_timer() { - time_remaining = 0; - arm.setSelected(false); - arm.setEnabled(false); - fire.setEnabled(false); - timer_running = false; - set_arm_text(); - } - - void cancel () { - apogee.setSelected(false); - main.setSelected(false); - fire.setEnabled(false); - stop_timer(); - } - - void get_ignite_status() throws InterruptedException, TimeoutException { - apogee_status = ignite.status(AltosIgnite.Apogee); - main_status = ignite.status(AltosIgnite.Main); - } - - void set_ignite_status() throws InterruptedException, TimeoutException { - get_ignite_status(); - apogee_status_label.setText(String.format("\"%s\"", ignite.status_string(apogee_status))); - main_status_label.setText(String.format("\"%s\"", ignite.status_string(main_status))); - } - - void close() { - timer.stop(); - setVisible(false); - ignite.close(); - } - - void abort() { - close(); - JOptionPane.showMessageDialog(owner, - String.format("Connection to \"%s\" failed", - device.toShortString()), - "Connection Failed", - JOptionPane.ERROR_MESSAGE); - } - - void tick_timer() { - if (timer_running) { - --time_remaining; - if (time_remaining <= 0) - cancel(); - else - set_arm_text(); - } - try { - set_ignite_status(); - } catch (InterruptedException ie) { - abort(); - } catch (TimeoutException te) { - abort(); - } - } - - void fire() { - if (arm.isEnabled() && arm.isSelected() && time_remaining > 0) { - int igniter = AltosIgnite.None; - if (apogee.isSelected() && !main.isSelected()) - igniter = AltosIgnite.Apogee; - else if (main.isSelected() && !apogee.isSelected()) - igniter = AltosIgnite.Main; - ignite.fire(igniter); - cancel(); - } - } - - public void actionPerformed(ActionEvent e) { - String cmd = e.getActionCommand(); - if (cmd.equals("apogee") || cmd.equals("main")) { - stop_timer(); - } - - if (cmd.equals("apogee") && apogee.isSelected()) { - main.setSelected(false); - arm.setEnabled(true); - } - if (cmd.equals("main") && main.isSelected()) { - apogee.setSelected(false); - arm.setEnabled(true); - } - - if (cmd.equals("arm")) { - if (arm.isSelected()) { - fire.setEnabled(true); - start_timer(); - } else - cancel(); - } - if (cmd.equals("fire")) - fire(); - if (cmd.equals("tick")) - tick_timer(); - if (cmd.equals("close")) { - close(); - } - } - - /* A window listener to catch closing events and tell the config code */ - class ConfigListener extends WindowAdapter { - AltosIgniteUI ui; - - public ConfigListener(AltosIgniteUI this_ui) { - ui = this_ui; - } - - public void windowClosing(WindowEvent e) { - ui.actionPerformed(new ActionEvent(e.getSource(), - ActionEvent.ACTION_PERFORMED, - "close")); - } - } - - private boolean open() { - device = AltosDeviceDialog.show(owner, AltosDevice.product_any); - if (device != null) { - try { - ignite = new AltosIgnite(device); - return true; - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(owner, - String.format("Cannot open device \"%s\"", - device.toShortString()), - "Cannot open target device", - JOptionPane.ERROR_MESSAGE); - } catch (AltosSerialInUseException si) { - JOptionPane.showMessageDialog(owner, - String.format("Device \"%s\" already in use", - device.toShortString()), - "Device in use", - JOptionPane.ERROR_MESSAGE); - } catch (IOException ee) { - JOptionPane.showMessageDialog(owner, - device.toShortString(), - ee.getLocalizedMessage(), - JOptionPane.ERROR_MESSAGE); - } - } - return false; - } - - public AltosIgniteUI(JFrame in_owner) { - - owner = in_owner; - apogee_status = AltosIgnite.Unknown; - main_status = AltosIgnite.Unknown; - - if (!open()) - return; - - Container pane = getContentPane(); - GridBagConstraints c = new GridBagConstraints(); - Insets i = new Insets(4,4,4,4); - - timer = new javax.swing.Timer(timeout, this); - timer.setActionCommand("tick"); - timer_running = false; - timer.restart(); - - owner = in_owner; - - pane.setLayout(new GridBagLayout()); - - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - c.weightx = 1; - c.weighty = 1; - - c.gridx = 0; - c.gridy = 0; - c.gridwidth = 2; - c.anchor = GridBagConstraints.CENTER; - label = new JLabel ("Fire Igniter"); - pane.add(label, c); - - c.gridx = 0; - c.gridy = 1; - c.gridwidth = 1; - c.anchor = GridBagConstraints.WEST; - apogee = new JRadioButton ("Apogee"); - pane.add(apogee, c); - apogee.addActionListener(this); - apogee.setActionCommand("apogee"); - - c.gridx = 1; - c.gridy = 1; - c.gridwidth = 1; - c.anchor = GridBagConstraints.WEST; - apogee_status_label = new JLabel(); - pane.add(apogee_status_label, c); - - c.gridx = 0; - c.gridy = 2; - c.gridwidth = 1; - c.anchor = GridBagConstraints.WEST; - main = new JRadioButton ("Main"); - pane.add(main, c); - main.addActionListener(this); - main.setActionCommand("main"); - - c.gridx = 1; - c.gridy = 2; - c.gridwidth = 1; - c.anchor = GridBagConstraints.WEST; - main_status_label = new JLabel(); - pane.add(main_status_label, c); - - try { - set_ignite_status(); - } catch (InterruptedException ie) { - abort(); - return; - } catch (TimeoutException te) { - abort(); - return; - } - - c.gridx = 0; - c.gridy = 3; - c.gridwidth = 1; - c.anchor = GridBagConstraints.CENTER; - arm = new JToggleButton ("Arm"); - pane.add(arm, c); - arm.addActionListener(this); - arm.setActionCommand("arm"); - arm.setEnabled(false); - - c.gridx = 1; - c.gridy = 3; - c.gridwidth = 1; - c.anchor = GridBagConstraints.CENTER; - fire = new JButton ("Fire"); - fire.setEnabled(false); - pane.add(fire, c); - fire.addActionListener(this); - fire.setActionCommand("fire"); - - pack(); - setLocationRelativeTo(owner); - setVisible(true); - - addWindowListener(new ConfigListener(this)); - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosInfoTable.java b/ao-tools/altosui/AltosInfoTable.java deleted file mode 100644 index 723f8301..00000000 --- a/ao-tools/altosui/AltosInfoTable.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosInfoTable extends JTable { - private AltosFlightInfoTableModel model; - - private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14); - private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14); - - static final int info_columns = 3; - static final int info_rows = 17; - - int desired_row_height() { - FontMetrics infoValueMetrics = getFontMetrics(infoValueFont); - return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10; - } - - public AltosInfoTable() { - super(new AltosFlightInfoTableModel(info_rows, info_columns)); - model = (AltosFlightInfoTableModel) getModel(); - setFont(infoValueFont); - setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); - setShowGrid(true); - setRowHeight(desired_row_height()); - doLayout(); - } - - public Dimension getPreferredScrollableViewportSize() { - return getPreferredSize(); - } - - void info_reset() { - model.reset(); - } - - void info_add_row(int col, String name, String value) { - model.addRow(col, name, value); - } - - void info_add_row(int col, String name, String format, Object... parameters) { - info_add_row (col, name, String.format(format, parameters)); - } - - void info_add_deg(int col, String name, double v, int pos, int neg) { - int c = pos; - if (v < 0) { - c = neg; - v = -v; - } - double deg = Math.floor(v); - double min = (v - deg) * 60; - - info_add_row(col, name, String.format("%3.0f°%08.5f'", deg, min)); - } - - void info_finish() { - model.finish(); - } - - public void clear() { - model.clear(); - } - - public void show(AltosState state, int crc_errors) { - if (state == null) - return; - info_reset(); - info_add_row(0, "Rocket state", "%s", state.data.state()); - info_add_row(0, "Callsign", "%s", state.data.callsign); - info_add_row(0, "Rocket serial", "%6d", state.data.serial); - info_add_row(0, "Rocket flight", "%6d", state.data.flight); - - info_add_row(0, "RSSI", "%6d dBm", state.data.rssi); - info_add_row(0, "CRC Errors", "%6d", crc_errors); - info_add_row(0, "Height", "%6.0f m", state.height); - info_add_row(0, "Max height", "%6.0f m", state.max_height); - info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration); - info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration); - info_add_row(0, "Speed", "%8.1f m/s", state.ascent ? state.speed : state.baro_speed); - info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed); - info_add_row(0, "Temperature", "%9.2f °C", state.temperature); - info_add_row(0, "Battery", "%9.2f V", state.battery); - info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense); - info_add_row(0, "Main", "%9.2f V", state.main_sense); - info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude); - if (state.gps == null) { - info_add_row(1, "GPS", "not available"); - } else { - if (state.gps_ready) - info_add_row(1, "GPS state", "%s", "ready"); - else - info_add_row(1, "GPS state", "wait (%d)", - state.gps_waiting); - if (state.data.gps.locked) - info_add_row(1, "GPS", " locked"); - else if (state.data.gps.connected) - 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); - - /* The SkyTraq GPS doesn't report these values */ - if (false) { - info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°", - state.gps.ground_speed, - state.gps.course); - info_add_row(1, "GPS climb rate", "%8.1f m/s", - state.gps.climb_rate); - info_add_row(1, "GPS error", "%6d m(h)%3d m(v)", - state.gps.h_error, state.gps.v_error); - } - info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop); - - if (state.npad > 0) { - if (state.from_pad != null) { - info_add_row(1, "Distance from pad", "%6d m", - (int) (state.from_pad.distance + 0.5)); - info_add_row(1, "Direction from pad", "%6d°", - (int) (state.from_pad.bearing + 0.5)); - info_add_row(1, "Elevation from pad", "%6d°", - (int) (state.elevation + 0.5)); - info_add_row(1, "Range from pad", "%6d m", - (int) (state.range + 0.5)); - } else { - info_add_row(1, "Distance from pad", "unknown"); - info_add_row(1, "Direction from pad", "unknown"); - info_add_row(1, "Elevation from pad", "unknown"); - info_add_row(1, "Range from pad", "unknown"); - } - info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); - 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); - int nsat_vis = 0; - int c; - - if (state.gps.cc_gps_sat == null) - info_add_row(2, "Satellites Visible", "%4d", 0); - else { - info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length); - for (c = 0; c < state.gps.cc_gps_sat.length; c++) { - info_add_row(2, "Satellite id,C/N0", - "%4d, %4d", - state.gps.cc_gps_sat[c].svid, - state.gps.cc_gps_sat[c].c_n0); - } - } - } - info_finish(); - } -} diff --git a/ao-tools/altosui/AltosKML.java b/ao-tools/altosui/AltosKML.java deleted file mode 100644 index d586033f..00000000 --- a/ao-tools/altosui/AltosKML.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.io.*; -import java.text.*; -import java.util.*; - -public class AltosKML implements AltosWriter { - - File name; - PrintStream out; - int state = -1; - AltosRecord prev = null; - - static final String[] kml_state_colors = { - "FF000000", - "FF000000", - "FF000000", - "FF0000FF", - "FF4080FF", - "FF00FFFF", - "FFFF0000", - "FF00FF00", - "FF000000", - "FFFFFFFF" - }; - - static final String kml_header_start = - "\n" + - "\n" + - "\n" + - " AO Flight#%d S/N: %03d\n" + - " \n"; - static final String kml_header_end = - " \n" + - " 0\n"; - - static final String kml_style_start = - " \n"; - - static final String kml_placemark_start = - " \n" + - " %s\n" + - " #ao-flightstate-%s\n" + - " \n" + - " 1\n" + - " absolute\n" + - " \n"; - - static final String kml_coord_fmt = - " %12.7f, %12.7f, %12.7f \n"; - - static final String kml_placemark_end = - " \n" + - " \n" + - " \n"; - - static final String kml_footer = - "\n" + - "\n"; - - void start (AltosRecord 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); - out.printf("Time: %2d:%02d:%02d\n", - record.gps.hour, record.gps.minute, record.gps.second); - out.printf("%s", kml_header_end); - } - - 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]); - 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) { - out.printf("%s", kml_placemark_end); - } - - void coord(AltosRecord record) { - AltosGPS gps = record.gps; - out.printf(kml_coord_fmt, - gps.lon, gps.lat, - record.filtered_altitude(), (double) gps.alt, - record.time, gps.nsat); - } - - void end() { - out.printf("%s", kml_footer); - } - - public void close() { - if (prev != null) { - state_end(prev); - end(); - prev = null; - } - } - - public void write(AltosRecord record) { - AltosGPS gps = record.gps; - - if (gps == null) - return; - if (!started) { - start(record); - started = true; - } - if (prev != null && - prev.gps.second == record.gps.second && - prev.gps.minute == record.gps.minute && - prev.gps.hour == record.gps.hour) - return; - if (record.state != state) { - state = record.state; - if (prev != null) { - coord(record); - state_end(prev); - } - state_start(record); - } - coord(record); - prev = record; - } - - public void write(AltosRecordIterable iterable) { - for (AltosRecord record : iterable) - write(record); - } - - public AltosKML(File in_name) throws FileNotFoundException { - name = in_name; - out = new PrintStream(name); - } - - public AltosKML(String in_string) throws FileNotFoundException { - this(new File(in_string)); - } -} diff --git a/ao-tools/altosui/AltosLanded.java b/ao-tools/altosui/AltosLanded.java deleted file mode 100644 index d34efe6d..00000000 --- a/ao-tools/altosui/AltosLanded.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosLanded extends JComponent implements AltosFlightDisplay { - GridBagLayout layout; - Font label_font; - Font value_font; - - public class LandedValue { - JLabel label; - JTextField value; - void show(AltosState state, int crc_errors) {} - - void reset() { - value.setText(""); - } - - void show(String format, double v) { - value.setText(String.format(format, v)); - } - - public LandedValue (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 0; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); - c.anchor = GridBagConstraints.WEST; - c.weightx = 0; - c.fill = GridBagConstraints.VERTICAL; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setFont(value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 1; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.weightx = 1; - c.fill = GridBagConstraints.BOTH; - layout.setConstraints(value, c); - add(value); - } - } - - String pos(double p, String pos, String neg) { - String h = pos; - if (p < 0) { - h = neg; - p = -p; - } - int deg = (int) Math.floor(p); - double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %4d° %9.6f", h, deg, min); - } - - class Lat extends LandedValue { - void show (AltosState state, int crc_errors) { - if (state.gps != null) - value.setText(pos(state.gps.lat,"N", "S")); - else - value.setText("???"); - } - public Lat (GridBagLayout layout, int y) { - super (layout, y, "Latitude"); - } - } - - Lat lat; - - class Lon extends LandedValue { - void show (AltosState state, int crc_errors) { - if (state.gps != null) - value.setText(pos(state.gps.lon,"E", "W")); - else - value.setText("???"); - } - public Lon (GridBagLayout layout, int y) { - super (layout, y, "Longitude"); - } - } - - Lon lon; - - class Bearing extends LandedValue { - void show (AltosState state, int crc_errors) { - if (state.from_pad != null) - show("%3.0f°", state.from_pad.bearing); - else - value.setText("???"); - } - public Bearing (GridBagLayout layout, int y) { - super (layout, y, "Bearing"); - } - } - - Bearing bearing; - - class Distance extends LandedValue { - void show (AltosState state, int crc_errors) { - if (state.from_pad != null) - show("%6.0f m", state.from_pad.distance); - else - value.setText("???"); - } - public Distance (GridBagLayout layout, int y) { - super (layout, y, "Distance"); - } - } - - Distance distance; - - class Height extends LandedValue { - void show (AltosState state, int crc_errors) { - show("%6.0f m", state.max_height); - } - public Height (GridBagLayout layout, int y) { - super (layout, y, "Maximum Height"); - } - } - - Height height; - - class Speed extends LandedValue { - void show (AltosState state, int crc_errors) { - show("%6.0f m/s", state.max_speed); - } - public Speed (GridBagLayout layout, int y) { - super (layout, y, "Maximum Speed"); - } - } - - Speed speed; - - class Accel extends LandedValue { - void show (AltosState state, int crc_errors) { - show("%6.0f m/s²", state.max_acceleration); - } - public Accel (GridBagLayout layout, int y) { - super (layout, y, "Maximum Acceleration"); - } - } - - Accel accel; - - public void reset() { - lat.reset(); - lon.reset(); - bearing.reset(); - distance.reset(); - height.reset(); - speed.reset(); - accel.reset(); - } - - public void show(AltosState state, int crc_errors) { - bearing.show(state, crc_errors); - distance.show(state, crc_errors); - lat.show(state, crc_errors); - lon.show(state, crc_errors); - height.show(state, crc_errors); - speed.show(state, crc_errors); - accel.show(state, crc_errors); - } - - public AltosLanded() { - layout = new GridBagLayout(); - - label_font = new Font("Dialog", Font.PLAIN, 22); - value_font = new Font("Monospaced", Font.PLAIN, 22); - setLayout(layout); - - /* Elements in descent display */ - bearing = new Bearing(layout, 0); - distance = new Distance(layout, 1); - lat = new Lat(layout, 2); - lon = new Lon(layout, 3); - height = new Height(layout, 4); - speed = new Speed(layout, 5); - accel = new Accel(layout, 6); - } -} diff --git a/ao-tools/altosui/AltosLed.java b/ao-tools/altosui/AltosLed.java deleted file mode 100644 index e08e9960..00000000 --- a/ao-tools/altosui/AltosLed.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosLed extends JLabel { - ImageIcon on, off; - - ImageIcon create_icon(String path) { - java.net.URL imgURL = AltosUI.class.getResource(path); - if (imgURL != null) - return new ImageIcon(imgURL); - System.err.printf("Cannot find icon \"%s\"\n", path); - return null; - } - - public void set(boolean set) { - if (set) - setIcon(on); - else - setIcon(off); - } - - public AltosLed(String on_path, String off_path) { - on = create_icon(on_path); - off = create_icon(off_path); - setIcon(off); - } -} diff --git a/ao-tools/altosui/AltosLights.java b/ao-tools/altosui/AltosLights.java deleted file mode 100644 index 2fa38412..00000000 --- a/ao-tools/altosui/AltosLights.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosLights extends JComponent { - - GridBagLayout gridbag; - - AltosLed red, green; - - ImageIcon create_icon(String path, String description) { - java.net.URL imgURL = AltosUI.class.getResource(path); - if (imgURL != null) - return new ImageIcon(imgURL, description); - System.err.printf("Cannot find icon \"%s\"\n", path); - return null; - } - - public void set (boolean on) { - if (on) { - red.set(false); - green.set(true); - } else { - red.set(true); - green.set(false); - } - } - - public AltosLights() { - GridBagConstraints c; - gridbag = new GridBagLayout(); - setLayout(gridbag); - - c = new GridBagConstraints(); - red = new AltosLed("/redled.png", "/grayled.png"); - c.gridx = 0; c.gridy = 0; - c.insets = new Insets (0, 5, 0, 5); - gridbag.setConstraints(red, c); - add(red); - red.set(true); - green = new AltosLed("/greenled.png", "/grayled.png"); - c.gridx = 1; c.gridy = 0; - gridbag.setConstraints(green, c); - add(green); - green.set(false); - } -} diff --git a/ao-tools/altosui/AltosLine.java b/ao-tools/altosui/AltosLine.java deleted file mode 100644 index 86e9d4c6..00000000 --- a/ao-tools/altosui/AltosLine.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -public class AltosLine { - public String line; - - public AltosLine() { - line = null; - } - - public AltosLine(String s) { - line = s; - } -} \ No newline at end of file diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java deleted file mode 100644 index dd147d21..00000000 --- a/ao-tools/altosui/AltosLog.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.io.*; -import java.lang.*; -import java.util.*; -import java.text.ParseException; -import java.util.concurrent.LinkedBlockingQueue; - -/* - * This creates a thread to capture telemetry data and write it to - * a log file - */ -class AltosLog implements Runnable { - - LinkedBlockingQueue input_queue; - LinkedBlockingQueue pending_queue; - int serial; - int flight; - FileWriter log_file; - Thread log_thread; - - private void close_log_file() { - if (log_file != null) { - try { - log_file.close(); - } catch (IOException io) { - } - log_file = null; - } - } - - void close() { - close_log_file(); - if (log_thread != null) { - log_thread.interrupt(); - log_thread = null; - } - } - - boolean open (AltosTelemetry telem) throws IOException { - AltosFile a = new AltosFile(telem); - - log_file = new FileWriter(a, true); - if (log_file != null) { - while (!pending_queue.isEmpty()) { - try { - String s = pending_queue.take(); - log_file.write(s); - log_file.write('\n'); - } catch (InterruptedException ie) { - } - } - log_file.flush(); - } - return log_file != null; - } - - public void run () { - try { - for (;;) { - AltosLine line = input_queue.take(); - if (line.line == null) - continue; - try { - AltosTelemetry telem = new AltosTelemetry(line.line); - if (telem.serial != serial || telem.flight != flight || log_file == null) { - close_log_file(); - serial = telem.serial; - flight = telem.flight; - open(telem); - } - } catch (ParseException pe) { - } catch (AltosCRCException ce) { - } - if (log_file != null) { - log_file.write(line.line); - log_file.write('\n'); - log_file.flush(); - } else - pending_queue.put(line.line); - } - } catch (InterruptedException ie) { - } catch (IOException ie) { - } - close(); - } - - public AltosLog (AltosSerial s) { - pending_queue = new LinkedBlockingQueue (); - input_queue = new LinkedBlockingQueue (); - s.add_monitor(input_queue); - serial = -1; - flight = -1; - log_file = null; - log_thread = new Thread(this); - log_thread.start(); - } -} diff --git a/ao-tools/altosui/AltosPad.java b/ao-tools/altosui/AltosPad.java deleted file mode 100644 index 66954347..00000000 --- a/ao-tools/altosui/AltosPad.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosPad extends JComponent implements AltosFlightDisplay { - GridBagLayout layout; - - public class LaunchStatus { - JLabel label; - JTextField value; - AltosLights lights; - - void show(AltosState state, int crc_errors) {} - void reset() { - value.setText(""); - lights.set(false); - } - - public LaunchStatus (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - lights = new AltosLights(); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(lights, c); - add(lights); - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - - } - } - - public class LaunchValue { - JLabel label; - JTextField value; - void show(AltosState state, int crc_errors) {} - - void reset() { - value.setText(""); - } - public LaunchValue (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - } - } - - class Battery extends LaunchStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.2f V", state.battery)); - lights.set(state.battery > 3.7); - } - public Battery (GridBagLayout layout, int y) { - super(layout, y, "Battery Voltage"); - } - } - - Battery battery; - - class Apogee extends LaunchStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.2f V", state.drogue_sense)); - lights.set(state.drogue_sense > 3.2); - } - public Apogee (GridBagLayout layout, int y) { - super(layout, y, "Apogee Igniter Voltage"); - } - } - - Apogee apogee; - - class Main extends LaunchStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.2f V", state.main_sense)); - lights.set(state.main_sense > 3.2); - } - public Main (GridBagLayout layout, int y) { - super(layout, y, "Main Igniter Voltage"); - } - } - - Main main; - - class GPSLocked extends LaunchStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4d sats", state.gps.nsat)); - lights.set(state.gps.locked); - } - public GPSLocked (GridBagLayout layout, int y) { - super (layout, y, "GPS Locked"); - } - } - - GPSLocked gps_locked; - - class GPSReady extends LaunchStatus { - void show (AltosState state, int crc_errors) { - if (state.gps_ready) - value.setText("Ready"); - else - value.setText(String.format("Waiting %d", state.gps_waiting)); - lights.set(state.gps_ready); - } - public GPSReady (GridBagLayout layout, int y) { - super (layout, y, "GPS Ready"); - } - } - - GPSReady gps_ready; - - String pos(double p, String pos, String neg) { - String h = pos; - if (p < 0) { - h = neg; - p = -p; - } - int deg = (int) Math.floor(p); - double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %4d° %9.6f", h, deg, min); - } - - class PadLat extends LaunchValue { - void show (AltosState state, int crc_errors) { - value.setText(pos(state.pad_lat,"N", "S")); - } - public PadLat (GridBagLayout layout, int y) { - super (layout, y, "Pad Latitude"); - } - } - - PadLat pad_lat; - - class PadLon extends LaunchValue { - void show (AltosState state, int crc_errors) { - value.setText(pos(state.pad_lon,"E", "W")); - } - public PadLon (GridBagLayout layout, int y) { - super (layout, y, "Pad Longitude"); - } - } - - PadLon pad_lon; - - class PadAlt extends LaunchValue { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.0f m", state.pad_alt)); - } - public PadAlt (GridBagLayout layout, int y) { - super (layout, y, "Pad Altitude"); - } - } - - PadAlt pad_alt; - - public void reset() { - battery.reset(); - apogee.reset(); - main.reset(); - gps_locked.reset(); - gps_ready.reset(); - pad_lat.reset(); - pad_lon.reset(); - pad_alt.reset(); - } - - public void show(AltosState state, int crc_errors) { - battery.show(state, crc_errors); - apogee.show(state, crc_errors); - main.show(state, crc_errors); - gps_locked.show(state, crc_errors); - gps_ready.show(state, crc_errors); - pad_lat.show(state, crc_errors); - pad_lon.show(state, crc_errors); - pad_alt.show(state, crc_errors); - } - - public AltosPad() { - layout = new GridBagLayout(); - - setLayout(layout); - - /* Elements in pad display: - * - * Battery voltage - * Igniter continuity - * GPS lock status - * GPS ready status - * GPS location - * Pad altitude - * RSSI - */ - battery = new Battery(layout, 0); - apogee = new Apogee(layout, 1); - main = new Main(layout, 2); - gps_locked = new GPSLocked(layout, 3); - gps_ready = new GPSReady(layout, 4); - pad_lat = new PadLat(layout, 5); - pad_lon = new PadLon(layout, 6); - pad_alt = new PadAlt(layout, 7); - } -} diff --git a/ao-tools/altosui/AltosParse.java b/ao-tools/altosui/AltosParse.java deleted file mode 100644 index fbfcaaee..00000000 --- a/ao-tools/altosui/AltosParse.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.text.*; -import java.lang.*; - -public class AltosParse { - static boolean isdigit(char c) { - return '0' <= c && c <= '9'; - } - - static int parse_int(String v) throws ParseException { - try { - return Altos.fromdec(v); - } catch (NumberFormatException e) { - throw new ParseException("error parsing int " + v, 0); - } - } - - static int parse_hex(String v) throws ParseException { - try { - return Altos.fromhex(v); - } catch (NumberFormatException e) { - throw new ParseException("error parsing hex " + v, 0); - } - } - - static double parse_double(String v) throws ParseException { - try { - return Double.parseDouble(v); - } catch (NumberFormatException e) { - throw new ParseException("error parsing double " + v, 0); - } - } - - static double parse_coord(String coord) throws ParseException { - String[] dsf = coord.split("\\D+"); - - if (dsf.length != 3) { - throw new ParseException("error parsing coord " + coord, 0); - } - int deg = parse_int(dsf[0]); - int min = parse_int(dsf[1]); - int frac = parse_int(dsf[2]); - - double r = deg + (min + frac / 10000.0) / 60.0; - if (coord.endsWith("S") || coord.endsWith("W")) - r = -r; - return r; - } - - static String strip_suffix(String v, String suffix) { - if (v.endsWith(suffix)) - return v.substring(0, v.length() - suffix.length()); - return v; - } - - static void word(String v, String m) throws ParseException { - if (!v.equals(m)) { - throw new ParseException("error matching '" + v + "' '" + m + "'", 0); - } - } -} diff --git a/ao-tools/altosui/AltosPreferences.java b/ao-tools/altosui/AltosPreferences.java deleted file mode 100644 index e2a3df3b..00000000 --- a/ao-tools/altosui/AltosPreferences.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; -import java.awt.Component; -import javax.swing.*; -import javax.swing.filechooser.FileSystemView; - -class AltosPreferences { - static Preferences preferences; - - /* logdir preference name */ - final static String logdirPreference = "LOGDIR"; - - /* channel preference name */ - final static String channelPreferenceFormat = "CHANNEL-%d"; - - /* voice preference name */ - final static String voicePreference = "VOICE"; - - /* callsign preference name */ - final static String callsignPreference = "CALLSIGN"; - - /* firmware directory preference name */ - final static String firmwaredirPreference = "FIRMWARE"; - - /* Default logdir is ~/TeleMetrum */ - final static String logdirName = "TeleMetrum"; - - /* UI Component to pop dialogs up */ - static Component component; - - /* Log directory */ - static File logdir; - - /* Channel (map serial to channel) */ - static Hashtable channels; - - /* Voice preference */ - static boolean voice; - - /* Callsign preference */ - static String callsign; - - /* Firmware directory */ - static File firmwaredir; - - public static void init(Component ui) { - preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); - - component = ui; - - /* Initialize logdir from preferences */ - String logdir_string = preferences.get(logdirPreference, null); - if (logdir_string != null) - logdir = new File(logdir_string); - else { - /* Use the file system view default directory */ - logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName); - if (!logdir.exists()) - logdir.mkdirs(); - } - - channels = new Hashtable(); - - voice = preferences.getBoolean(voicePreference, true); - - callsign = preferences.get(callsignPreference,"N0CALL"); - - String firmwaredir_string = preferences.get(firmwaredirPreference, null); - if (firmwaredir_string != null) - firmwaredir = new File(firmwaredir_string); - else - firmwaredir = null; - } - - static void flush_preferences() { - try { - preferences.flush(); - } catch (BackingStoreException ee) { - JOptionPane.showMessageDialog(component, - preferences.absolutePath(), - "Cannot save prefernces", - JOptionPane.ERROR_MESSAGE); - } - } - - public static void set_logdir(File new_logdir) { - logdir = new_logdir; - synchronized (preferences) { - preferences.put(logdirPreference, logdir.getPath()); - flush_preferences(); - } - } - - private static boolean check_dir(File dir) { - if (!dir.exists()) { - if (!dir.mkdirs()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Cannot create directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - } else if (!dir.isDirectory()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Is not a directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - return true; - } - - /* Configure the log directory. This is where all telemetry and eeprom files - * will be written to, and where replay will look for telemetry files - */ - public static void ConfigureLog() { - JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile()); - - logdir_chooser.setDialogTitle("Configure Data Logging Directory"); - logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - - if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) { - File dir = logdir_chooser.getSelectedFile(); - if (check_dir(dir)) - set_logdir(dir); - } - } - - public static File logdir() { - return logdir; - } - - public static void set_channel(int serial, int new_channel) { - channels.put(serial, new_channel); - synchronized (preferences) { - preferences.putInt(String.format(channelPreferenceFormat, serial), new_channel); - flush_preferences(); - } - } - - public static int channel(int serial) { - if (channels.containsKey(serial)) - return channels.get(serial); - int channel = preferences.getInt(String.format(channelPreferenceFormat, serial), 0); - channels.put(serial, channel); - return channel; - } - - public static void set_voice(boolean new_voice) { - voice = new_voice; - synchronized (preferences) { - preferences.putBoolean(voicePreference, voice); - flush_preferences(); - } - } - - public static boolean voice() { - return voice; - } - - public static void set_callsign(String new_callsign) { - callsign = new_callsign; - synchronized(preferences) { - preferences.put(callsignPreference, callsign); - flush_preferences(); - } - } - - public static String callsign() { - return callsign; - } - - public static void set_firmwaredir(File new_firmwaredir) { - firmwaredir = new_firmwaredir; - synchronized (preferences) { - preferences.put(firmwaredirPreference, firmwaredir.getPath()); - flush_preferences(); - } - } - - public static File firmwaredir() { - return firmwaredir; - } -} diff --git a/ao-tools/altosui/AltosReader.java b/ao-tools/altosui/AltosReader.java deleted file mode 100644 index b9280a0c..00000000 --- a/ao-tools/altosui/AltosReader.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.io.*; -import java.util.*; -import java.text.*; - -public class AltosReader { - public AltosRecord read() throws IOException, ParseException { return null; } - public void close() { } - public void write_comments(PrintStream out) { } -} diff --git a/ao-tools/altosui/AltosRecord.java b/ao-tools/altosui/AltosRecord.java deleted file mode 100644 index 1160a273..00000000 --- a/ao-tools/altosui/AltosRecord.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.text.*; -import java.util.HashMap; -import java.io.*; - -public class AltosRecord { - int version; - String callsign; - int serial; - int flight; - int rssi; - int status; - int state; - int tick; - int accel; - int pres; - int temp; - int batt; - int drogue; - int main; - int flight_accel; - int ground_accel; - int flight_vel; - int flight_pres; - int ground_pres; - int accel_plus_g; - int accel_minus_g; - AltosGPS gps; - - double time; /* seconds since boost */ - - /* - * 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 raw_pressure() { - return barometer_to_pressure(pres); - } - - public double filtered_pressure() { - return barometer_to_pressure(flight_pres); - } - - public double ground_pressure() { - return barometer_to_pressure(ground_pres); - } - - public double filtered_altitude() { - return AltosConvert.pressure_to_altitude(filtered_pressure()); - } - - public double raw_altitude() { - return AltosConvert.pressure_to_altitude(raw_pressure()); - } - - public double ground_altitude() { - return AltosConvert.pressure_to_altitude(ground_pressure()); - } - - public double filtered_height() { - return filtered_altitude() - ground_altitude(); - } - - public double raw_height() { - return raw_altitude() - ground_altitude(); - } - - public double battery_voltage() { - return AltosConvert.cc_battery_to_voltage(batt); - } - - public double main_voltage() { - return AltosConvert.cc_ignitor_to_voltage(main); - } - - public double drogue_voltage() { - 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() { - 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() { - return (ground_accel - accel) / accel_counts_per_mss(); - } - - public double accel_speed() { - double speed = flight_vel / (accel_counts_per_mss() * 100.0); - return speed; - } - - public String state() { - return Altos.state_name(state); - } - - public static String gets(FileInputStream s) throws IOException { - int c; - String line = ""; - - while ((c = s.read()) != -1) { - if (c == '\r') - continue; - if (c == '\n') { - return line; - } - line = line + (char) c; - } - return null; - } - - public AltosRecord(AltosRecord 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; - gps = new AltosGPS(old.gps); - } - - public AltosRecord() { - version = 0; - callsign = "N0CALL"; - serial = 0; - flight = 0; - rssi = 0; - status = 0; - state = Altos.ao_flight_startup; - tick = 0; - accel = 0; - pres = 0; - temp = 0; - batt = 0; - drogue = 0; - main = 0; - flight_accel = 0; - ground_accel = 0; - flight_vel = 0; - flight_pres = 0; - ground_pres = 0; - accel_plus_g = 0; - accel_minus_g = 0; - gps = new AltosGPS(); - } -} diff --git a/ao-tools/altosui/AltosRecordIterable.java b/ao-tools/altosui/AltosRecordIterable.java deleted file mode 100644 index a7df92d1..00000000 --- a/ao-tools/altosui/AltosRecordIterable.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -public abstract class AltosRecordIterable implements Iterable { - public abstract Iterator iterator(); - public void write_comments(PrintStream out) { } -} diff --git a/ao-tools/altosui/AltosReplayReader.java b/ao-tools/altosui/AltosReplayReader.java deleted file mode 100644 index 4e5e1d93..00000000 --- a/ao-tools/altosui/AltosReplayReader.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -/* - * Open an existing telemetry file and replay it in realtime - */ - -public class AltosReplayReader extends AltosFlightReader { - Iterator iterator; - - public AltosRecord read() { - if (iterator.hasNext()) - return iterator.next(); - return null; - } - - public void close (boolean interrupted) { - } - - void update(AltosState state) throws InterruptedException { - /* Make it run in realtime after the rocket leaves the pad */ - if (state.state > Altos.ao_flight_pad) - Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); - } - - public AltosReplayReader(Iterator in_iterator, String in_name) { - iterator = in_iterator; - name = in_name; - } -} diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java deleted file mode 100644 index 55056b5e..00000000 --- a/ao-tools/altosui/AltosRomconfig.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; -import java.io.*; - -public class AltosRomconfig { - public boolean valid; - public int version; - public int check; - public int serial_number; - public int radio_calibration; - - static int get_int(byte[] bytes, int start, int len) { - int v = 0; - int o = 0; - while (len > 0) { - v = v | ((((int) bytes[start]) & 0xff) << o); - start++; - len--; - o += 8; - } - return v; - } - - static void put_int(int value, byte[] bytes, int start, int len) { - while (len > 0) { - bytes[start] = (byte) (value & 0xff); - start++; - len--; - value >>= 8; - } - } - - static void put_string(String value, byte[] bytes, int start) { - for (int i = 0; i < value.length(); i++) - bytes[start + i] = (byte) value.charAt(i); - } - - static final int AO_USB_DESC_STRING = 3; - - static void put_usb_serial(int value, byte[] bytes, int start) { - int offset = start + 0xa; - int string_num = 0; - - while (offset < bytes.length && bytes[offset] != 0) { - if (bytes[offset + 1] == AO_USB_DESC_STRING) { - ++string_num; - if (string_num == 4) - break; - } - offset += ((int) bytes[offset]) & 0xff; - } - if (offset >= bytes.length || bytes[offset] == 0) - return; - int len = ((((int) bytes[offset]) & 0xff) - 2) / 2; - String fmt = String.format("%%0%dd", len); - - String s = String.format(fmt, value); - if (s.length() != len) { - System.out.printf("weird usb length issue %s isn't %d\n", - s, len); - return; - } - for (int i = 0; i < len; i++) { - bytes[offset + 2 + i*2] = (byte) s.charAt(i); - bytes[offset + 2 + i*2+1] = 0; - } - } - - public AltosRomconfig(byte[] bytes, int offset) { - version = get_int(bytes, offset + 0, 2); - check = get_int(bytes, offset + 2, 2); - if (check == (~version & 0xffff)) { - switch (version) { - case 2: - case 1: - serial_number = get_int(bytes, offset + 4, 2); - radio_calibration = get_int(bytes, offset + 6, 4); - valid = true; - break; - } - } - } - - public AltosRomconfig(AltosHexfile hexfile) { - this(hexfile.data, 0xa0 - hexfile.address); - } - - public void write(byte[] bytes, int offset) throws IOException { - if (!valid) - throw new IOException("rom configuration invalid"); - - if (offset < 0 || bytes.length < offset + 10) - throw new IOException("image cannot contain rom config"); - - AltosRomconfig existing = new AltosRomconfig(bytes, offset); - if (!existing.valid) - throw new IOException("image does not contain existing rom config"); - - switch (existing.version) { - case 2: - put_usb_serial(serial_number, bytes, offset); - case 1: - put_int(serial_number, bytes, offset + 4, 2); - put_int(radio_calibration, bytes, offset + 6, 4); - break; - } - } - - public void write (AltosHexfile hexfile) throws IOException { - write(hexfile.data, 0xa0 - hexfile.address); - AltosRomconfig check = new AltosRomconfig(hexfile); - if (!check.valid()) - throw new IOException("writing new rom config failed\n"); - } - - public AltosRomconfig(int in_serial_number, int in_radio_calibration) { - valid = true; - version = 1; - check = (~version & 0xffff); - serial_number = in_serial_number; - radio_calibration = in_radio_calibration; - } - - public boolean valid() { - return valid && serial_number != 0; - } - - public AltosRomconfig() { - valid = false; - } -} diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java deleted file mode 100644 index e1dc974e..00000000 --- a/ao-tools/altosui/AltosRomconfigUI.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import javax.swing.event.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; - -public class AltosRomconfigUI - extends JDialog - implements ActionListener -{ - Container pane; - Box box; - JLabel serial_label; - JLabel radio_calibration_label; - - JFrame owner; - JTextField serial_value; - JTextField radio_calibration_value; - - JButton ok; - JButton cancel; - - /* Build the UI using a grid bag */ - public AltosRomconfigUI(JFrame in_owner) { - super (in_owner, "Configure TeleMetrum Rom Values", true); - - owner = in_owner; - GridBagConstraints c; - - Insets il = new Insets(4,4,4,4); - Insets ir = new Insets(4,4,4,4); - - pane = getContentPane(); - pane.setLayout(new GridBagLayout()); - - /* Serial */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 0; - c.gridwidth = 3; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - serial_label = new JLabel("Serial:"); - pane.add(serial_label, c); - - c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 0; - c.gridwidth = 3; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - serial_value = new JTextField("0"); - pane.add(serial_value, c); - - /* Radio calibration value */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 1; - c.gridwidth = 3; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - c.ipady = 5; - radio_calibration_label = new JLabel("Radio Calibration:"); - pane.add(radio_calibration_label, c); - - c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 1; - c.gridwidth = 3; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - c.ipady = 5; - radio_calibration_value = new JTextField("1186611"); - pane.add(radio_calibration_value, c); - - /* Buttons */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 2; - c.gridwidth = 3; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = il; - ok = new JButton("OK"); - pane.add(ok, c); - ok.addActionListener(this); - ok.setActionCommand("ok"); - - c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 2; - c.gridwidth = 3; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = il; - cancel = new JButton("Cancel"); - pane.add(cancel, c); - cancel.addActionListener(this); - cancel.setActionCommand("cancel"); - - pack(); - setLocationRelativeTo(owner); - } - - boolean selected; - - /* Listen for events from our buttons */ - public void actionPerformed(ActionEvent e) { - String cmd = e.getActionCommand(); - - if (cmd.equals("ok")) { - AltosRomconfig romconfig = romconfig(); - if (romconfig == null || !romconfig.valid()) { - JOptionPane.showMessageDialog(this, - "Invalid serial number or radio calibration value", - "Invalid rom configuration", - JOptionPane.ERROR_MESSAGE); - return; - } - selected = true; - } - setVisible(false); - } - - int serial() { - return Integer.parseInt(serial_value.getText()); - } - - void set_serial(int serial) { - serial_value.setText(String.format("%d", serial)); - } - - int radio_calibration() { - return Integer.parseInt(radio_calibration_value.getText()); - } - - void set_radio_calibration(int calibration) { - radio_calibration_value.setText(String.format("%d", calibration)); - } - - public void set(AltosRomconfig config) { - if (config != null && config.valid()) { - set_serial(config.serial_number); - set_radio_calibration(config.radio_calibration); - } - } - - AltosRomconfig romconfig() { - try { - return new AltosRomconfig(serial(), radio_calibration()); - } catch (NumberFormatException ne) { - return null; - } - } - - public AltosRomconfig showDialog() { - setVisible(true); - if (selected) - return romconfig(); - return null; - } -} diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java deleted file mode 100644 index b19143e5..00000000 --- a/ao-tools/altosui/AltosSerial.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -/* - * Deal with TeleDongle on a serial port - */ - -package altosui; - -import java.lang.*; -import java.io.*; -import java.util.concurrent.*; -import java.util.*; - -import libaltosJNI.*; - -/* - * This class reads from the serial port and places each received - * line in a queue. Dealing with that queue is left up to other - * threads. - */ - -public class AltosSerial implements Runnable { - - static List devices_opened = Collections.synchronizedList(new LinkedList()); - - AltosDevice device; - SWIGTYPE_p_altos_file altos; - LinkedList> monitors; - LinkedBlockingQueue reply_queue; - Thread input_thread; - String line; - byte[] line_bytes; - int line_count; - boolean monitor_mode; - - public void run () { - int c; - - try { - for (;;) { - c = libaltos.altos_getchar(altos, 0); - if (Thread.interrupted()) - break; - if (c == libaltosConstants.LIBALTOS_ERROR) { - for (int e = 0; e < monitors.size(); e++) { - LinkedBlockingQueue q = monitors.get(e); - q.put(new AltosLine()); - } - reply_queue.put (new AltosLine()); - break; - } - if (c == libaltosConstants.LIBALTOS_TIMEOUT) - continue; - if (c == '\r') - continue; - synchronized(this) { - if (c == '\n') { - if (line_count != 0) { - try { - line = new String(line_bytes, 0, line_count, "UTF-8"); - } catch (UnsupportedEncodingException ue) { - line = ""; - for (int i = 0; i < line_count; i++) - line = line + line_bytes[i]; - } - if (line.startsWith("VERSION") || line.startsWith("CRC")) { - for (int e = 0; e < monitors.size(); e++) { - LinkedBlockingQueue q = monitors.get(e); - q.put(new AltosLine (line)); - } - } else { -// System.out.printf("GOT: %s\n", line); - reply_queue.put(new AltosLine (line)); - } - line_count = 0; - line = ""; - } - } else { - if (line_bytes == null) { - line_bytes = new byte[256]; - } else if (line_count == line_bytes.length) { - byte[] new_line_bytes = new byte[line_count * 2]; - System.arraycopy(line_bytes, 0, new_line_bytes, 0, line_count); - line_bytes = new_line_bytes; - } - line_bytes[line_count] = (byte) c; - line_count++; - } - } - } - } catch (InterruptedException e) { - } - } - - public void flush_output() { - if (altos != null) - libaltos.altos_flush(altos); - } - - public void flush_input() { - flush_output(); - boolean got_some; - do { - try { - Thread.sleep(100); - } catch (InterruptedException ie) { - } - got_some = !reply_queue.isEmpty(); - synchronized(this) { - if (!"VERSION".startsWith(line) && - !line.startsWith("VERSION")) - line = ""; - reply_queue.clear(); - } - } while (got_some); - } - - public String get_reply() throws InterruptedException { - flush_output(); - AltosLine line = reply_queue.take(); - return line.line; - } - - public String get_reply(int timeout) throws InterruptedException { - flush_output(); - AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS); - if (line == null) - return null; - return line.line; - } - - public void add_monitor(LinkedBlockingQueue q) { - set_monitor(true); - monitors.add(q); - } - - public void remove_monitor(LinkedBlockingQueue q) { - monitors.remove(q); - if (monitors.isEmpty()) - set_monitor(false); - } - - public void close() { - if (altos != null) { - libaltos.altos_close(altos); - } - if (input_thread != null) { - try { - input_thread.interrupt(); - input_thread.join(); - } catch (InterruptedException e) { - } - input_thread = null; - } - if (altos != null) { - libaltos.altos_free(altos); - altos = null; - } - synchronized (devices_opened) { - devices_opened.remove(device.getPath()); - } - } - - public void putc(char c) { - if (altos != null) - libaltos.altos_putchar(altos, c); - } - - public void print(String data) { -// System.out.printf("\"%s\" ", data); - for (int i = 0; i < data.length(); i++) - putc(data.charAt(i)); - } - - public void printf(String format, Object ... arguments) { - print(String.format(format, arguments)); - } - - private void open() throws FileNotFoundException, AltosSerialInUseException { - synchronized (devices_opened) { - if (devices_opened.contains(device.getPath())) - throw new AltosSerialInUseException(device); - devices_opened.add(device.getPath()); - } - altos = libaltos.altos_open(device); - if (altos == null) { - close(); - throw new FileNotFoundException(device.toShortString()); - } - input_thread = new Thread(this); - input_thread.start(); - print("~\nE 0\n"); - set_monitor(false); - flush_output(); - } - - public void set_radio() { - set_channel(AltosPreferences.channel(device.getSerial())); - set_callsign(AltosPreferences.callsign()); - } - - public void set_channel(int channel) { - if (altos != null) { - if (monitor_mode) - printf("m 0\nc r %d\nm 1\n", channel); - else - printf("c r %d\n", channel); - flush_output(); - } - } - - void set_monitor(boolean monitor) { - monitor_mode = monitor; - if (altos != null) { - if (monitor) - printf("m 1\n"); - else - printf("m 0\n"); - flush_output(); - } - } - - public void set_callsign(String callsign) { - if (altos != null) { - printf ("c c %s\n", callsign); - flush_output(); - } - } - - public AltosSerial(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { - device = in_device; - line = ""; - monitor_mode = false; - monitors = new LinkedList> (); - reply_queue = new LinkedBlockingQueue (); - open(); - } -} diff --git a/ao-tools/altosui/AltosSerialInUseException.java b/ao-tools/altosui/AltosSerialInUseException.java deleted file mode 100644 index 4b108c7c..00000000 --- a/ao-tools/altosui/AltosSerialInUseException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import libaltosJNI.*; - -public class AltosSerialInUseException extends Exception { - public altos_device device; - - public AltosSerialInUseException (altos_device in_device) { - device = in_device; - } -} diff --git a/ao-tools/altosui/AltosSerialMonitor.java b/ao-tools/altosui/AltosSerialMonitor.java deleted file mode 100644 index ad0e9295..00000000 --- a/ao-tools/altosui/AltosSerialMonitor.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -public interface AltosSerialMonitor { - void data(String data); -} diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java deleted file mode 100644 index 80970605..00000000 --- a/ao-tools/altosui/AltosSiteMap.java +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import java.awt.*; -import java.awt.image.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.MouseInputAdapter; -import javax.imageio.ImageIO; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.lang.Math; -import java.awt.geom.Point2D; -import java.awt.geom.Line2D; - -public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { - // preferred vertical step in a tile in naut. miles - // will actually choose a step size between x and 2x, where this - // is 1.5x - static final double tile_size_nmi = 0.75; - - static final int px_size = 512; - - static final int MAX_TILE_DELTA = 100; - - private static Point2D.Double translatePoint(Point2D.Double p, - Point2D.Double d) - { - return new Point2D.Double(p.x + d.x, p.y + d.y); - } - - static class LatLng { - public double lat, lng; - public LatLng(double lat, double lng) { - this.lat = lat; - this.lng = lng; - } - } - - // based on google js - // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js - // search for fromLatLngToPoint and fromPointToLatLng - private static Point2D.Double pt(LatLng latlng, int zoom) { - double scale_x = 256/360.0 * Math.pow(2, zoom); - double scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - return pt(latlng, scale_x, scale_y); - } - - private static Point2D.Double pt(LatLng latlng, - double scale_x, double scale_y) - { - Point2D.Double res = new Point2D.Double(); - double e; - - res.x = latlng.lng * scale_x; - - e = Math.sin(Math.toRadians(latlng.lat)); - e = Math.max(e,-(1-1.0E-15)); - e = Math.min(e, 1-1.0E-15 ); - - res.y = 0.5*Math.log((1+e)/(1-e))*-scale_y; - return res; - } - - static private LatLng latlng(Point2D.Double pt, - double scale_x, double scale_y) - { - double lat, lng; - double rads; - - lng = pt.x/scale_x; - rads = 2 * Math.atan(Math.exp(-pt.y/scale_y)); - lat = Math.toDegrees(rads - Math.PI/2); - - return new LatLng(lat,lng); - } - - int zoom; - double scale_x, scale_y; - - private Point2D.Double pt(double lat, double lng) { - return pt(new LatLng(lat, lng), scale_x, scale_y); - } - - private LatLng latlng(double x, double y) { - return latlng(new Point2D.Double(x,y), scale_x, scale_y); - } - private LatLng latlng(Point2D.Double pt) { - return latlng(pt, scale_x, scale_y); - } - - HashMap mapTiles = new HashMap(); - Point2D.Double centre; - - private Point2D.Double tileCoordOffset(Point p) { - return new Point2D.Double(centre.x - p.x*px_size, - centre.y - p.y * px_size); - } - - private Point tileOffset(Point2D.Double p) { - return new Point((int)Math.floor((centre.x+p.x)/px_size), - (int)Math.floor((centre.y+p.y)/px_size)); - } - - private Point2D.Double getBaseLocation(double lat, double lng) { - Point2D.Double locn, north_step; - - zoom = 2; - // stupid loop structure to please Java's control flow analysis - do { - zoom++; - scale_x = 256/360.0 * Math.pow(2, zoom); - scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - locn = pt(lat, lng); - north_step = pt(lat+tile_size_nmi*4/3/60.0, lng); - if (locn.y - north_step.y > px_size) - break; - } while (zoom < 22); - locn.x = -px_size * Math.floor(locn.x/px_size); - locn.y = -px_size * Math.floor(locn.y/px_size); - return locn; - } - - public void reset() { - // nothing - } - - private void bgLoadMap(final AltosSiteMapTile tile, - final File pngfile, final String pngurl) - { - //System.out.printf("Loading/fetching map %s\n", pngfile); - Thread thread = new Thread() { - public void run() { - ImageIcon res; - res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl); - if (res != null) { - tile.loadMap(res); - } else { - System.out.printf("# Failed to fetch file %s\n", pngfile); - System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); - } - } - }; - thread.start(); - } - - public static void prefetchMaps(double lat, double lng, int w, int h) { - AltosPreferences.init(null); - - AltosSiteMap asm = new AltosSiteMap(true); - asm.centre = asm.getBaseLocation(lat, lng); - - Point2D.Double p = new Point2D.Double(); - Point2D.Double p2; - int dx = -w/2, dy = -h/2; - for (int y = dy; y < h+dy; y++) { - for (int x = dx; x < w+dx; x++) { - LatLng map_latlng = asm.latlng( - -asm.centre.x + x*px_size + px_size/2, - -asm.centre.y + y*px_size + px_size/2); - File pngfile = asm.MapFile(map_latlng.lat, map_latlng.lng); - String pngurl = asm.MapURL(map_latlng.lat, map_latlng.lng); - if (pngfile.exists()) { - System.out.printf("Already have %s\n", pngfile); - } else if (AltosSiteMapCache.fetchMap(pngfile, pngurl)) { - System.out.printf("Fetched map %s\n", pngfile); - } else { - System.out.printf("# Failed to fetch file %s\n", pngfile); - System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl); - } - } - } - } - - private void initMap(AltosSiteMapTile tile, Point offset) { - Point2D.Double coord = tileCoordOffset(offset); - - LatLng map_latlng = latlng(px_size/2-coord.x, px_size/2-coord.y); - - File pngfile = MapFile(map_latlng.lat, map_latlng.lng); - String pngurl = MapURL(map_latlng.lat, map_latlng.lng); - bgLoadMap(tile, pngfile, pngurl); - } - - private void initMaps(double lat, double lng) { - centre = getBaseLocation(lat, lng); - - for (Point k : mapTiles.keySet()) { - initMap(mapTiles.get(k), k); - } - } - - private File MapFile(double lat, double lng) { - char chlat = lat < 0 ? 'S' : 'N'; - char chlng = lng < 0 ? 'E' : 'W'; - if (lat < 0) lat = -lat; - if (lng < 0) lng = -lng; - return new File(AltosPreferences.logdir(), - String.format("map-%c%.6f,%c%.6f-%d.png", - chlat, lat, chlng, lng, zoom)); - } - - private String MapURL(double lat, double lng) { - return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32", lat, lng, zoom, px_size, px_size); - } - - boolean initialised = false; - Point2D.Double last_pt = null; - int last_state = -1; - public void show(final AltosState state, final int crc_errors) { - // if insufficient gps data, nothing to update - if (state.gps == null) - return; - if (state.pad_lat == 0 && state.pad_lon == 0) - return; - if (!state.gps.locked) { - if (state.gps.nsat < 4) - return; - } - - if (!initialised) { - initMaps(state.pad_lat, state.pad_lon); - initialised = true; - } - - final Point2D.Double pt = pt(state.gps.lat, state.gps.lon); - if (last_pt == pt && last_state == state.state) - return; - - if (last_pt == null) { - last_pt = pt; - } - boolean in_any = false; - for (Point offset : mapTiles.keySet()) { - AltosSiteMapTile tile = mapTiles.get(offset); - Point2D.Double ref, lref; - ref = translatePoint(pt, tileCoordOffset(offset)); - lref = translatePoint(last_pt, tileCoordOffset(offset)); - tile.show(state, crc_errors, lref, ref); - if (0 <= ref.x && ref.x < px_size) - if (0 <= ref.y && ref.y < px_size) - in_any = true; - } - - Point offset = tileOffset(pt); - if (!in_any) { - Point2D.Double ref, lref; - ref = translatePoint(pt, tileCoordOffset(offset)); - lref = translatePoint(last_pt, tileCoordOffset(offset)); - - AltosSiteMapTile tile = createTile(offset); - tile.show(state, crc_errors, lref, ref); - initMap(tile, offset); - finishTileLater(tile, offset); - } - - scrollRocketToVisible(pt); - - if (offset != tileOffset(last_pt)) { - ensureTilesAround(offset); - } - - last_pt = pt; - last_state = state.state; - } - - private AltosSiteMapTile createTile(Point offset) { - AltosSiteMapTile tile = new AltosSiteMapTile(px_size); - mapTiles.put(offset, tile); - return tile; - } - private void finishTileLater(final AltosSiteMapTile tile, - final Point offset) - { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - addTileAt(tile, offset); - } - } ); - } - - private void ensureTilesAround(Point base_offset) { - for (int x = -1; x <= 1; x++) { - for (int y = -1; y <= 1; y++) { - Point offset = new Point(base_offset.x + x, base_offset.y + y); - if (mapTiles.containsKey(offset)) - continue; - AltosSiteMapTile tile = createTile(offset); - initMap(tile, offset); - finishTileLater(tile, offset); - } - } - } - - private Point topleft = new Point(0,0); - private void scrollRocketToVisible(Point2D.Double pt) { - Rectangle r = comp.getVisibleRect(); - Point2D.Double copt = translatePoint(pt, tileCoordOffset(topleft)); - int dx = (int)copt.x - r.width/2 - r.x; - int dy = (int)copt.y - r.height/2 - r.y; - if (Math.abs(dx) > r.width/4 || Math.abs(dy) > r.height/4) { - r.x += dx; - r.y += dy; - comp.scrollRectToVisible(r); - } - } - - private void addTileAt(AltosSiteMapTile tile, Point offset) { - if (Math.abs(offset.x) >= MAX_TILE_DELTA || - Math.abs(offset.y) >= MAX_TILE_DELTA) - { - System.out.printf("Rocket too far away from pad (tile %d,%d)\n", - offset.x, offset.y); - return; - } - - boolean review = false; - Rectangle r = comp.getVisibleRect(); - if (offset.x < topleft.x) { - r.x += (topleft.x - offset.x) * px_size; - topleft.x = offset.x; - review = true; - } - if (offset.y < topleft.y) { - r.y += (topleft.y - offset.y) * px_size; - topleft.y = offset.y; - review = true; - } - GridBagConstraints c = new GridBagConstraints(); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.BOTH; - // put some space between the map tiles, debugging only - // c.insets = new Insets(5, 5, 5, 5); - - c.gridx = offset.x + MAX_TILE_DELTA; - c.gridy = offset.y + MAX_TILE_DELTA; - layout.setConstraints(tile, c); - - comp.add(tile); - if (review) { - comp.scrollRectToVisible(r); - } - } - - private AltosSiteMap(boolean knowWhatYouAreDoing) { - if (!knowWhatYouAreDoing) { - throw new RuntimeException("Arggh."); - } - } - - JComponent comp = new JComponent() { }; - private GridBagLayout layout = new GridBagLayout(); - - public AltosSiteMap() { - GrabNDrag scroller = new GrabNDrag(comp); - - comp.setLayout(layout); - - for (int x = -1; x <= 1; x++) { - for (int y = -1; y <= 1; y++) { - Point offset = new Point(x, y); - AltosSiteMapTile t = createTile(offset); - addTileAt(t, offset); - } - } - setViewportView(comp); - setPreferredSize(new Dimension(500,200)); - } -} diff --git a/ao-tools/altosui/AltosSiteMapCache.java b/ao-tools/altosui/AltosSiteMapCache.java deleted file mode 100644 index 2e62cc45..00000000 --- a/ao-tools/altosui/AltosSiteMapCache.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import java.awt.*; -import java.awt.image.*; -import java.awt.event.*; -import javax.swing.*; -import javax.imageio.ImageIO; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.net.URL; -import java.net.URLConnection; - -public class AltosSiteMapCache extends JLabel { - public static boolean fetchMap(File file, String url) { - URL u; - - try { - u = new URL(url); - } catch (java.net.MalformedURLException e) { - return false; - } - - byte[] data; - try { - URLConnection uc = u.openConnection(); - int contentLength = uc.getContentLength(); - InputStream in = new BufferedInputStream(uc.getInputStream()); - int bytesRead = 0; - int offset = 0; - data = new byte[contentLength]; - while (offset < contentLength) { - bytesRead = in.read(data, offset, data.length - offset); - if (bytesRead == -1) - break; - offset += bytesRead; - } - in.close(); - - if (offset != contentLength) { - return false; - } - } catch (IOException e) { - return false; - } - - try { - FileOutputStream out = new FileOutputStream(file); - out.write(data); - out.flush(); - out.close(); - } catch (FileNotFoundException e) { - return false; - } catch (IOException e) { - if (file.exists()) { - file.delete(); - } - return false; - } - return true; - } - - public static ImageIcon fetchAndLoadMap(File pngfile, String url) { - if (!pngfile.exists()) { - if (!fetchMap(pngfile, url)) { - return null; - } - } - return loadMap(pngfile, url); - } - - public static ImageIcon loadMap(File pngfile, String url) { - if (!pngfile.exists()) { - return null; - } - - try { - return new ImageIcon(ImageIO.read(pngfile)); - } catch (IOException e) { - System.out.printf("# IO error trying to load %s\n", pngfile); - return null; - } - } -} diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java deleted file mode 100644 index 8301f42b..00000000 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import java.awt.*; -import java.awt.image.*; -import java.awt.event.*; -import javax.swing.*; -import javax.imageio.ImageIO; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.lang.Math; -import java.awt.geom.Point2D; -import java.awt.geom.Line2D; - -public class AltosSiteMapTile extends JLayeredPane { - JLabel mapLabel; - JLabel draw; - Graphics2D g2d; - - public void loadMap(ImageIcon icn) { - mapLabel.setIcon(icn); - } - - static Color stateColors[] = { - Color.WHITE, // startup - Color.WHITE, // idle - Color.WHITE, // pad - Color.RED, // boost - Color.PINK, // fast - Color.YELLOW, // coast - Color.CYAN, // drogue - Color.BLUE, // main - Color.BLACK // landed - }; - - private boolean drawn_landed_circle = false; - private boolean drawn_boost_circle = false; - public synchronized void show(AltosState state, int crc_errors, - Point2D.Double last_pt, Point2D.Double pt) - { - if (0 <= state.state && state.state < stateColors.length) { - g2d.setColor(stateColors[state.state]); - } - g2d.draw(new Line2D.Double(last_pt, pt)); - - if (state.state == 3 && !drawn_boost_circle) { - drawn_boost_circle = true; - g2d.setColor(Color.RED); - g2d.drawOval((int)last_pt.x-5, (int)last_pt.y-5, 10, 10); - g2d.drawOval((int)last_pt.x-20, (int)last_pt.y-20, 40, 40); - g2d.drawOval((int)last_pt.x-35, (int)last_pt.y-35, 70, 70); - } - if (state.state == 8 && !drawn_landed_circle) { - drawn_landed_circle = true; - g2d.setColor(Color.BLACK); - g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); - g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); - g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); - } - - repaint(); - } - - public static Graphics2D fillLabel(JLabel l, Color c, int px_size) { - BufferedImage img = new BufferedImage(px_size, px_size, - BufferedImage.TYPE_INT_ARGB); - Graphics2D g = img.createGraphics(); - g.setColor(c); - g.fillRect(0, 0, px_size, px_size); - l.setIcon(new ImageIcon(img)); - return g; - } - - public AltosSiteMapTile(int px_size) { - setPreferredSize(new Dimension(px_size, px_size)); - - mapLabel = new JLabel(); - fillLabel(mapLabel, Color.GRAY, px_size); - mapLabel.setOpaque(true); - mapLabel.setBounds(0, 0, px_size, px_size); - add(mapLabel, new Integer(0)); - - draw = new JLabel(); - g2d = fillLabel(draw, new Color(127, 127, 127, 0), px_size); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - g2d.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - draw.setBounds(0, 0, px_size, px_size); - draw.setOpaque(false); - - add(draw, new Integer(1)); - } -} diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java deleted file mode 100644 index ec499d5a..00000000 --- a/ao-tools/altosui/AltosState.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -/* - * Track flight state from telemetry or eeprom data stream - */ - -package altosui; - -public class AltosState { - AltosRecord data; - - /* derived data */ - - long report_time; - - double time_change; - int tick; - - int state; - boolean landed; - boolean ascent; /* going up? */ - - double ground_altitude; - double height; - double speed; - double acceleration; - double battery; - double temperature; - double main_sense; - double drogue_sense; - double baro_speed; - - double max_height; - double max_acceleration; - double max_speed; - - AltosGPS gps; - - double pad_lat; - double pad_lon; - double pad_alt; - - static final int MIN_PAD_SAMPLES = 10; - - int npad; - int ngps; - int gps_waiting; - boolean gps_ready; - - AltosGreatCircle from_pad; - double elevation; /* from pad */ - double range; /* total distance */ - - double gps_height; - - int speak_tick; - double speak_altitude; - - - void init (AltosRecord cur, AltosState prev_state) { - int i; - AltosRecord prev; - - data = cur; - - ground_altitude = data.ground_altitude(); - height = data.filtered_altitude() - ground_altitude; - - report_time = System.currentTimeMillis(); - - acceleration = data.acceleration(); - speed = data.accel_speed(); - temperature = data.temperature(); - drogue_sense = data.drogue_voltage(); - main_sense = data.main_voltage(); - battery = data.battery_voltage(); - 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; - 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_speed = prev_state.max_speed; - - /* make sure the clock is monotonic */ - while (tick < prev_state.tick) - tick += 65536; - - time_change = (tick - prev_state.tick) / 100.0; - - /* compute barometric speed */ - - double height_change = height - prev_state.height; - if (time_change > 0) - baro_speed = (prev_state.baro_speed * 3 + (height_change / time_change)) / 4.0; - else - baro_speed = prev_state.baro_speed; - } else { - npad = 0; - ngps = 0; - gps = null; - baro_speed = 0; - time_change = 0; - } - - if (state == Altos.ao_flight_pad) { - - /* 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) { - /* 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; - } - ngps++; - } - } - - gps_waiting = MIN_PAD_SAMPLES - npad; - if (gps_waiting < 0) - gps_waiting = 0; - - gps_ready = gps_waiting == 0; - - ascent = (Altos.ao_flight_boost <= state && - state <= Altos.ao_flight_coast); - - /* Only look at accelerometer data on the way up */ - if (ascent && acceleration > max_acceleration) - max_acceleration = acceleration; - if (ascent && speed > max_speed) - max_speed = speed; - - if (height > max_height) - max_height = height; - if (data.gps != null) { - if (gps == null || !gps.locked || data.gps.locked) - gps = data.gps; - if (ngps > 0 && gps.locked) { - from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); - } - } - elevation = 0; - range = -1; - if (ngps > 0) { - gps_height = gps.alt - pad_alt; - if (from_pad != null) { - elevation = Math.atan2(height, from_pad.distance) * 180 / Math.PI; - range = Math.sqrt(height * height + from_pad.distance * from_pad.distance); - } - } else { - gps_height = 0; - } - } - - public AltosState(AltosRecord cur) { - init(cur, null); - } - - public AltosState (AltosRecord cur, AltosState prev) { - init(cur, prev); - } -} diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java deleted file mode 100644 index bdb6466a..00000000 --- a/ao-tools/altosui/AltosTelemetry.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.text.*; -import java.util.HashMap; - -/* - * Telemetry data contents - */ - - -/* - * The telemetry data stream is a bit of a mess at present, 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 AltosTelemetry extends AltosRecord { - public AltosTelemetry(String line) throws ParseException, AltosCRCException { - String[] words = line.split("\\s+"); - int i = 0; - - if (words[i].equals("CRC") && words[i+1].equals("INVALID")) { - i += 2; - AltosParse.word(words[i++], "RSSI"); - rssi = AltosParse.parse_int(words[i++]); - throw new AltosCRCException(rssi); - } - if (words[i].equals("CALL")) { - version = 0; - } else { - AltosParse.word (words[i++], "VERSION"); - version = AltosParse.parse_int(words[i++]); - } - - 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 = Altos.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:"); - drogue = 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++]); - - 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); - } -} diff --git a/ao-tools/altosui/AltosTelemetryIterable.java b/ao-tools/altosui/AltosTelemetryIterable.java deleted file mode 100644 index a71ab872..00000000 --- a/ao-tools/altosui/AltosTelemetryIterable.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.io.*; -import java.util.*; -import java.text.*; - -public class AltosTelemetryIterable extends AltosRecordIterable { - LinkedList records; - - public Iterator iterator () { - return records.iterator(); - } - - public AltosTelemetryIterable (FileInputStream input) { - boolean saw_boost = false; - int current_tick = 0; - int boost_tick = 0; - - records = new LinkedList (); - - try { - for (;;) { - String line = AltosRecord.gets(input); - if (line == null) { - break; - } - try { - AltosTelemetry record = new AltosTelemetry(line); - if (record == null) - break; - if (records.isEmpty()) { - current_tick = record.tick; - } else { - int tick = record.tick | (current_tick & ~ 0xffff); - if (tick < current_tick - 0x1000) - tick += 0x10000; - current_tick = tick; - record.tick = current_tick; - } - if (!saw_boost && record.state >= Altos.ao_flight_boost) - { - saw_boost = true; - boost_tick = record.tick; - } - records.add(record); - } catch (ParseException pe) { - System.out.printf("parse exception %s\n", pe.getMessage()); - } catch (AltosCRCException ce) { - System.out.printf("crc error\n"); - } - } - } catch (IOException io) { - System.out.printf("io exception\n"); - } - - /* 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/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java deleted file mode 100644 index 6c5a9397..00000000 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.text.*; -import java.io.*; -import java.util.concurrent.*; - -class AltosTelemetryReader extends AltosFlightReader { - AltosDevice device; - AltosSerial serial; - AltosLog log; - - LinkedBlockingQueue telem; - - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { - AltosLine l = telem.take(); - if (l.line == null) - throw new IOException("IO error"); - return new AltosTelemetry(l.line); - } - - void close(boolean interrupted) { - serial.remove_monitor(telem); - log.close(); - serial.close(); - } - - void set_channel(int channel) { - serial.set_channel(channel); - AltosPreferences.set_channel(device.getSerial(), channel); - } - - public AltosTelemetryReader (AltosDevice in_device) - throws FileNotFoundException, AltosSerialInUseException, IOException { - device = in_device; - serial = new AltosSerial(device); - log = new AltosLog(serial); - name = device.toShortString(); - - telem = new LinkedBlockingQueue(); - serial.set_radio(); - serial.add_monitor(telem); - } -} diff --git a/ao-tools/altosui/AltosUI.app/Contents/Info.plist b/ao-tools/altosui/AltosUI.app/Contents/Info.plist deleted file mode 100644 index 97b1b59c..00000000 --- a/ao-tools/altosui/AltosUI.app/Contents/Info.plist +++ /dev/null @@ -1,38 +0,0 @@ - - - - - CFBundleName - altosui - CFBundleVersion - 100.0 - CFBundleAllowMixedLocalizations - true - CFBundleExecutable - JavaApplicationStub - CFBundleDevelopmentRegion - English - CFBundlePackageType - APPL - CFBundleSignature - ???? - CFBundleGetInfoString - AltOS UI version 0.7 - CFBundleInfoDictionaryVersion - 6.0 - CFBundleIconFile - AltosUIIcon.icns - Java - - MainClass - altosui.AltosUI - JVMVersion - 1.5+ - ClassPath - - $JAVAROOT/altosui.jar - $JAVAROOT/freetts.jar - - - - diff --git a/ao-tools/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub b/ao-tools/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub deleted file mode 100755 index c661d3e1..00000000 Binary files a/ao-tools/altosui/AltosUI.app/Contents/MacOS/JavaApplicationStub and /dev/null differ diff --git a/ao-tools/altosui/AltosUI.app/Contents/PkgInfo b/ao-tools/altosui/AltosUI.app/Contents/PkgInfo deleted file mode 100644 index 8a43480f..00000000 --- a/ao-tools/altosui/AltosUI.app/Contents/PkgInfo +++ /dev/null @@ -1 +0,0 @@ -APPLAM.O diff --git a/ao-tools/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns b/ao-tools/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns deleted file mode 100644 index fe49f362..00000000 Binary files a/ao-tools/altosui/AltosUI.app/Contents/Resources/AltosUIIcon.icns and /dev/null differ diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java deleted file mode 100644 index 94c4dd2a..00000000 --- a/ao-tools/altosui/AltosUI.java +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; - -import libaltosJNI.*; - -public class AltosUI extends JFrame { - public AltosVoice voice = new AltosVoice(); - - public static boolean load_library(Frame frame) { - if (!AltosDevice.load_library()) { - JOptionPane.showMessageDialog(frame, - String.format("No AltOS library in \"%s\"", - System.getProperty("java.library.path","")), - "Cannot load device access library", - JOptionPane.ERROR_MESSAGE); - return false; - } - return true; - } - - void telemetry_window(AltosDevice device) { - try { - AltosFlightReader reader = new AltosTelemetryReader(device); - if (reader != null) - new AltosFlightUI(voice, reader, device.getSerial()); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - String.format("Cannot open device \"%s\"", - device.toShortString()), - "Cannot open target device", - JOptionPane.ERROR_MESSAGE); - } catch (AltosSerialInUseException si) { - JOptionPane.showMessageDialog(AltosUI.this, - String.format("Device \"%s\" already in use", - device.toShortString()), - "Device in use", - JOptionPane.ERROR_MESSAGE); - } catch (IOException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - device.toShortString(), - "Unkonwn I/O error", - JOptionPane.ERROR_MESSAGE); - } - } - - Container pane; - GridBagLayout gridbag; - - JButton addButton(int x, int y, String label) { - GridBagConstraints c; - JButton b; - - c = new GridBagConstraints(); - c.gridx = x; c.gridy = y; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - c.weighty = 1; - b = new JButton(label); - - Dimension ps = b.getPreferredSize(); - - gridbag.setConstraints(b, c); - add(b, c); - return b; - } - - public AltosUI() { - - load_library(null); - - java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg"); - if (imgURL != null) - setIconImage(new ImageIcon(imgURL).getImage()); - - AltosPreferences.init(this); - - pane = getContentPane(); - gridbag = new GridBagLayout(); - pane.setLayout(gridbag); - - JButton b; - - b = addButton(0, 0, "Monitor Flight"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - ConnectToDevice(); - } - }); - b = addButton(1, 0, "Save Flight Data"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - SaveFlightData(); - } - }); - b = addButton(2, 0, "Replay Flight"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - Replay(); - } - }); - b = addButton(3, 0, "Graph Data"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - GraphData(); - } - }); - b = addButton(4, 0, "Export Data"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - ExportData(); - } - }); - b = addButton(0, 1, "Configure TeleMetrum"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - ConfigureTeleMetrum(); - } - }); - - b = addButton(1, 1, "Configure AltosUI"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - ConfigureAltosUI(); - } - }); - - b = addButton(2, 1, "Flash Image"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - FlashImage(); - } - }); - - b = addButton(3, 1, "Fire Igniter"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - FireIgniter(); - } - }); - - b = addButton(4, 1, "Quit"); - b.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - System.exit(0); - } - }); - - setTitle("AltOS"); - - pane.doLayout(); - pane.validate(); - - doLayout(); - validate(); - - setVisible(true); - - Insets i = getInsets(); - Dimension ps = rootPane.getPreferredSize(); - ps.width += i.left + i.right; - ps.height += i.top + i.bottom; - setPreferredSize(ps); - setSize(ps); - setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); - } - - private void ConnectToDevice() { - AltosDevice device = AltosDeviceDialog.show(AltosUI.this, - AltosDevice.product_basestation); - - if (device != null) - telemetry_window(device); - } - - void ConfigureCallsign() { - String result; - result = JOptionPane.showInputDialog(AltosUI.this, - "Configure Callsign", - AltosPreferences.callsign()); - if (result != null) - AltosPreferences.set_callsign(result); - } - - void ConfigureTeleMetrum() { - new AltosConfig(AltosUI.this); - } - - void FlashImage() { - new AltosFlashUI(AltosUI.this); - } - - void FireIgniter() { - new AltosIgniteUI(AltosUI.this); - } - - /* - * Replay a flight from telemetry data - */ - private void Replay() { - AltosDataChooser chooser = new AltosDataChooser( - AltosUI.this); - - AltosRecordIterable iterable = chooser.runDialog(); - if (iterable != null) { - AltosFlightReader reader = new AltosReplayReader(iterable.iterator(), - chooser.filename()); - new AltosFlightUI(voice, reader); - } - } - - /* Connect to TeleMetrum, either directly or through - * a TeleDongle over the packet link - */ - private void SaveFlightData() { - new AltosEepromDownload(AltosUI.this); - } - - /* Load a flight log file and write out a CSV file containing - * all of the data in standard units - */ - - private void ExportData() { - AltosDataChooser chooser; - chooser = new AltosDataChooser(this); - AltosRecordIterable record_reader = chooser.runDialog(); - if (record_reader == null) - return; - new AltosCSVUI(AltosUI.this, record_reader, chooser.file()); - } - - /* Load a flight log CSV file and display a pretty graph. - */ - - private void GraphData() { - AltosDataChooser chooser; - chooser = new AltosDataChooser(this); - AltosRecordIterable record_reader = chooser.runDialog(); - if (record_reader == null) - return; - new AltosGraphUI(record_reader); - } - - private void ConfigureAltosUI() { - new AltosConfigureUI(AltosUI.this, voice); - } - - static AltosRecordIterable open_logfile(String filename) { - File file = new File (filename); - try { - FileInputStream in; - - in = new FileInputStream(file); - if (filename.endsWith("eeprom")) - return new AltosEepromIterable(in); - else - return new AltosTelemetryIterable(in); - } catch (FileNotFoundException fe) { - System.out.printf("Cannot open '%s'\n", filename); - return null; - } - } - - static AltosWriter open_csv(String filename) { - File file = new File (filename); - try { - return new AltosCSV(file); - } catch (FileNotFoundException fe) { - System.out.printf("Cannot open '%s'\n", filename); - return null; - } - } - - static AltosWriter open_kml(String filename) { - File file = new File (filename); - try { - return new AltosKML(file); - } catch (FileNotFoundException fe) { - System.out.printf("Cannot open '%s'\n", filename); - return null; - } - } - - static final int process_csv = 1; - static final int process_kml = 2; - - static void process_file(String input, int process) { - AltosRecordIterable iterable = open_logfile(input); - if (iterable == null) - return; - if (process == 0) - process = process_csv; - if ((process & process_csv) != 0) { - String output = Altos.replace_extension(input,".csv"); - System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); - if (input.equals(output)) { - System.out.printf("Not processing '%s'\n", input); - } else { - AltosWriter writer = open_csv(output); - if (writer != null) { - writer.write(iterable); - writer.close(); - } - } - } - if ((process & process_kml) != 0) { - String output = Altos.replace_extension(input,".kml"); - System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); - if (input.equals(output)) { - System.out.printf("Not processing '%s'\n", input); - } else { - AltosWriter writer = open_kml(output); - if (writer == null) - return; - writer.write(iterable); - writer.close(); - } - } - } - - public static void main(final String[] args) { - int process = 0; - /* Handle batch-mode */ - if (args.length == 1 && args[0].equals("--help")) { - System.out.printf("Usage: altosui [OPTION]... [FILE]...\n"); - System.out.printf(" Options:\n"); - System.out.printf(" --fetchmaps \tpre-fetch maps for site map view\n"); - System.out.printf(" --replay \t\trelive the glory of past flights \n"); - System.out.printf(" --csv\tgenerate comma separated output for spreadsheets, etc\n"); - System.out.printf(" --kml\tgenerate KML output for use with Google Earth\n"); - } else if (args.length == 3 && args[0].equals("--fetchmaps")) { - double lat = Double.parseDouble(args[1]); - double lon = Double.parseDouble(args[2]); - AltosSiteMap.prefetchMaps(lat, lon, 5, 5); - } else if (args.length == 2 && args[0].equals("--replay")) { - String filename = args[1]; - FileInputStream in; - try { - in = new FileInputStream(filename); - } catch (Exception e) { - System.out.printf("Failed to open file '%s'\n", filename); - return; - } - AltosRecordIterable recs; - AltosReplayReader reader; - if (filename.endsWith("eeprom")) { - recs = new AltosEepromIterable(in); - } else { - recs = new AltosTelemetryIterable(in); - } - reader = new AltosReplayReader(recs.iterator(), filename); - AltosFlightUI flight_ui = new AltosFlightUI(new AltosVoice(), reader); - flight_ui.set_exit_on_close(); - return; - } else if (args.length > 0) { - for (int i = 0; i < args.length; i++) { - if (args[i].equals("--kml")) - process |= process_kml; - else if (args[i].equals("--csv")) - process |= process_csv; - else - process_file(args[i], process); - } - } else { - AltosUI altosui = new AltosUI(); - altosui.setVisible(true); - - AltosDevice[] devices = AltosDevice.list(AltosDevice.product_basestation); - for (int i = 0; i < devices.length; i++) - altosui.telemetry_window(devices[i]); - } - } -} diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java deleted file mode 100644 index ac13ee14..00000000 --- a/ao-tools/altosui/AltosVoice.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import com.sun.speech.freetts.Voice; -import com.sun.speech.freetts.VoiceManager; -import com.sun.speech.freetts.audio.JavaClipAudioPlayer; -import java.util.concurrent.LinkedBlockingQueue; - -public class AltosVoice implements Runnable { - VoiceManager voice_manager; - Voice voice; - LinkedBlockingQueue phrases; - Thread thread; - boolean busy; - - final static String voice_name = "kevin16"; - - public void run() { - try { - for (;;) { - String s = phrases.take(); - voice.speak(s); - synchronized(this) { - if (phrases.isEmpty()) { - busy = false; - notifyAll(); - } - } - } - } catch (InterruptedException e) { - } - } - - public synchronized void drain() throws InterruptedException { - while (busy) - wait(); - } - - public void speak_always(String s) { - try { - if (voice != null) { - synchronized(this) { - busy = true; - phrases.put(s); - } - } - } catch (InterruptedException e) { - } - } - - public void speak(String s) { - if (AltosPreferences.voice()) - speak_always(s); - } - - public void speak(String format, Object... parameters) { - speak(String.format(format, parameters)); - } - - public AltosVoice () { - busy = false; - voice_manager = VoiceManager.getInstance(); - voice = voice_manager.getVoice(voice_name); - if (voice != null) { - voice.allocate(); - phrases = new LinkedBlockingQueue (); - thread = new Thread(this); - thread.start(); - } else { - System.out.printf("Voice manager failed to open %s\n", voice_name); - Voice[] voices = voice_manager.getVoices(); - System.out.printf("Available voices:\n"); - for (int i = 0; i < voices.length; i++) { - System.out.println(" " + voices[i].getName() - + " (" + voices[i].getDomain() + " domain)"); - } - } - } -} diff --git a/ao-tools/altosui/AltosWriter.java b/ao-tools/altosui/AltosWriter.java deleted file mode 100644 index a172dff0..00000000 --- a/ao-tools/altosui/AltosWriter.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -package altosui; - -import java.lang.*; -import java.io.*; -import java.text.*; -import java.util.*; - -public interface AltosWriter { - - public void write(AltosRecord record); - - public void write(AltosRecordIterable iterable); - - public void close(); -} diff --git a/ao-tools/altosui/GrabNDrag.java b/ao-tools/altosui/GrabNDrag.java deleted file mode 100644 index e6b87b58..00000000 --- a/ao-tools/altosui/GrabNDrag.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import java.awt.*; -import java.awt.image.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.MouseInputAdapter; -import javax.imageio.ImageIO; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; - -class GrabNDrag extends MouseInputAdapter { - private JComponent scroll; - private Point startPt = new Point(); - - public GrabNDrag(JComponent scroll) { - this.scroll = scroll; - scroll.addMouseMotionListener(this); - scroll.addMouseListener(this); - scroll.setAutoscrolls(true); - } - - public void mousePressed(MouseEvent e) { - startPt.setLocation(e.getPoint()); - } - public void mouseDragged(MouseEvent e) { - int xd = e.getX() - startPt.x; - int yd = e.getY() - startPt.y; - - Rectangle r = scroll.getVisibleRect(); - r.x -= xd; - r.y -= yd; - scroll.scrollRectToVisible(r); - } -} diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi deleted file mode 100644 index 3ed821eb..00000000 --- a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi +++ /dev/null @@ -1,84 +0,0 @@ -# -# InstDrv Example, (c) 2003 Jan Kiszka (Jan Kiszka@web.de) -# - -Name "InstDrv.dll test" - -OutFile "InstDrv-Test.exe" - -ShowInstDetails show - -ComponentText "InstDrv Plugin Usage Example" - -Page components -Page instfiles - -Section "Install a Driver" InstDriver - InstDrv::InitDriverSetup /NOUNLOAD "{4d36e978-e325-11ce-bfc1-08002be10318}" "IrCOMM2k" - Pop $0 - DetailPrint "InitDriverSetup: $0" - - InstDrv::DeleteOemInfFiles /NOUNLOAD - Pop $0 - DetailPrint "DeleteOemInfFiles: $0" - StrCmp $0 "00000000" PrintInfNames ContInst1 - - PrintInfNames: - Pop $0 - DetailPrint "Deleted $0" - Pop $0 - DetailPrint "Deleted $0" - - ContInst1: - InstDrv::CreateDevice /NOUNLOAD - Pop $0 - DetailPrint "CreateDevice: $0" - - SetOutPath $TEMP - File "ircomm2k.inf" - File "ircomm2k.sys" - - InstDrv::InstallDriver /NOUNLOAD "$TEMP\ircomm2k.inf" - Pop $0 - DetailPrint "InstallDriver: $0" - StrCmp $0 "00000000" PrintReboot ContInst2 - - PrintReboot: - Pop $0 - DetailPrint "Reboot: $0" - - ContInst2: - InstDrv::CountDevices - Pop $0 - DetailPrint "CountDevices: $0" -SectionEnd - -Section "Uninstall the driver again" UninstDriver - InstDrv::InitDriverSetup /NOUNLOAD "{4d36e978-e325-11ce-bfc1-08002be10318}" "IrCOMM2k" - Pop $0 - DetailPrint "InitDriverSetup: $0" - - InstDrv::DeleteOemInfFiles /NOUNLOAD - Pop $0 - DetailPrint "DeleteOemInfFiles: $0" - StrCmp $0 "00000000" PrintInfNames ContUninst1 - - PrintInfNames: - Pop $0 - DetailPrint "Deleted $0" - Pop $0 - DetailPrint "Deleted $0" - - ContUninst1: - InstDrv::RemoveAllDevices - Pop $0 - DetailPrint "RemoveAllDevices: $0" - StrCmp $0 "00000000" PrintReboot ContUninst2 - - PrintReboot: - Pop $0 - DetailPrint "Reboot: $0" - - ContUninst2: - Delete "$SYSDIR\system32\ircomm2k.sys" -SectionEnd \ No newline at end of file diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe deleted file mode 100644 index 615bae15..00000000 Binary files a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe and /dev/null differ diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c deleted file mode 100644 index efe866e9..00000000 --- a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c +++ /dev/null @@ -1,704 +0,0 @@ -/* - -InstDrv.dll - Installs or Removes Device Drivers - -Copyright 2003 Jan Kiszka (Jan.Kiszka@web.de) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute -it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; - you must not claim that you wrote the original software. - If you use this software in a product, an acknowledgment in the - product documentation would be appreciated but is not required. -2. Altered versions must be plainly marked as such, - and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any distribution. - -*/ - - -#include -#include -#include -#include "../exdll/exdll.h" - - -char paramBuf[1024]; -GUID devClass; -char hwIdBuf[1024]; -int initialized = 0; - - - -void* memset(void* dst, int val, unsigned int len) -{ - while (len-- > 0) - *((char *)dst)++ = val; - - return NULL; -} - - - -void* memcpy(void* dst, const void* src, unsigned int len) -{ - while (len-- > 0) - *((char *)dst)++ = *((char *)src)++; - - return NULL; -} - - - -int HexCharToInt(char c) -{ - if ((c >= '0') && (c <= '9')) - return c - '0'; - else if ((c >= 'a') && (c <= 'f')) - return c - 'a' + 10; - else if ((c >= 'A') && (c <= 'F')) - return c - 'A' + 10; - else - return -1; -} - - - -BOOLEAN HexStringToUInt(char* str, int width, void* valBuf) -{ - int i, val; - - - for (i = width - 4; i >= 0; i -= 4) - { - val = HexCharToInt(*str++); - if (val < 0) - return FALSE; - *(unsigned int *)valBuf += val << i; - } - - return TRUE; -} - - - -BOOLEAN StringToGUID(char* guidStr, GUID* pGuid) -{ - int i; - - - memset(pGuid, 0, sizeof(GUID)); - - if (*guidStr++ != '{') - return FALSE; - - if (!HexStringToUInt(guidStr, 32, &pGuid->Data1)) - return FALSE; - guidStr += 8; - - if (*guidStr++ != '-') - return FALSE; - - if (!HexStringToUInt(guidStr, 16, &pGuid->Data2)) - return FALSE; - guidStr += 4; - - if (*guidStr++ != '-') - return FALSE; - - if (!HexStringToUInt(guidStr, 16, &pGuid->Data3)) - return FALSE; - guidStr += 4; - - if (*guidStr++ != '-') - return FALSE; - - for (i = 0; i < 2; i++) - { - if (!HexStringToUInt(guidStr, 8, &pGuid->Data4[i])) - return FALSE; - guidStr += 2; - } - - if (*guidStr++ != '-') - return FALSE; - - for (i = 2; i < 8; i++) - { - if (!HexStringToUInt(guidStr, 8, &pGuid->Data4[i])) - return FALSE; - guidStr += 2; - } - - if (*guidStr++ != '}') - return FALSE; - - return TRUE; -} - - - -DWORD FindNextDevice(HDEVINFO devInfoSet, SP_DEVINFO_DATA* pDevInfoData, DWORD* pIndex) -{ - DWORD buffersize = 0; - LPTSTR buffer = NULL; - DWORD dataType; - DWORD result; - - - while (1) - { - if (!SetupDiEnumDeviceInfo(devInfoSet, (*pIndex)++, pDevInfoData)) - { - result = GetLastError(); - break; - } - - GetDeviceRegistryProperty: - if (!SetupDiGetDeviceRegistryProperty(devInfoSet, pDevInfoData, SPDRP_HARDWAREID, - &dataType, (PBYTE)buffer, buffersize, - &buffersize)) - { - result = GetLastError(); - - if (result == ERROR_INSUFFICIENT_BUFFER) - { - if (buffer != NULL) - LocalFree(buffer); - - buffer = (LPTSTR)LocalAlloc(LPTR, buffersize); - - if (buffer == NULL) - break; - - goto GetDeviceRegistryProperty; - } - else if (result == ERROR_INVALID_DATA) - continue; // ignore invalid entries - else - break; // break on other errors - } - - if (lstrcmpi(buffer, hwIdBuf) == 0) - { - result = 0; - break; - } - } - - if (buffer != NULL) - LocalFree(buffer); - - return result; -} - - - -DWORD FindFirstDevice(HWND hwndParent, const GUID* pDevClass, const LPTSTR hwId, - HDEVINFO* pDevInfoSet, SP_DEVINFO_DATA* pDevInfoData, - DWORD *pIndex, DWORD flags) -{ - DWORD result; - - - *pDevInfoSet = SetupDiGetClassDevs((GUID*)pDevClass, NULL, hwndParent, flags); - if (*pDevInfoSet == INVALID_HANDLE_VALUE) - return GetLastError(); - - pDevInfoData->cbSize = sizeof(SP_DEVINFO_DATA); - *pIndex = 0; - - result = FindNextDevice(*pDevInfoSet, pDevInfoData, pIndex); - - if (result != 0) - SetupDiDestroyDeviceInfoList(*pDevInfoSet); - - return result; -} - - - -/* - * InstDrv::InitDriverSetup devClass drvHWID - * - * devClass - GUID of the driver's device setup class - * drvHWID - Hardware ID of the supported device - * - * Return: - * result - error message, empty on success - */ -void __declspec(dllexport) InitDriverSetup(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) -{ - EXDLL_INIT(); - - /* convert class GUID */ - popstring(paramBuf); - - if (!StringToGUID(paramBuf, &devClass)) - { - popstring(paramBuf); - pushstring("Invalid GUID!"); - return; - } - - /* get hardware ID */ - memset(hwIdBuf, 0, sizeof(hwIdBuf)); - popstring(hwIdBuf); - - initialized = 1; - pushstring(""); -} - - - -/* - * InstDrv::CountDevices - * - * Return: - * result - Number of installed devices the driver supports - */ -void __declspec(dllexport) CountDevices(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) -{ - HDEVINFO devInfoSet; - SP_DEVINFO_DATA devInfoData; - int count = 0; - char countBuf[16]; - DWORD index; - DWORD result; - - - EXDLL_INIT(); - - if (!initialized) - { - pushstring("Fatal error!"); - return; - } - - result = FindFirstDevice(hwndParent, &devClass, hwIdBuf, &devInfoSet, &devInfoData, - &index, DIGCF_PRESENT); - if (result != 0) - { - pushstring("0"); - return; - } - - do - { - count++; - } while (FindNextDevice(devInfoSet, &devInfoData, &index) == 0); - - SetupDiDestroyDeviceInfoList(devInfoSet); - - wsprintf(countBuf, "%d", count); - pushstring(countBuf); -} - - - -/* - * InstDrv::CreateDevice - * - * Return: - * result - Windows error code - */ -void __declspec(dllexport) CreateDevice(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) -{ - HDEVINFO devInfoSet; - SP_DEVINFO_DATA devInfoData; - DWORD result = 0; - char resultBuf[16]; - - - EXDLL_INIT(); - - if (!initialized) - { - pushstring("Fatal error!"); - return; - } - - devInfoSet = SetupDiCreateDeviceInfoList(&devClass, hwndParent); - if (devInfoSet == INVALID_HANDLE_VALUE) - { - wsprintf(resultBuf, "%08X", GetLastError()); - pushstring(resultBuf); - return; - } - - devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); - if (!SetupDiCreateDeviceInfo(devInfoSet, hwIdBuf, &devClass, NULL, - hwndParent, DICD_GENERATE_ID, &devInfoData)) - { - result = GetLastError(); - goto InstallCleanup; - } - - if (!SetupDiSetDeviceRegistryProperty(devInfoSet, &devInfoData, SPDRP_HARDWAREID, - hwIdBuf, (lstrlen(hwIdBuf)+2)*sizeof(TCHAR))) - { - result = GetLastError(); - goto InstallCleanup; - } - - if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, devInfoSet, &devInfoData)) - result = GetLastError(); - - InstallCleanup: - SetupDiDestroyDeviceInfoList(devInfoSet); - - wsprintf(resultBuf, "%08X", result); - pushstring(resultBuf); -} - - - -/* - * InstDrv::InstallDriver infPath - * - * Return: - * result - Windows error code - * reboot - non-zero if reboot is required - */ -void __declspec(dllexport) InstallDriver(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) -{ - char resultBuf[16]; - BOOL reboot; - - - EXDLL_INIT(); - popstring(paramBuf); - - if (!initialized) - { - pushstring("Fatal error!"); - return; - } - - if (!UpdateDriverForPlugAndPlayDevices(hwndParent, hwIdBuf, paramBuf, - INSTALLFLAG_FORCE, &reboot)) - { - wsprintf(resultBuf, "%08X", GetLastError()); - pushstring(resultBuf); - } - else - { - wsprintf(resultBuf, "%d", reboot); - pushstring(resultBuf); - pushstring("00000000"); - } -} - - - -/* - * InstDrv::DeleteOemInfFiles - * - * Return: - * result - Windows error code - * oeminf - Path of the deleted devices setup file (oemXX.inf) - * oempnf - Path of the deleted devices setup file (oemXX.pnf) - */ -void __declspec(dllexport) DeleteOemInfFiles(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) -{ - HDEVINFO devInfo; - SP_DEVINFO_DATA devInfoData; - SP_DRVINFO_DATA drvInfoData; - SP_DRVINFO_DETAIL_DATA drvInfoDetail; - DWORD index; - DWORD result; - char resultBuf[16]; - - - if (!initialized) - { - pushstring("Fatal error!"); - return; - } - - result = FindFirstDevice(NULL, &devClass, hwIdBuf, &devInfo, &devInfoData, &index, 0); - if (result != 0) - goto Cleanup1; - - if (!SetupDiBuildDriverInfoList(devInfo, &devInfoData, SPDIT_COMPATDRIVER)) - { - result = GetLastError(); - goto Cleanup2; - } - - drvInfoData.cbSize = sizeof(SP_DRVINFO_DATA); - drvInfoDetail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA); - - if (!SetupDiEnumDriverInfo(devInfo, &devInfoData, SPDIT_COMPATDRIVER, 0, &drvInfoData)) - { - result = GetLastError(); - goto Cleanup3; - } - - if (!SetupDiGetDriverInfoDetail(devInfo, &devInfoData, &drvInfoData, - &drvInfoDetail, sizeof(drvInfoDetail), NULL)) - { - result = GetLastError(); - - if (result != ERROR_INSUFFICIENT_BUFFER) - goto Cleanup3; - - result = 0; - } - - pushstring(drvInfoDetail.InfFileName); - if (!DeleteFile(drvInfoDetail.InfFileName)) - result = GetLastError(); - else - { - index = lstrlen(drvInfoDetail.InfFileName); - if (index > 3) - { - lstrcpy(drvInfoDetail.InfFileName+index-3, "pnf"); - pushstring(drvInfoDetail.InfFileName); - if (!DeleteFile(drvInfoDetail.InfFileName)) - result = GetLastError(); - } - } - - Cleanup3: - SetupDiDestroyDriverInfoList(devInfo, &devInfoData, SPDIT_COMPATDRIVER); - - Cleanup2: - SetupDiDestroyDeviceInfoList(devInfo); - - Cleanup1: - wsprintf(resultBuf, "%08X", result); - pushstring(resultBuf); -} - - - -/* - * InstDrv::RemoveAllDevices - * - * Return: - * result - Windows error code - * reboot - non-zero if reboot is required - */ -void __declspec(dllexport) RemoveAllDevices(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) -{ - HDEVINFO devInfo; - SP_DEVINFO_DATA devInfoData; - DWORD index; - DWORD result; - char resultBuf[16]; - BOOL reboot = FALSE; - SP_DEVINSTALL_PARAMS instParams; - - - EXDLL_INIT(); - - if (!initialized) - { - pushstring("Fatal error!"); - return; - } - - result = FindFirstDevice(NULL, &devClass, hwIdBuf, &devInfo, &devInfoData, &index, 0); - if (result != 0) - goto Cleanup1; - - do - { - if (!SetupDiCallClassInstaller(DIF_REMOVE, devInfo, &devInfoData)) - { - result = GetLastError(); - break; - } - - instParams.cbSize = sizeof(instParams); - if (!reboot && - SetupDiGetDeviceInstallParams(devInfo, &devInfoData, &instParams) && - ((instParams.Flags & (DI_NEEDRESTART|DI_NEEDREBOOT)) != 0)) - { - reboot = TRUE; - } - - result = FindNextDevice(devInfo, &devInfoData, &index); - } while (result == 0); - - SetupDiDestroyDeviceInfoList(devInfo); - - Cleanup1: - if ((result == 0) || (result == ERROR_NO_MORE_ITEMS)) - { - wsprintf(resultBuf, "%d", reboot); - pushstring(resultBuf); - pushstring("00000000"); - } - else - { - wsprintf(resultBuf, "%08X", result); - pushstring(resultBuf); - } -} - - - -/* - * InstDrv::StartSystemService serviceName - * - * Return: - * result - Windows error code - */ -void __declspec(dllexport) StartSystemService(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) -{ - SC_HANDLE managerHndl; - SC_HANDLE svcHndl; - SERVICE_STATUS svcStatus; - DWORD oldCheckPoint; - DWORD result; - char resultBuf[16]; - - - EXDLL_INIT(); - popstring(paramBuf); - - managerHndl = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if (managerHndl == NULL) - { - result = GetLastError(); - goto Cleanup1; - } - - svcHndl = OpenService(managerHndl, paramBuf, SERVICE_START | SERVICE_QUERY_STATUS); - if (svcHndl == NULL) - { - result = GetLastError(); - goto Cleanup2; - } - - if (!StartService(svcHndl, 0, NULL) || !QueryServiceStatus(svcHndl, &svcStatus)) - { - result = GetLastError(); - goto Cleanup3; - } - - while (svcStatus.dwCurrentState == SERVICE_START_PENDING) - { - oldCheckPoint = svcStatus.dwCheckPoint; - - Sleep(svcStatus.dwWaitHint); - - if (!QueryServiceStatus(svcHndl, &svcStatus)) - { - result = GetLastError(); - break; - } - - if (oldCheckPoint >= svcStatus.dwCheckPoint) - { - if ((svcStatus.dwCurrentState == SERVICE_STOPPED) && - (svcStatus.dwWin32ExitCode != 0)) - result = svcStatus.dwWin32ExitCode; - else - result = ERROR_SERVICE_REQUEST_TIMEOUT; - } - } - - if (svcStatus.dwCurrentState == SERVICE_RUNNING) - result = 0; - - Cleanup3: - CloseServiceHandle(svcHndl); - - Cleanup2: - CloseServiceHandle(managerHndl); - - Cleanup1: - wsprintf(resultBuf, "%08X", result); - pushstring(resultBuf); -} - - - -/* - * InstDrv::StopSystemService serviceName - * - * Return: - * result - Windows error code - */ -void __declspec(dllexport) StopSystemService(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) -{ - SC_HANDLE managerHndl; - SC_HANDLE svcHndl; - SERVICE_STATUS svcStatus; - DWORD oldCheckPoint; - DWORD result; - char resultBuf[16]; - - - EXDLL_INIT(); - popstring(paramBuf); - - managerHndl = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if (managerHndl == NULL) - { - result = GetLastError(); - goto Cleanup1; - } - - svcHndl = OpenService(managerHndl, paramBuf, SERVICE_STOP | SERVICE_QUERY_STATUS); - if (svcHndl == NULL) - { - result = GetLastError(); - goto Cleanup2; - } - - if (!ControlService(svcHndl, SERVICE_CONTROL_STOP, &svcStatus)) - { - result = GetLastError(); - goto Cleanup3; - } - - while (svcStatus.dwCurrentState == SERVICE_STOP_PENDING) - { - oldCheckPoint = svcStatus.dwCheckPoint; - - Sleep(svcStatus.dwWaitHint); - - if (!QueryServiceStatus(svcHndl, &svcStatus)) - { - result = GetLastError(); - break; - } - - if (oldCheckPoint >= svcStatus.dwCheckPoint) - { - result = ERROR_SERVICE_REQUEST_TIMEOUT; - break; - } - } - - if (svcStatus.dwCurrentState == SERVICE_STOPPED) - result = 0; - - Cleanup3: - CloseServiceHandle(svcHndl); - - Cleanup2: - CloseServiceHandle(managerHndl); - - Cleanup1: - wsprintf(resultBuf, "%08X", result); - pushstring(resultBuf); -} - - - -BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) -{ - return TRUE; -} diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp deleted file mode 100644 index 874e66c7..00000000 --- a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp +++ /dev/null @@ -1,110 +0,0 @@ -# Microsoft Developer Studio Project File - Name="InstDrv" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** NICHT BEARBEITEN ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=InstDrv - Win32 Debug -!MESSAGE Dies ist kein gltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE -!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und fhren Sie den Befehl -!MESSAGE -!MESSAGE NMAKE /f "InstDrv.mak". -!MESSAGE -!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben -!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: -!MESSAGE -!MESSAGE NMAKE /f "InstDrv.mak" CFG="InstDrv - Win32 Debug" -!MESSAGE -!MESSAGE Fr die Konfiguration stehen zur Auswahl: -!MESSAGE -!MESSAGE "InstDrv - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library") -!MESSAGE "InstDrv - Win32 Debug" (basierend auf "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "InstDrv - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O1 /I "C:\Programme\WINDDK\3790\inc\ddk\w2k" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /FD /c -# SUBTRACT CPP /YX -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x407 /d "NDEBUG" -# ADD RSC /l 0x407 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib setupapi.lib newdev.lib /nologo /entry:"_DllMainCRTStartup" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/InstDrv.dll" /libpath:"C:\Programme\WINDDK\3790\lib\w2k\i386" /opt:nowin98 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "InstDrv - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x407 /d "_DEBUG" -# ADD RSC /l 0x407 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"_DllMainCRTStartup" /dll /debug /machine:I386 /pdbtype:sept -# SUBTRACT LINK32 /nodefaultlib - -!ENDIF - -# Begin Target - -# Name "InstDrv - Win32 Release" -# Name "InstDrv - Win32 Debug" -# Begin Group "Quellcodedateien" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\InstDrv.c -# End Source File -# End Group -# Begin Group "Header-Dateien" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Ressourcendateien" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw deleted file mode 100644 index b3d02f0e..00000000 --- a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELSCHT WERDEN! - -############################################################################### - -Project: "InstDrv"=.\InstDrv.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt deleted file mode 100644 index e5877aa6..00000000 --- a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt +++ /dev/null @@ -1,141 +0,0 @@ -InstDrv.dll version 0.2 - Installs or Removes Device Drivers ------------------------------------------------------------- - - -The plugin helps you to create NSIS scripts for installing device drivers or -removing them again. It can count installed device instances, create new ones -or delete all supported device. InstDrv works on Windows 2000 or later. - - - -InstDrv::InitDriverSetup devClass drvHWID -Return: result - -To start processing a driver, first call this function. devClass is the GUID -of the device class the driver supports, drvHWID is the device hardware ID. If -you don't know what these terms mean, you may want to take a look at the -Windows DDK. This function returns an empty string on success, otherwise an -error message. - -InitDriverSetup has to be called every time after the plugin dll has been -(re-)loaded, or if you want to switch to a different driver. - - - -InstDrv::CountDevices -Return: number - -This call returns the number of installed and supported devices of the driver. - - - -InstDrv::CreateDevice -Return: result - -To create a new deviced node which the driver has to support, use this -function. You may even call it multiple times for more than one instance. The -return value is the Windows error code (in hex). Use CreateDevice before -installing or updating the driver itself. - - - -InstDrv::InstallDriver infPath -Return: result - reboot - -InstallDriver installs or updates a device driver as specified in the .inf -setup script. It returns a Windows error code (in hex) and, on success, a flag -signalling if a system reboot is required. - - - -InstDrv::DeleteOemInfFiles -Return: result - oeminf - oempnf - -DeleteOemInfFiles tries to clean up the Windows inf directory by deleting the -oemXX.inf and oemXX.pnf files associated with the drivers. It returns a -Windows error code (in hex) and, on success, the names of the deleted files. -This functions requires that at least one device instance is still present. -So, call it before you remove the devices itself. You should also call it -before updating a driver. This avoids that the inf directory gets slowly -messed up with useless old setup scripts (which does NOT really accelerate -Windows). The error code which comes up when no device is installed is -"00000103". - - - -InstDrv::RemoveAllDevices -Return: result - reboot - -This functions deletes all devices instances the driver supported. It returns -a Windows error code (in hex) and, on success, a flag signalling if the system -needs to be rebooted. You additionally have to remove the driver binaries from -the system paths. - - - -InstDrv::StartSystemService serviceName -Return: result - -Call this function to start the provided system service. The function blocks -until the service is started or the system reported a timeout. The return value -is the Windows error code (in hex). - - - -InstDrv::StopSystemService serviceName -Return: result - -This function tries to stop the provided system service. It blocks until the -service has been shut down or the system reported a timeout. The return value -is the Windows error code (in hex). - - - -Example.nsi - -The example script installs or removes the virtual COM port driver of IrCOMM2k -(2.0.0-alpha8, see www.ircomm2k.de/english). The driver and its setup script -are only included for demonstration purposes, they do not work without the -rest of IrCOMM2k (but they also do not cause any harm). - - - -Building the Source Code - -To build the plugin from the source code, some include files and libraries -which come with the Windows DDK are required. - - - -History - - 0.2 - fixed bug when calling InitDriverSetup the second time - - added StartSystemService and StopSystemService - - 0.1 - first release - - - -License - -Copyright 2003 Jan Kiszka (Jan.Kiszka@web.de) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute -it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; - you must not claim that you wrote the original software. - If you use this software in a product, an acknowledgment in the - product documentation would be appreciated but is not required. -2. Altered versions must be plainly marked as such, - and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any distribution. diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf deleted file mode 100644 index ccda1d87..00000000 --- a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf +++ /dev/null @@ -1,137 +0,0 @@ -; IrCOMM2k.inf -; -; Installation file for the Virtual Infrared-COM-Port -; -; (c) Copyright 2001, 2002 Jan Kiszka -; - -[Version] -Signature="$Windows NT$" -Provider=%JK% -Class=Ports -ClassGUID={4d36e978-e325-11ce-bfc1-08002be10318} -;DriverVer=03/26/2002,1.2.1.0 - -[DestinationDirs] -IrCOMM2k.Copy2Drivers = 12 -IrCOMM2k.Copy2Winnt = 10 -IrCOMM2k.Copy2System32 = 11 -IrCOMM2k.Copy2Help = 18 - - -; -; Driver information -; - -[Manufacturer] -%JK% = JK.Mfg - -[JK.Mfg] -%JK.DeviceDescIrCOMM% = IrCOMM2k_inst,IrCOMM2k - - -; -; General installation section -; - -[IrCOMM2k_inst] -CopyFiles = IrCOMM2k.Copy2Drivers ;,IrCOMM2k.Copy2System32,IrCOMM2k.Copy2Help,IrCOMM2k.Copy2Winnt -;AddReg = IrCOMM2k_inst_AddReg - - -; -; File sections -; - -[IrCOMM2k.Copy2Drivers] -ircomm2k.sys,,,2 - -;[IrCOMM2k.Copy2System32] -;ircomm2k.exe,,,2 -;ircomm2k.dll,,,2 - -;[IrCOMM2k.Copy2Help] -;ircomm2k.hlp,,,2 - -;[IrCOMM2k.Copy2Winnt] -;IrCOMM2k-Setup.exe,Setup.exe,,2 - - -; -; Service Installation -; - -[IrCOMM2k_inst.Services] -AddService = IrCOMM2k,0x00000002,IrCOMM2k_DriverService_Inst,IrCOMM2k_DriverEventLog_Inst -;AddService = IrCOMM2kSvc,,IrCOMM2k_Service_Inst - -[IrCOMM2k_DriverService_Inst] -DisplayName = %IrCOMM2k.DrvName% -ServiceType = 1 ; SERVICE_KERNEL_DRIVER -StartType = 3 ; SERVICE_DEMAND_START -ErrorControl = 0 ; SERVICE_ERROR_IGNORE -ServiceBinary = %12%\ircomm2k.sys - -;[IrCOMM2k_Service_Inst] -;DisplayName = %IrCOMM2k.SvcName% -;Description = %IrCOMM2k.SvcDesc% -;ServiceType = 0x00000120 ; SERVICE_WIN32_SHARE_PROCESS, SERVICE_INTERACTIVE_PROCESS -;StartType = 2 ; SERVICE_AUTO_START -;ErrorControl = 0 ; SERVICE_ERROR_IGNORE -;ServiceBinary = %11%\ircomm2k.exe -;Dependencies = IrCOMM2k -;AddReg = IrCOMM2kSvcAddReg - - -[IrCOMM2k_inst.nt.HW] -AddReg=IrCOMM2kHwAddReg - -[IrCOMM2kHwAddReg] -HKR,,PortSubClass,REG_BINARY,0x00000001 -;HKR,,TimeoutScaling,REG_DWORD,0x00000001 -;HKR,,StatusLines,REG_DWORD,0x00000000 - -;[IrCOMM2k_inst_AddReg] -;HKR,,EnumPropPages32,,"ircomm2k.dll,IrCOMM2kPropPageProvider" -;HKLM,%UNINSTALL_KEY%,DisplayIcon,0x00020000,"%windir%\IrCOMM2k-Setup.exe" -;HKLM,%UNINSTALL_KEY%,DisplayName,,"IrCOMM2k 1.2.1 " -;HKLM,%UNINSTALL_KEY%,DisplayVersion,,"1.2.1" -;HKLM,%UNINSTALL_KEY%,HelpLink,,"http://www.ircomm2k.de" -;HKLM,%UNINSTALL_KEY%,Publisher,,%JK% -;HKLM,%UNINSTALL_KEY%,UninstallString,0x00020000,"%windir%\IrCOMM2k-Setup.exe" - -;[IrCOMM2kSvcAddReg] -;HKR,Parameters,ActiveConnectOnly,REG_DWORD,0x00000000 - - -[IrCOMM2k_DriverEventLog_Inst] -AddReg = IrCOMM2k_DriverEventLog_AddReg - -[IrCOMM2k_DriverEventLog_AddReg] -HKR,,EventMessageFile,REG_EXPAND_SZ,"%SystemRoot%\System32\IoLogMsg.dll;%SystemRoot%\System32\drivers\ircomm2k.sys" -HKR,,TypesSupported,REG_DWORD,7 - - -[Strings] - -; -; Non-Localizable Strings -; - -REG_SZ = 0x00000000 -REG_MULTI_SZ = 0x00010000 -REG_EXPAND_SZ = 0x00020000 -REG_BINARY = 0x00000001 -REG_DWORD = 0x00010001 -SERVICEROOT = "System\CurrentControlSet\Services" -UNINSTALL_KEY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrCOMM2k" - -; -; Localizable Strings -; - -JK = "Jan Kiszka" -JK.DeviceDescIrCOMM = "Virtueller Infrarot-Kommunikationsanschluss" -IrCOMM2k.DrvName = "Virtueller Infrarot-Kommunikationsanschluss" -;IrCOMM2k.SvcName = "Virtueller Infrarot-Kommunikationsanschlu, Dienstprogramm" -;IrCOMM2k.SvcDesc = "Bildet ber Infarot einen Kommunikationsanschlu nach." diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys deleted file mode 100644 index 7882583b..00000000 Binary files a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys and /dev/null differ diff --git a/ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll b/ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll deleted file mode 100644 index 482e955e..00000000 Binary files a/ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll and /dev/null differ diff --git a/ao-tools/altosui/Makefile-standalone b/ao-tools/altosui/Makefile-standalone deleted file mode 100644 index a95a5aa8..00000000 --- a/ao-tools/altosui/Makefile-standalone +++ /dev/null @@ -1,184 +0,0 @@ -.SUFFIXES: .java .class - -CLASSPATH=classes:./*:/usr/share/java/* -CLASSFILES=\ - Altos.class \ - AltosChannelMenu.class \ - AltosConfig.class \ - AltosConfigUI.class \ - AltosConvert.class \ - AltosCRCException.class \ - AltosCSV.class \ - AltosCSVUI.class \ - AltosDebug.class \ - AltosEepromDownload.class \ - AltosEepromMonitor.class \ - AltosEepromReader.class \ - AltosEepromRecord.class \ - AltosFile.class \ - AltosFlash.class \ - AltosFlashUI.class \ - AltosFlightInfoTableModel.class \ - AltosFlightStatusTableModel.class \ - AltosGPS.class \ - AltosGreatCircle.class \ - AltosHexfile.class \ - AltosLine.class \ - AltosInfoTable.class \ - AltosLog.class \ - AltosLogfileChooser.class \ - AltosParse.class \ - AltosPreferences.class \ - AltosReader.class \ - AltosRecord.class \ - AltosSerialMonitor.class \ - AltosSerial.class \ - AltosState.class \ - AltosStatusTable.class \ - AltosTelemetry.class \ - AltosTelemetryReader.class \ - AltosUI.class \ - AltosDevice.class \ - AltosDeviceDialog.class \ - AltosRomconfig.class \ - AltosRomconfigUI.class \ - AltosVoice.class - -JAVA_ICON=../../icon/altus-metrum-16x16.jpg -WINDOWS_ICON=../../icon/altus-metrum.ico - -# where altosui.jar gets installed -ALTOSLIB=/usr/share/java - -# where freetts.jar is to be found -FREETTSLIB=/usr/share/java - -# all of the freetts files -FREETTSJAR= \ - $(FREETTSLIB)/cmudict04.jar \ - $(FREETTSLIB)/cmulex.jar \ - $(FREETTSLIB)/cmu_time_awb.jar \ - $(FREETTSLIB)/cmutimelex.jar \ - $(FREETTSLIB)/cmu_us_kal.jar \ - $(FREETTSLIB)/en_us.jar \ - $(FREETTSLIB)/freetts.jar - -# The current hex files -HEXLIB=../../src -HEXFILES = \ - $(HEXLIB)/telemetrum-v1.0.ihx \ - $(HEXLIB)/teledongle-v0.2.ihx - -JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation - -ALTOSUIJAR = altosui.jar -FATJAR = fat/altosui.jar - -OS:=$(shell uname) - -LINUX_APP=altosui - -DARWIN_ZIP=Altos-Mac.zip - -WINDOWS_EXE=Altos-Windows.exe - -LINUX_TGZ=Altos-Linux.tgz - -all: altosui.jar $(LINUX_APP) -fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) - -$(CLASSFILES): - -.java.class: - javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java - -altosui.jar: classes/images classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt - cd ./classes && jar cfm ../$@ altosui/Manifest.txt images/* altosui/*.class libaltosJNI/*.class - -Manifest.txt: Makefile $(CLASSFILES) - echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTSLIB)/freetts.jar" >> $@ - -classes/altosui: - mkdir -p classes - ln -sf .. classes/altosui - -classes/libaltosJNI: - mkdir -p classes - ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI - -classes/images: - mkdir -p classes/images - ln -sf ../../$(JAVA_ICON) classes/images - -altosui: - echo "#!/bin/sh" > $@ - echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ - chmod +x ./altosui - -fat/altosui: - echo "#!/bin/sh" > $@ - echo 'ME=`which "$0"`' >> $@ - echo 'DIR=`dirname "$ME"`' >> $@ - echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ - chmod +x $@ - -fat/altosui.jar: $(CLASSFILES) $(JAVA_ICON) fat/classes/Manifest.txt - mkdir -p fat/classes - test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui - mkdir -p fat/classes/images - cp $(JAVA_ICON) fat/classes/images - test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI - cd ./fat/classes && jar cfm ../../$@ Manifest.txt images/* altosui/*.class libaltosJNI/*.class - -fat/classes/Manifest.txt: $(CLASSFILES) Makefile - mkdir -p fat/classes - echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: freetts.jar" >> $@ - -install: altosui.jar altosui - install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar - install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 - install altosui $(DESTDIR)/usr/bin/altosui - -clean: - rm -f *.class altosui.jar - rm -f AltosUI.app/Contents/Resources/Java/* - rm -rf classes - rm -rf windows linux - -distclean: clean - rm -f $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) - rm -rf darwin fat - -FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) - -LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui -$(LINUX_TGZ): $(LINUX_FILES) - rm -f $@ - mkdir -p linux/AltOS - rm -f linux/AltOS/* - cp $(LINUX_FILES) linux/AltOS - cd linux && tar czf ../$@ AltOS - -DARWIN_RESOURCES=$(FATJAR) $(FREETTSJAR) ../libaltos/libaltos.dylib -DARWIN_EXTRA=$(HEXFILES) -DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) - -$(DARWIN_ZIP): $(DARWIN_FILES) - rm -f $@ - cp -a AltosUI.app darwin/ - mkdir -p darwin/AltosUI.app/Contents/Resources/Java - cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java - mkdir -p darwin/AltOS - cp $(DARWIN_EXTRA) darwin/AltOS - cd darwin && zip -r ../$@ AltosUI.app AltOS - -WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ICON) - -$(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi - rm -f $@ - mkdir -p windows/AltOS - rm -f windows/AltOS/* - cp $(WINDOWS_FILES) windows/AltOS - makensis altos-windows.nsi diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am deleted file mode 100644 index 93a43b12..00000000 --- a/ao-tools/altosui/Makefile.am +++ /dev/null @@ -1,271 +0,0 @@ -JAVAROOT=classes -AM_JAVACFLAGS=-encoding UTF-8 - -man_MANS=altosui.1 - -altoslibdir=$(libdir)/altos - -CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" - -bin_SCRIPTS=altosui - -altosui_JAVA = \ - GrabNDrag.java \ - AltosAscent.java \ - AltosChannelMenu.java \ - AltosConfig.java \ - AltosConfigUI.java \ - AltosConfigureUI.java \ - AltosConvert.java \ - AltosCRCException.java \ - AltosCSV.java \ - AltosCSVUI.java \ - AltosDebug.java \ - AltosDescent.java \ - AltosDeviceDialog.java \ - AltosDevice.java \ - AltosDisplayThread.java \ - AltosEepromDownload.java \ - AltosEepromMonitor.java \ - AltosEepromIterable.java \ - AltosEepromRecord.java \ - AltosFile.java \ - AltosFlash.java \ - AltosFlashUI.java \ - AltosFlightDisplay.java \ - AltosFlightInfoTableModel.java \ - AltosFlightReader.java \ - AltosFlightStatus.java \ - AltosFlightUI.java \ - AltosGPS.java \ - AltosGreatCircle.java \ - AltosHexfile.java \ - Altos.java \ - AltosIgnite.java \ - AltosIgniteUI.java \ - AltosInfoTable.java \ - AltosKML.java \ - AltosLanded.java \ - AltosLed.java \ - AltosLights.java \ - AltosLine.java \ - AltosLog.java \ - AltosPad.java \ - AltosParse.java \ - AltosPreferences.java \ - AltosReader.java \ - AltosRecord.java \ - AltosRecordIterable.java \ - AltosTelemetryReader.java \ - AltosReplayReader.java \ - AltosRomconfig.java \ - AltosRomconfigUI.java \ - AltosSerial.java \ - AltosSerialInUseException.java \ - AltosSerialMonitor.java \ - AltosSiteMap.java \ - AltosSiteMapCache.java \ - AltosSiteMapTile.java \ - AltosState.java \ - AltosTelemetry.java \ - AltosTelemetryIterable.java \ - AltosUI.java \ - AltosWriter.java \ - AltosDataPointReader.java \ - AltosDataPoint.java \ - AltosGraph.java \ - AltosGraphTime.java \ - AltosGraphUI.java \ - AltosDataChooser.java \ - AltosVoice.java - -JFREECHART_CLASS= \ - jfreechart.jar - -JCOMMON_CLASS=\ - jcommon.jar - -FREETTS_CLASS= \ - cmudict04.jar \ - cmulex.jar \ - cmu_time_awb.jar \ - cmutimelex.jar \ - cmu_us_kal.jar \ - en_us.jar \ - freetts.jar - -LIBALTOS= \ - libaltos.so \ - libaltos.dylib \ - altos.dll - -JAR=altosui.jar - -FATJAR=altosui-fat.jar - -# Icons -ICONDIR=$(top_srcdir)/icon - -JAVA_ICON=$(ICONDIR)/altus-metrum-16x16.jpg - -ICONS= $(ICONDIR)/redled.png $(ICONDIR)/redoff.png \ - $(ICONDIR)/greenled.png $(ICONDIR)/greenoff.png \ - $(ICONDIR)/grayled.png $(ICONDIR)/grayoff.png - -# icon base names for jar -ICONJAR= -C $(ICONDIR) altus-metrum-16x16.jpg \ - -C $(ICONDIR) redled.png -C $(ICONDIR) redoff.png \ - -C $(ICONDIR) greenled.png -C $(ICONDIR) greenoff.png \ - -C $(ICONDIR) grayon.png -C $(ICONDIR) grayled.png - -WINDOWS_ICON=$(ICONDIR)/altus-metrum.ico - -# Firmware -FIRMWARE_TD=$(top_srcdir)/src/teledongle-v0.2-$(VERSION).ihx -FIRMWARE_TM=$(top_srcdir)/src/telemetrum-v1.0-$(VERSION).ihx -FIRMWARE=$(FIRMWARE_TM) $(FIRMWARE_TD) - -# Distribution targets -LINUX_DIST=Altos-Linux-$(VERSION).tar.bz2 -MACOSX_DIST=Altos-Mac-$(VERSION).zip -WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe - -FAT_FILES=$(FATJAR) $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) - -LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) -LINUX_EXTRA=altosui-fat - -MACOSX_FILES=$(FAT_FILES) libaltos.dylib -MACOSX_EXTRA=$(FIRMWARE) - -WINDOWS_FILES=$(FAT_FILES) altos.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) - -all-local: classes/altosui $(JAR) altosui altosui-test altosui-jdb - -clean-local: - -rm -rf classes $(JAR) $(FATJAR) \ - $(LINUX_DIST) $(MACOSX_DIST) windows $(WINDOWS_DIST) $(FREETTS_CLASS) \ - $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ - altosui altosui-test altosui-jdb macosx linux - -if FATINSTALL - -FATTARGET=$(FATDIR)/$(VERSION) - -LINUX_DIST_TARGET=$(FATTARGET)/$(LINUX_DIST) -MACOSX_DIST_TARGET=$(FATTARGET)/$(MACOSX_DIST) -WINDOWS_DIST_TARGET=$(FATTARGET)/$(WINDOWS_DIST) - -fat: $(LINUX_DIST_TARGET) $(MACOSX_DIST_TARGET) $(WINDOWS_DIST_TARGET) - -$(LINUX_DIST_TARGET): $(LINUX_DIST) - mkdir -p $(FATTARGET) - cp -p $< $@ - -$(MACOSX_DIST_TARGET): $(MACOSX_DIST) - mkdir -p $(FATTARGET) - cp -p $< $@ - -$(WINDOWS_DIST_TARGET): $(WINDOWS_DIST) - mkdir -p $(FATTARGET) - cp -p $< $@ - -else -fat: $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) -endif - - -altosuidir=$(datadir)/java - -install-altosuiJAVA: altosui.jar - @$(NORMAL_INSTALL) - test -z "$(altosuidir)" || $(MKDIR_P) "$(DESTDIR)$(altosuidir)" - echo " $(INSTALL_DATA)" "$<" "'$(DESTDIR)$(altosuidir)/altosui.jar'"; \ - $(INSTALL_DATA) "$<" "$(DESTDIR)$(altosuidir)" - -classes/altosui: - mkdir -p classes/altosui - -$(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) - jar cfm $@ Manifest.txt \ - $(ICONJAR) \ - -C classes altosui \ - -C ../libaltos libaltosJNI - -$(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) $(JAVA_ICON) - jar cfm $@ Manifest-fat.txt \ - $(ICONJAR) \ - -C classes altosui \ - -C ../libaltos libaltosJNI - -Manifest.txt: Makefile - echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTS)/freetts.jar $(JFREECHART)/jfreechart.jar $(JCOMMON)/jcommon.jar" >> $@ - -Manifest-fat.txt: - echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: freetts.jar jfreechart.jar jcommon.jar" >> $@ - -altosui: Makefile - echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="$(altoslibdir)" -jar "$(altosuidir)/altosui.jar" "$$@"' >> $@ - chmod +x $@ - -altosui-test: Makefile - echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="../libaltos/.libs" -jar altosui.jar "$$@"' >> $@ - chmod +x $@ - -altosui-jdb: Makefile - echo "#!/bin/sh" > $@ - echo 'exec jdb -classpath "classes:../libaltos:$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="../libaltos/.libs" altosui/AltosUI "$$@"' >> $@ - chmod +x $@ - -libaltos.so: - -rm -f "$@" - $(LN_S) ../libaltos/.libs/"$@" . - -libaltos.dylib: - -rm -f "$@" - $(LN_S) ../libaltos/"$@" . - -altos.dll: - -rm -f "$@" - $(LN_S) ../libaltos/"$@" . - -$(FREETTS_CLASS): - -rm -f "$@" - $(LN_S) "$(FREETTS)"/"$@" . - -$(JFREECHART_CLASS): - -rm -f "$@" - $(LN_S) "$(JFREECHART)"/"$@" . - -$(JCOMMON_CLASS): - -rm -f "$@" - $(LN_S) "$(JCOMMON)"/"$@" . - -$(LINUX_DIST): $(LINUX_FILES) $(LINUX_EXTRA) - -rm -f $@ - -rm -rf linux - mkdir -p linux/AltOS - cp -p $(LINUX_FILES) linux/AltOS - cp -p altosui-fat linux/AltOS/altosui - chmod +x linux/AltOS/altosui - tar cjf $@ -C linux AltOS - -$(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) - -rm -f $@ - -rm -rf macosx - mkdir macosx - cp -a AltosUI.app macosx/ - mkdir -p macosx/AltOS macosx/AltosUI.app/Contents/Resources/Java - cp -p $(FATJAR) macosx/AltosUI.app/Contents/Resources/Java/altosui.jar - cp -p $(FREETTS_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java - cp -p $(JFREECHART_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java - cp -p $(MACOSX_EXTRA) macosx/AltOS - cd macosx && zip -r ../$@ AltosUI.app AltOS - -$(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi - -rm -f $@ - makensis -Oaltos-windows.log "-XOutFile $@" "-DVERSION=$(VERSION)" altos-windows.nsi diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi deleted file mode 100644 index 37777fd6..00000000 --- a/ao-tools/altosui/altos-windows.nsi +++ /dev/null @@ -1,113 +0,0 @@ -!addplugindir Instdrv/NSIS/Plugins - -Name "Altus Metrum Installer" - -; Default install directory -InstallDir "$PROGRAMFILES\AltusMetrum" - -; Tell the installer where to re-install a new version -InstallDirRegKey HKLM "Software\AltusMetrum" "Install_Dir" - -LicenseText "GNU General Public License Version 2" -LicenseData "../../COPYING" - -; Need admin privs for Vista or Win7 -RequestExecutionLevel admin - -ShowInstDetails Show - -ComponentText "Altus Metrum Software and Driver Installer" - -; Pages to present - -Page license -Page components -Page directory -Page instfiles - -UninstPage uninstConfirm -UninstPage instfiles - -; And the stuff to install - -Section "Install Driver" InstDriver - InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} "Altus Metrum" - Pop $0 - DetailPrint "InitDriverSetup: $0" - - InstDrv::DeleteOemInfFiles /NOUNLOAD - InstDrv::CreateDevice /NOUNLOAD - SetOutPath $TEMP - File "../../telemetrum.inf" - InstDrv::InstallDriver /NOUNLOAD "$TEMP\telemetrum.inf" - - SetOutPath $INSTDIR - File "../../telemetrum.inf" -SectionEnd - -Section "AltosUI Application" - SetOutPath $INSTDIR - - File "altosui-fat.jar" - File "cmudict04.jar" - File "cmulex.jar" - File "cmu_time_awb.jar" - File "cmutimelex.jar" - File "cmu_us_kal.jar" - File "en_us.jar" - File "freetts.jar" - - File "*.dll" - - File "../../icon/*.ico" - - CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui-fat.jar" "" "$INSTDIR\altus-metrum.ico" -SectionEnd - -Section "AltosUI Desktop Shortcut" - CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui-fat.jar" "" "$INSTDIR\altus-metrum.ico" -SectionEnd - -Section "TeleMetrum and TeleDongle Firmware" - - SetOutPath $INSTDIR - - File "../../src/telemetrum-v1.0/telemetrum-v1.0-${VERSION}.ihx" - File "../../src/teledongle-v0.2/teledongle-v0.2-${VERSION}.ihx" - -SectionEnd - -Section "Uninstaller" - - ; Deal with the uninstaller - - SetOutPath $INSTDIR - - ; Write the install path to the registry - WriteRegStr HKLM SOFTWARE\AltusMetrum "Install_Dir" "$INSTDIR" - - ; Write the uninstall keys for windows - WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "DisplayName" "Altus Metrum" - WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "UninstallString" '"$INSTDIR\uninstall.exe"' - WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoModify" "1" - WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoRepair" "1" - - WriteUninstaller "uninstall.exe" -SectionEnd - -Section "Uninstall" - DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" - DeleteRegKey HKLM "Software\AltusMetrum" - - Delete "$INSTDIR\*.*" - RMDir "$INSTDIR" - - ; Remove devices - InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} "Altus Metrum" - InstDrv::DeleteOemInfFiles /NOUNLOAD - InstDrv::RemoveAllDevices - - ; Remove shortcuts, if any - Delete "$SMPROGRAMS\AltusMetrum.lnk" - Delete "$DESKTOP\AltusMetrum.lnk" -SectionEnd diff --git a/ao-tools/altosui/altosui-fat b/ao-tools/altosui/altosui-fat deleted file mode 100755 index 95b1c051..00000000 --- a/ao-tools/altosui/altosui-fat +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -me=`which "$0"` -dir=`dirname "$me"` -exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui-fat.jar "$@" diff --git a/ao-tools/altosui/altosui.1 b/ao-tools/altosui/altosui.1 deleted file mode 100644 index 57fa4489..00000000 --- a/ao-tools/altosui/altosui.1 +++ /dev/null @@ -1,46 +0,0 @@ -.\" -.\" Copyright © 2010 Bdale Garbee -.\" -.\" 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 ALTOSUI 1 "altosui" "" -.SH NAME -altosui \- Rocket flight monitor -.SH SYNOPSIS -.B "altosui" -.SH DESCRIPTION -.I altosui -connects to a TeleDongle or TeleMetrum device through a USB serial device. -It provides a menu-oriented -user interface to monitor, record and review rocket flight data. -.SH USAGE -When connected to a TeleDongle device, altosui turns on the radio -receiver and listens for telemetry packets. It displays the received -telemetry data, and reports flight status via voice synthesis. All -received telemetry information is recorded to a file. -.P -When connected to a TeleMetrum device, altosui can be used to configure the -TeleMetrum, and to downloads the eeprom data and store it in a file. -.P -A number of other menu options exist, including the ability to export flight -data in different formats. -.SH FILES -All data log files are recorded into a user-specified directory -(default ~/TeleMetrum). Files are named using the current date, the serial -number of the reporting device, the flight number recorded in the data -and either '.telem' for telemetry data or '.eeprom' for eeprom data. -.SH AUTHOR -Keith Packard diff --git a/ao-tools/altosui/altusmetrum.jpg b/ao-tools/altosui/altusmetrum.jpg deleted file mode 100644 index 04027921..00000000 Binary files a/ao-tools/altosui/altusmetrum.jpg and /dev/null differ diff --git a/ao-tools/libaltos/.gitignore b/ao-tools/libaltos/.gitignore deleted file mode 100644 index c490e6f8..00000000 --- a/ao-tools/libaltos/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -*.so -*.lo -*.la -*.java -*.class -.libs/ -classlibaltos.stamp -libaltos_wrap.c -libaltosJNI -cjnitest -libaltos.swig -swig_bindings/ diff --git a/ao-tools/libaltos/Makefile-standalone b/ao-tools/libaltos/Makefile-standalone deleted file mode 100644 index 4e438050..00000000 --- a/ao-tools/libaltos/Makefile-standalone +++ /dev/null @@ -1,126 +0,0 @@ -OS:=$(shell uname) - -# -# Linux -# -ifeq ($(OS),Linux) - -JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include - -OS_LIB_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) - -OS_APP_CFLAGS=$(OS_LIB_CFLAGS) - -OS_LDFLAGS= - -LIBNAME=libaltos.so -EXEEXT= -endif - -# -# Darwin (Mac OS X) -# -ifeq ($(OS),Darwin) - -OS_LIB_CFLAGS=\ - -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ - --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ - -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ - -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ - -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers -OS_APP_CFLAGS=$(OS_LIB_CFLAGS) - -OS_LDFLAGS =\ - -framework IOKit -framework CoreFoundation - -LIBNAME=libaltos.dylib -EXEEXT= - -endif - -# -# Windows -# -ifneq (,$(findstring MINGW,$(OS))) - -CC=gcc - -OS_LIB_CFLAGS = -DWINDOWS -mconsole -DBUILD_DLL -OS_APP_CFLAGS = -DWINDOWS -mconsole - -OS_LDFLAGS = -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lole32 \ - -ladvapi32 -lcomctl32 -mconsole -Wl,--add-stdcall-alias - -LIBNAME=altos.dll - -EXEEXT=.exe - -endif - -.SUFFIXES: .java .class - -CLASSPATH=".:jnitest/*:libaltosJNI:/usr/share/java/*" - -SWIG_DIR=swig_bindings/java -SWIG_FILE=$(SWIG_DIR)/libaltos.swig -SWIG_WRAP=$(SWIG_DIR)/libaltos_wrap.c - -JNI_DIR=libaltosJNI -JNI_FILE=$(JNI_DIR)/libaltosJNI.java -JNI_SRCS=$(JNI_FILE) \ - $(JNI_DIR)/SWIGTYPE_p_altos_file.java \ - $(JNI_DIR)/SWIGTYPE_p_altos_list.java \ - $(JNI_DIR)/altos_device.java \ - $(JNI_DIR)/libaltos.java - -JAVAFILES=\ - $(JNI_SRCS) - -CLASSFILES = $(JAVAFILES:%.java=%.class) - -JAVAFLAGS=-Xlint:unchecked - -CJNITEST=cjnitest$(EXEEXT) - -all: $(LIBNAME) $(CJNITEST) $(CLASSFILES) - -.java.class: - javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java - -CFLAGS=$(OS_LIB_CFLAGS) -O -I. - -LDFLAGS=$(OS_LDFLAGS) - -HEADERS=libaltos.h -SRCS = libaltos.c $(SWIG_WRAP) -OBJS = $(SRCS:%.c=%.o) -LIBS = $(DARWIN_LIBS) - -$(CJNITEST): cjnitest.c $(LIBNAME) - $(CC) -o $@ $(OS_APP_CFLAGS) cjnitest.c $(LIBNAME) $(LIBS) $(LDFLAGS) - -$(LIBNAME): $(OBJS) - $(CC) -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) - -clean: - rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o - rm -rf swig_bindings libaltosJNI - -distclean: clean - -$(JNI_FILE): libaltos.i0 $(HEADERS) - mkdir -p $(SWIG_DIR) - mkdir -p libaltosJNI - sed 's;//%;%;' libaltos.i0 $(HEADERS) > $(SWIG_FILE) - swig -java -package libaltosJNI $(SWIG_FILE) - cp swig_bindings/java/*.java libaltosJNI - -$(SWIG_WRAP): $(JNI_FILE) - -ifeq ($(OS),Linux) -install: $(LIBNAME) - install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) - -endif - -.NOTPARALLEL: diff --git a/ao-tools/libaltos/Makefile.am b/ao-tools/libaltos/Makefile.am deleted file mode 100644 index 388d2104..00000000 --- a/ao-tools/libaltos/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -JAVAC=javac -AM_CFLAGS=-DLINUX -DPOSIX_TTY -I$(JVM_INCLUDE) -AM_JAVACFLAGS=-encoding UTF-8 - -altoslibdir=$(libdir)/altos - -altoslib_LTLIBRARIES=libaltos.la - -libaltos_la_LDFLAGS = -version-info 1:0:1 - -libaltos_la_SOURCES=\ - libaltos.c \ - libaltos_wrap.c - -noinst_PROGRAMS=cjnitest - -cjnitest_LDADD=libaltos.la - -LIBS= - -HFILES=libaltos.h - -SWIG_FILE=libaltos.swig - -CLASSDIR=libaltosJNI - -$(SWIG_FILE): libaltos.i0 $(HFILES) - sed 's;//%;%;' libaltos.i0 $(HFILES) > $(SWIG_FILE) - -all-local: classlibaltos.stamp - -libaltos_wrap.c: classlibaltos.stamp - -classlibaltos.stamp: $(SWIG_FILE) - swig -java -package libaltosJNI $(SWIG_FILE) - mkdir -p libaltosJNI - $(JAVAC) -d . $(AM_JAVACFLAGS) $(JAVACFLAGS) *.java && \ - touch classlibaltos.stamp - -clean-local: - -rm -rf libaltosJNI *.class *.java classlibaltos.stamp $(SWIG_FILE) libaltos_wrap.c diff --git a/ao-tools/libaltos/altos.dll b/ao-tools/libaltos/altos.dll deleted file mode 100755 index 28e9b4ad..00000000 Binary files a/ao-tools/libaltos/altos.dll and /dev/null differ diff --git a/ao-tools/libaltos/cjnitest.c b/ao-tools/libaltos/cjnitest.c deleted file mode 100644 index c6d6e069..00000000 --- a/ao-tools/libaltos/cjnitest.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include "libaltos.h" - -static void -altos_puts(struct altos_file *file, char *string) -{ - char c; - - while ((c = *string++)) - altos_putchar(file, c); -} - -main () -{ - struct altos_device device; - struct altos_list *list; - - altos_init(); - list = altos_list_start(); - while (altos_list_next(list, &device)) { - struct altos_file *file; - int c; - - printf ("%04x:%04x %-20s %4d %s\n", device.vendor, device.product, - device.name, device.serial, device.path); - - file = altos_open(&device); - if (!file) { - printf("altos_open failed\n"); - continue; - } - altos_puts(file,"v\nc s\n"); - altos_flush(file); - while ((c = altos_getchar(file, 100)) >= 0) { - putchar (c); - } - if (c != LIBALTOS_TIMEOUT) - printf ("getchar returns %d\n", c); - altos_close(file); - } - altos_list_finish(list); - altos_fini(); -} diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c deleted file mode 100644 index 465f0ac8..00000000 --- a/ao-tools/libaltos/libaltos.c +++ /dev/null @@ -1,1028 +0,0 @@ -/* - * Copyright © 2010 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 "libaltos.h" -#include -#include -#include - -#define USE_POLL - -PUBLIC int -altos_init(void) -{ - return LIBALTOS_SUCCESS; -} - -PUBLIC void -altos_fini(void) -{ -} - -#ifdef DARWIN - -#undef USE_POLL - -/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */ -static char * -altos_strndup (const char *s, size_t n) -{ - size_t len = strlen (s); - char *ret; - - if (len <= n) - return strdup (s); - ret = malloc(n + 1); - strncpy(ret, s, n); - ret[n] = '\0'; - return ret; -} - -#else -#define altos_strndup strndup -#endif - -/* - * Scan for Altus Metrum devices by looking through /sys - */ - -#ifdef LINUX - -#define _GNU_SOURCE -#include -#include -#include -#include -#include - -static char * -cc_fullname (char *dir, char *file) -{ - char *new; - int dlen = strlen (dir); - int flen = strlen (file); - int slen = 0; - - if (dir[dlen-1] != '/') - slen = 1; - new = malloc (dlen + slen + flen + 1); - if (!new) - return 0; - strcpy(new, dir); - if (slen) - strcat (new, "/"); - strcat(new, file); - return new; -} - -static char * -cc_basename(char *file) -{ - char *b; - - b = strrchr(file, '/'); - if (!b) - return file; - return b + 1; -} - -static char * -load_string(char *dir, char *file) -{ - char *full = cc_fullname(dir, file); - char line[4096]; - char *r; - FILE *f; - int rlen; - - f = fopen(full, "r"); - free(full); - if (!f) - return NULL; - r = fgets(line, sizeof (line), f); - fclose(f); - if (!r) - return NULL; - rlen = strlen(r); - if (r[rlen-1] == '\n') - r[rlen-1] = '\0'; - return strdup(r); -} - -static int -load_hex(char *dir, char *file) -{ - char *line; - char *end; - long i; - - line = load_string(dir, file); - if (!line) - return -1; - i = strtol(line, &end, 16); - free(line); - if (end == line) - return -1; - return i; -} - -static int -load_dec(char *dir, char *file) -{ - char *line; - char *end; - long i; - - line = load_string(dir, file); - if (!line) - return -1; - i = strtol(line, &end, 10); - free(line); - if (end == line) - return -1; - return i; -} - -static int -dir_filter_tty_colon(const struct dirent *d) -{ - return strncmp(d->d_name, "tty:", 4) == 0; -} - -static int -dir_filter_tty(const struct dirent *d) -{ - return strncmp(d->d_name, "tty", 3) == 0; -} - -struct altos_usbdev { - char *sys; - char *tty; - char *manufacturer; - char *product_name; - int serial; /* AltOS always uses simple integer serial numbers */ - int idProduct; - int idVendor; -}; - -static char * -usb_tty(char *sys) -{ - char *base; - int num_configs; - int config; - struct dirent **namelist; - int interface; - int num_interfaces; - char endpoint_base[20]; - char *endpoint_full; - char *tty_dir; - int ntty; - char *tty; - - base = cc_basename(sys); - num_configs = load_hex(sys, "bNumConfigurations"); - num_interfaces = load_hex(sys, "bNumInterfaces"); - for (config = 1; config <= num_configs; config++) { - for (interface = 0; interface < num_interfaces; interface++) { - sprintf(endpoint_base, "%s:%d.%d", - base, config, interface); - endpoint_full = cc_fullname(sys, endpoint_base); - - /* Check for tty:ttyACMx style names - */ - ntty = scandir(endpoint_full, &namelist, - dir_filter_tty_colon, - alphasort); - if (ntty > 0) { - free(endpoint_full); - tty = cc_fullname("/dev", namelist[0]->d_name + 4); - free(namelist); - return tty; - } - - /* Check for tty/ttyACMx style names - */ - tty_dir = cc_fullname(endpoint_full, "tty"); - free(endpoint_full); - ntty = scandir(tty_dir, &namelist, - dir_filter_tty, - alphasort); - free (tty_dir); - if (ntty > 0) { - tty = cc_fullname("/dev", namelist[0]->d_name); - free(namelist); - return tty; - } - } - } - return NULL; -} - -static struct altos_usbdev * -usb_scan_device(char *sys) -{ - struct altos_usbdev *usbdev; - - usbdev = calloc(1, sizeof (struct altos_usbdev)); - if (!usbdev) - return NULL; - usbdev->sys = strdup(sys); - usbdev->manufacturer = load_string(sys, "manufacturer"); - usbdev->product_name = load_string(sys, "product"); - usbdev->serial = load_dec(sys, "serial"); - usbdev->idProduct = load_hex(sys, "idProduct"); - usbdev->idVendor = load_hex(sys, "idVendor"); - usbdev->tty = usb_tty(sys); - return usbdev; -} - -static void -usbdev_free(struct altos_usbdev *usbdev) -{ - free(usbdev->sys); - free(usbdev->manufacturer); - free(usbdev->product_name); - /* this can get used as a return value */ - if (usbdev->tty) - free(usbdev->tty); - free(usbdev); -} - -#define USB_DEVICES "/sys/bus/usb/devices" - -static int -dir_filter_dev(const struct dirent *d) -{ - const char *n = d->d_name; - char c; - - while ((c = *n++)) { - if (isdigit(c)) - continue; - if (c == '-') - continue; - if (c == '.' && n != d->d_name + 1) - continue; - return 0; - } - return 1; -} - -struct altos_list { - struct altos_usbdev **dev; - int current; - int ndev; -}; - -struct altos_list * -altos_list_start(void) -{ - int e; - struct dirent **ents; - char *dir; - struct altos_usbdev *dev; - struct altos_list *devs; - int n; - - devs = calloc(1, sizeof (struct altos_list)); - if (!devs) - return NULL; - - n = scandir (USB_DEVICES, &ents, - dir_filter_dev, - alphasort); - if (!n) - return 0; - for (e = 0; e < n; e++) { - dir = cc_fullname(USB_DEVICES, ents[e]->d_name); - dev = usb_scan_device(dir); - free(dir); - if (USB_IS_ALTUSMETRUM(dev->idVendor, dev->idProduct)) { - if (devs->dev) - devs->dev = realloc(devs->dev, - devs->ndev + 1 * sizeof (struct usbdev *)); - else - devs->dev = malloc (sizeof (struct usbdev *)); - devs->dev[devs->ndev++] = dev; - } - } - free(ents); - devs->current = 0; - return devs; -} - -int -altos_list_next(struct altos_list *list, struct altos_device *device) -{ - struct altos_usbdev *dev; - if (list->current >= list->ndev) - return 0; - dev = list->dev[list->current]; - strcpy(device->name, dev->product_name); - device->vendor = dev->idVendor; - device->product = dev->idProduct; - strcpy(device->path, dev->tty); - device->serial = dev->serial; - list->current++; - return 1; -} - -void -altos_list_finish(struct altos_list *usbdevs) -{ - int i; - - if (!usbdevs) - return; - for (i = 0; i < usbdevs->ndev; i++) - usbdev_free(usbdevs->dev[i]); - free(usbdevs); -} - -#endif - -#ifdef DARWIN - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct altos_list { - io_iterator_t iterator; -}; - -static int -get_string(io_object_t object, CFStringRef entry, char *result, int result_len) -{ - CFTypeRef entry_as_string; - Boolean got_string; - - entry_as_string = IORegistryEntrySearchCFProperty (object, - kIOServicePlane, - entry, - kCFAllocatorDefault, - kIORegistryIterateRecursively); - if (entry_as_string) { - got_string = CFStringGetCString(entry_as_string, - result, result_len, - kCFStringEncodingASCII); - - CFRelease(entry_as_string); - if (got_string) - return 1; - } - return 0; -} - -static int -get_number(io_object_t object, CFStringRef entry, int *result) -{ - CFTypeRef entry_as_number; - Boolean got_number; - - entry_as_number = IORegistryEntrySearchCFProperty (object, - kIOServicePlane, - entry, - kCFAllocatorDefault, - kIORegistryIterateRecursively); - if (entry_as_number) { - got_number = CFNumberGetValue(entry_as_number, - kCFNumberIntType, - result); - if (got_number) - return 1; - } - return 0; -} - -struct altos_list * -altos_list_start(void) -{ - struct altos_list *list = calloc (sizeof (struct altos_list), 1); - CFMutableDictionaryRef matching_dictionary = IOServiceMatching("IOUSBDevice"); - io_iterator_t tdIterator; - io_object_t tdObject; - kern_return_t ret; - int i; - - ret = IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dictionary, &list->iterator); - if (ret != kIOReturnSuccess) - return NULL; - return list; -} - -int -altos_list_next(struct altos_list *list, struct altos_device *device) -{ - io_object_t object; - char serial_string[128]; - - for (;;) { - object = IOIteratorNext(list->iterator); - if (!object) - return 0; - - if (!get_number (object, CFSTR(kUSBVendorID), &device->vendor) || - !get_number (object, CFSTR(kUSBProductID), &device->product)) - continue; - if (device->vendor != 0xfffe) - continue; - if (device->product < 0x000a || 0x0013 < device->product) - continue; - if (get_string (object, CFSTR("IOCalloutDevice"), device->path, sizeof (device->path)) && - get_string (object, CFSTR("USB Product Name"), device->name, sizeof (device->name)) && - get_string (object, CFSTR("USB Serial Number"), serial_string, sizeof (serial_string))) { - device->serial = atoi(serial_string); - return 1; - } - } -} - -void -altos_list_finish(struct altos_list *list) -{ - IOObjectRelease (list->iterator); - free(list); -} - -#endif - -#ifdef POSIX_TTY - -#include -#include -#include -#include -#include - -#define USB_BUF_SIZE 64 - -struct altos_file { - int fd; -#ifdef USE_POLL - int pipe[2]; -#else - int out_fd; -#endif - unsigned char out_data[USB_BUF_SIZE]; - int out_used; - unsigned char in_data[USB_BUF_SIZE]; - int in_used; - int in_read; -}; - -PUBLIC struct altos_file * -altos_open(struct altos_device *device) -{ - struct altos_file *file = calloc (sizeof (struct altos_file), 1); - int ret; - struct termios term; - - if (!file) - return NULL; - - file->fd = open(device->path, O_RDWR | O_NOCTTY); - if (file->fd < 0) { - perror(device->path); - free(file); - return NULL; - } -#ifdef USE_POLL - pipe(file->pipe); -#else - file->out_fd = open(device->path, O_RDWR | O_NOCTTY); - if (file->out_fd < 0) { - perror(device->path); - close(file->fd); - free(file); - return NULL; - } -#endif - ret = tcgetattr(file->fd, &term); - if (ret < 0) { - perror("tcgetattr"); - close(file->fd); -#ifndef USE_POLL - close(file->out_fd); -#endif - free(file); - return NULL; - } - cfmakeraw(&term); -#ifdef USE_POLL - term.c_cc[VMIN] = 1; - term.c_cc[VTIME] = 0; -#else - term.c_cc[VMIN] = 0; - term.c_cc[VTIME] = 1; -#endif - ret = tcsetattr(file->fd, TCSAFLUSH, &term); - if (ret < 0) { - perror("tcsetattr"); - close(file->fd); -#ifndef USE_POLL - close(file->out_fd); -#endif - free(file); - return NULL; - } - return file; -} - -PUBLIC void -altos_close(struct altos_file *file) -{ - if (file->fd != -1) { - int fd = file->fd; - file->fd = -1; -#ifdef USE_POLL - write(file->pipe[1], "\r", 1); -#else - close(file->out_fd); - file->out_fd = -1; -#endif - close(fd); - } -} - -PUBLIC void -altos_free(struct altos_file *file) -{ - altos_close(file); - free(file); -} - -PUBLIC int -altos_flush(struct altos_file *file) -{ - if (file->out_used && 0) { - printf ("flush \""); - fwrite(file->out_data, 1, file->out_used, stdout); - printf ("\"\n"); - } - while (file->out_used) { - int ret; - - if (file->fd < 0) - return -EBADF; -#ifdef USE_POLL - ret = write (file->fd, file->out_data, file->out_used); -#else - ret = write (file->out_fd, file->out_data, file->out_used); -#endif - if (ret < 0) - return -errno; - if (ret) { - memmove(file->out_data, file->out_data + ret, - file->out_used - ret); - file->out_used -= ret; - } - } - return 0; -} - -PUBLIC int -altos_putchar(struct altos_file *file, char c) -{ - int ret; - - if (file->out_used == USB_BUF_SIZE) { - ret = altos_flush(file); - if (ret) { - return ret; - } - } - file->out_data[file->out_used++] = c; - ret = 0; - if (file->out_used == USB_BUF_SIZE) - ret = altos_flush(file); - return 0; -} - -#ifdef USE_POLL -#include -#endif - -static int -altos_fill(struct altos_file *file, int timeout) -{ - int ret; -#ifdef USE_POLL - struct pollfd fd[2]; -#endif - - if (timeout == 0) - timeout = -1; - while (file->in_read == file->in_used) { - if (file->fd < 0) - return LIBALTOS_ERROR; -#ifdef USE_POLL - fd[0].fd = file->fd; - fd[0].events = POLLIN|POLLERR|POLLHUP|POLLNVAL; - fd[1].fd = file->pipe[0]; - fd[1].events = POLLIN; - ret = poll(fd, 2, timeout); - if (ret < 0) { - perror("altos_getchar"); - return LIBALTOS_ERROR; - } - if (ret == 0) - return LIBALTOS_TIMEOUT; - - if (fd[0].revents & (POLLHUP|POLLERR|POLLNVAL)) - return LIBALTOS_ERROR; - if (fd[0].revents & POLLIN) -#endif - { - ret = read(file->fd, file->in_data, USB_BUF_SIZE); - if (ret < 0) { - perror("altos_getchar"); - return LIBALTOS_ERROR; - } - file->in_read = 0; - file->in_used = ret; -#ifndef USE_POLL - if (ret == 0 && timeout > 0) - return LIBALTOS_TIMEOUT; -#endif - } - } - if (file->in_used && 0) { - printf ("fill \""); - fwrite(file->in_data, 1, file->in_used, stdout); - printf ("\"\n"); - } - return 0; -} - -PUBLIC int -altos_getchar(struct altos_file *file, int timeout) -{ - int ret; - while (file->in_read == file->in_used) { - if (file->fd < 0) - return LIBALTOS_ERROR; - ret = altos_fill(file, timeout); - if (ret) - return ret; - } - return file->in_data[file->in_read++]; -} - -#endif /* POSIX_TTY */ - -#ifdef WINDOWS - -#include -#include -#include - -struct altos_list { - HDEVINFO dev_info; - int index; -}; - -#define USB_BUF_SIZE 64 - -struct altos_file { - HANDLE handle; - unsigned char out_data[USB_BUF_SIZE]; - int out_used; - unsigned char in_data[USB_BUF_SIZE]; - int in_used; - int in_read; - OVERLAPPED ov_read; - BOOL pend_read; - OVERLAPPED ov_write; -}; - -PUBLIC struct altos_list * -altos_list_start(void) -{ - struct altos_list *list = calloc(1, sizeof (struct altos_list)); - - if (!list) - return NULL; - list->dev_info = SetupDiGetClassDevs(NULL, "USB", NULL, - DIGCF_ALLCLASSES|DIGCF_PRESENT); - if (list->dev_info == INVALID_HANDLE_VALUE) { - printf("SetupDiGetClassDevs failed %d\n", GetLastError()); - free(list); - return NULL; - } - list->index = 0; - return list; -} - -PUBLIC int -altos_list_next(struct altos_list *list, struct altos_device *device) -{ - SP_DEVINFO_DATA dev_info_data; - char port[128]; - DWORD port_len; - char friendlyname[256]; - char symbolic[256]; - DWORD symbolic_len; - HKEY dev_key; - int vid, pid; - int serial; - HRESULT result; - DWORD friendlyname_type; - DWORD friendlyname_len; - - dev_info_data.cbSize = sizeof (SP_DEVINFO_DATA); - while(SetupDiEnumDeviceInfo(list->dev_info, list->index, - &dev_info_data)) - { - list->index++; - - dev_key = SetupDiOpenDevRegKey(list->dev_info, &dev_info_data, - DICS_FLAG_GLOBAL, 0, DIREG_DEV, - KEY_READ); - if (dev_key == INVALID_HANDLE_VALUE) { - printf("cannot open device registry key\n"); - continue; - } - - /* Fetch symbolic name for this device and parse out - * the vid/pid/serial info */ - symbolic_len = sizeof(symbolic); - result = RegQueryValueEx(dev_key, "SymbolicName", NULL, NULL, - symbolic, &symbolic_len); - if (result != 0) { - printf("cannot find SymbolicName value\n"); - RegCloseKey(dev_key); - continue; - } - vid = pid = serial = 0; - sscanf(symbolic + sizeof("\\??\\USB#VID_") - 1, - "%04X", &vid); - sscanf(symbolic + sizeof("\\??\\USB#VID_XXXX&PID_") - 1, - "%04X", &pid); - sscanf(symbolic + sizeof("\\??\\USB#VID_XXXX&PID_XXXX#") - 1, - "%d", &serial); - if (!USB_IS_ALTUSMETRUM(vid, pid)) { - RegCloseKey(dev_key); - continue; - } - - /* Fetch the com port name */ - port_len = sizeof (port); - result = RegQueryValueEx(dev_key, "PortName", NULL, NULL, - port, &port_len); - RegCloseKey(dev_key); - if (result != 0) { - printf("failed to get PortName\n"); - continue; - } - - /* Fetch the device description which is the device name, - * with firmware that has unique USB ids */ - friendlyname_len = sizeof (friendlyname); - if(!SetupDiGetDeviceRegistryProperty(list->dev_info, - &dev_info_data, - SPDRP_FRIENDLYNAME, - &friendlyname_type, - (BYTE *)friendlyname, - sizeof(friendlyname), - &friendlyname_len)) - { - printf("Failed to get friendlyname\n"); - continue; - } - device->vendor = vid; - device->product = pid; - device->serial = serial; - strcpy(device->name, friendlyname); - - strcpy(device->path, port); - return 1; - } - result = GetLastError(); - if (result != ERROR_NO_MORE_ITEMS) - printf ("SetupDiEnumDeviceInfo failed error %d\n", result); - return 0; -} - -PUBLIC void -altos_list_finish(struct altos_list *list) -{ - SetupDiDestroyDeviceInfoList(list->dev_info); - free(list); -} - -static int -altos_queue_read(struct altos_file *file) -{ - DWORD got; - if (file->pend_read) - return LIBALTOS_SUCCESS; - - if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, &file->ov_read)) { - if (GetLastError() != ERROR_IO_PENDING) - return LIBALTOS_ERROR; - file->pend_read = TRUE; - } else { - file->pend_read = FALSE; - file->in_read = 0; - file->in_used = got; - } - return LIBALTOS_SUCCESS; -} - -static int -altos_wait_read(struct altos_file *file, int timeout) -{ - DWORD ret; - DWORD got; - - if (!file->pend_read) - return LIBALTOS_SUCCESS; - - if (!timeout) - timeout = INFINITE; - - ret = WaitForSingleObject(file->ov_read.hEvent, timeout); - switch (ret) { - case WAIT_OBJECT_0: - if (!GetOverlappedResult(file->handle, &file->ov_read, &got, FALSE)) - return LIBALTOS_ERROR; - file->pend_read = FALSE; - file->in_read = 0; - file->in_used = got; - break; - case WAIT_TIMEOUT: - return LIBALTOS_TIMEOUT; - break; - default: - return LIBALTOS_ERROR; - } - return LIBALTOS_SUCCESS; -} - -static int -altos_fill(struct altos_file *file, int timeout) -{ - int ret; - - if (file->in_read < file->in_used) - return LIBALTOS_SUCCESS; - - file->in_read = file->in_used = 0; - - ret = altos_queue_read(file); - if (ret) - return ret; - ret = altos_wait_read(file, timeout); - if (ret) - return ret; - - return LIBALTOS_SUCCESS; -} - -PUBLIC int -altos_flush(struct altos_file *file) -{ - DWORD put; - char *data = file->out_data; - char used = file->out_used; - DWORD ret; - - while (used) { - if (!WriteFile(file->handle, data, used, &put, &file->ov_write)) { - if (GetLastError() != ERROR_IO_PENDING) - return LIBALTOS_ERROR; - ret = WaitForSingleObject(file->ov_write.hEvent, INFINITE); - switch (ret) { - case WAIT_OBJECT_0: - if (!GetOverlappedResult(file->handle, &file->ov_write, &put, FALSE)) - return LIBALTOS_ERROR; - break; - default: - return LIBALTOS_ERROR; - } - } - data += put; - used -= put; - } - file->out_used = 0; - return LIBALTOS_SUCCESS; -} - -PUBLIC struct altos_file * -altos_open(struct altos_device *device) -{ - struct altos_file *file = calloc (1, sizeof (struct altos_file)); - char full_name[64]; - DCB dcbSerialParams = {0}; - COMMTIMEOUTS timeouts; - - if (!file) - return NULL; - - strcpy(full_name, "\\\\.\\"); - strcat(full_name, device->path); - file->handle = CreateFile(full_name, GENERIC_READ|GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, NULL); - if (file->handle == INVALID_HANDLE_VALUE) { - free(file); - return NULL; - } - file->ov_read.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - file->ov_write.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; - timeouts.ReadTotalTimeoutConstant = 1 << 30; /* almost forever */ - timeouts.WriteTotalTimeoutMultiplier = 0; - timeouts.WriteTotalTimeoutConstant = 0; - SetCommTimeouts(file->handle, &timeouts); - - dcbSerialParams.DCBlength = sizeof(dcbSerialParams); - if (!GetCommState(file->handle, &dcbSerialParams)) { - CloseHandle(file->handle); - free(file); - return NULL; - } - dcbSerialParams.BaudRate = CBR_9600; - dcbSerialParams.ByteSize = 8; - dcbSerialParams.StopBits = ONESTOPBIT; - dcbSerialParams.Parity = NOPARITY; - if (!SetCommState(file->handle, &dcbSerialParams)) { - CloseHandle(file->handle); - free(file); - return NULL; - } - - return file; -} - -PUBLIC void -altos_close(struct altos_file *file) -{ - if (file->handle != INVALID_HANDLE_VALUE) { - CloseHandle(file->handle); - file->handle = INVALID_HANDLE_VALUE; - } -} - -PUBLIC void -altos_free(struct altos_file *file) -{ - altos_close(file); - free(file); -} - -int -altos_putchar(struct altos_file *file, char c) -{ - int ret; - - if (file->out_used == USB_BUF_SIZE) { - ret = altos_flush(file); - if (ret) - return ret; - } - file->out_data[file->out_used++] = c; - if (file->out_used == USB_BUF_SIZE) - return altos_flush(file); - return LIBALTOS_SUCCESS; -} - -int -altos_getchar(struct altos_file *file, int timeout) -{ - int ret; - while (file->in_read == file->in_used) { - if (file->handle == INVALID_HANDLE_VALUE) - return LIBALTOS_ERROR; - ret = altos_fill(file, timeout); - if (ret) - return ret; - } - return file->in_data[file->in_read++]; -} - -#endif diff --git a/ao-tools/libaltos/libaltos.dylib b/ao-tools/libaltos/libaltos.dylib deleted file mode 100755 index 89aa12e7..00000000 Binary files a/ao-tools/libaltos/libaltos.dylib and /dev/null differ diff --git a/ao-tools/libaltos/libaltos.h b/ao-tools/libaltos/libaltos.h deleted file mode 100644 index 6e94899e..00000000 --- a/ao-tools/libaltos/libaltos.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2010 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. - */ - -#ifndef _LIBALTOS_H_ -#define _LIBALTOS_H_ - -#include - -#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# ifndef BUILD_STATIC -# ifdef BUILD_DLL -# define PUBLIC __declspec(dllexport) -# else -# define PUBLIC __declspec(dllimport) -# endif -# endif /* BUILD_STATIC */ -#endif - -#ifndef PUBLIC -# define PUBLIC -#endif - -#define USB_VENDOR_FSF 0xfffe -#define USB_VENDOR_ALTUSMETRUM USB_VENDOR_FSF -#define USB_PRODUCT_ALTUSMETRUM 0x000a -#define USB_PRODUCT_TELEMETRUM 0x000b -#define USB_PRODUCT_TELEDONGLE 0x000c -#define USB_PRODUCT_TELETERRA 0x000d -#define USB_PRODUCT_ALTUSMETRUM_MIN 0x000a -#define USB_PRODUCT_ALTUSMETRUM_MAX 0x0013 - -#define USB_IS_ALTUSMETRUM(v,p) ((v) == USB_VENDOR_ALTUSMETRUM && \ - (USB_PRODUCT_ALTUSMETRUM_MIN <= (p) && \ - (p) <= USB_PRODUCT_ALTUSMETRUM_MAX)) - -struct altos_device { - //%immutable; - int vendor; - int product; - int serial; - char name[256]; - char path[256]; - //%mutable; -}; - -#define LIBALTOS_SUCCESS 0 -#define LIBALTOS_ERROR -1 -#define LIBALTOS_TIMEOUT -2 - -/* Returns 0 for success, < 0 on error */ -PUBLIC int -altos_init(void); - -PUBLIC void -altos_fini(void); - -PUBLIC struct altos_list * -altos_list_start(void); - -/* Returns 1 for success, zero on end of list */ -PUBLIC int -altos_list_next(struct altos_list *list, struct altos_device *device); - -PUBLIC void -altos_list_finish(struct altos_list *list); - -PUBLIC struct altos_file * -altos_open(struct altos_device *device); - -PUBLIC void -altos_close(struct altos_file *file); - -PUBLIC void -altos_free(struct altos_file *file); - -/* Returns < 0 for error */ -PUBLIC int -altos_putchar(struct altos_file *file, char c); - -/* Returns < 0 for error */ -PUBLIC int -altos_flush(struct altos_file *file); - -/* Returns < 0 for error or timeout. timeout of 0 == wait forever */ -PUBLIC int -altos_getchar(struct altos_file *file, int timeout); - -#endif /* _LIBALTOS_H_ */ diff --git a/ao-tools/libaltos/libaltos.i0 b/ao-tools/libaltos/libaltos.i0 deleted file mode 100644 index d06468f5..00000000 --- a/ao-tools/libaltos/libaltos.i0 +++ /dev/null @@ -1,5 +0,0 @@ -%module libaltos -%{ -#include "libaltos.h" -%} - diff --git a/configure.ac b/configure.ac index 903c5765..22af00ab 100644 --- a/configure.ac +++ b/configure.ac @@ -133,6 +133,8 @@ PKG_CHECK_MODULES([SNDFILE], [sndfile]) AC_OUTPUT([ Makefile +altosui/Makefile +altosui/libaltos/Makefile ao-tools/Makefile ao-tools/lib/Makefile ao-tools/ao-rawload/Makefile @@ -144,8 +146,6 @@ ao-tools/ao-list/Makefile ao-tools/ao-load/Makefile ao-tools/ao-postflight/Makefile ao-tools/ao-view/Makefile -ao-tools/libaltos/Makefile -ao-tools/altosui/Makefile ao-utils/Makefile src/Version ]) -- cgit v1.2.3 From c3080fdafff5212f267ba7c765a2f083435be799 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 18 Feb 2011 09:51:37 -0800 Subject: ao-load: fix usage message to note that '=' is required for options The usage message was suggesting incorrect command line syntax; long options use '=' between the option name and value, not whitespace. Signed-off-by: Keith Packard --- ao-tools/ao-load/ao-load.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-load/ao-load.c b/ao-tools/ao-load/ao-load.c index 4aa91b29..5accefc8 100644 --- a/ao-tools/ao-load/ao-load.c +++ b/ao-tools/ao-load/ao-load.c @@ -102,7 +102,7 @@ static const struct option options[] = { static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty ] [--device ] [--cal ] file.ihx serial-number\n", program); + fprintf(stderr, "usage: %s [--tty=] [--device=] [--cal=] file.ihx serial-number\n", program); exit(1); } -- cgit v1.2.3 From 8f1bd11b61d9423c62162f7bbe573fc69fd75269 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 16 Mar 2011 14:10:06 -0700 Subject: aoview: remove -s option. --- ao-tools/ao-view/aoview_main.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-view/aoview_main.c b/ao-tools/ao-view/aoview_main.c index 714bee9a..f8704b89 100644 --- a/ao-tools/ao-view/aoview_main.c +++ b/ao-tools/ao-view/aoview_main.c @@ -31,7 +31,6 @@ static void destroy_event(GtkWidget *widget, gpointer data) gtk_main_quit(); } -extern int _Xdebug; char *aoview_tty = NULL; int main(int argc, char **argv) @@ -42,13 +41,12 @@ int main(int argc, char **argv) static struct option long_options[] = { { "tty", 1, 0, 'T'}, - { "sync", 0, 0, 's'}, { 0, 0, 0, 0 } }; for (;;) { int c, temp; - c = getopt_long_only(argc, argv, "sT:", long_options, &temp); + c = getopt_long_only(argc, argv, "T:", long_options, &temp); if (c == -1) break; @@ -56,9 +54,6 @@ int main(int argc, char **argv) case 'T': aoview_tty = optarg; break; - case 's': - _Xdebug = 1; - break; default: usage(); } -- cgit v1.2.3 From d007bccf6cb36d24a9c7c48de7d80759ac6f2e37 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 7 Mar 2011 15:57:58 -0800 Subject: ao-load: Make usb descriptor rewriting optional TeleMini and TeleNano don't have USB descriptors to rewrite when loading firmware, so allow them to be missing. Signed-off-by: Keith Packard --- ao-tools/ao-load/ao-load.c | 72 ++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 34 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-load/ao-load.c b/ao-tools/ao-load/ao-load.c index 5accefc8..1b729d39 100644 --- a/ao-tools/ao-load/ao-load.c +++ b/ao-tools/ao-load/ao-load.c @@ -29,17 +29,18 @@ struct sym { unsigned addr; char *name; + int required; } ao_symbols[] = { - { 0, "_ao_serial_number" }, + { 0, "_ao_serial_number", 1 }, #define AO_SERIAL_NUMBER (ao_symbols[0].addr) - { 0, "_ao_usb_descriptors" }, + { 0, "_ao_usb_descriptors", 0 }, #define AO_USB_DESCRIPTORS (ao_symbols[1].addr) - { 0, "_ao_radio_cal" }, + { 0, "_ao_radio_cal", 1 }, #define AO_RADIO_CAL (ao_symbols[2].addr) }; -#define NUM_SERIAL_SYMBOLS 2 #define NUM_SYMBOLS 3 +#define NUM_REQUIRED_SYMBOLS 2 static int find_symbols(FILE *map) @@ -51,7 +52,7 @@ find_symbols(FILE *map) char *colon; unsigned long a; int s; - int found = 0; + int required = 0; while (fgets(line, sizeof(line), map) != NULL) { line[sizeof(line)-1] = '\0'; @@ -70,11 +71,12 @@ find_symbols(FILE *map) for (s = 0; s < NUM_SYMBOLS; s++) if (!strcmp(ao_symbols[s].name, name)) { ao_symbols[s].addr = (unsigned) a; - ++found; + if (ao_symbols[s].required) + ++required; break; } } - return found >= NUM_SERIAL_SYMBOLS; + return required >= NUM_REQUIRED_SYMBOLS; } static int @@ -125,7 +127,6 @@ main (int argc, char **argv) char serial_int[2]; unsigned int s; int i; - unsigned usb_descriptors; int string_num; char *tty = NULL; char *device = NULL; @@ -207,35 +208,38 @@ main (int argc, char **argv) exit(1); } - usb_descriptors = AO_USB_DESCRIPTORS - image->address; - string_num = 0; - while (image->data[usb_descriptors] != 0 && usb_descriptors < image->length) { - if (image->data[usb_descriptors+1] == AO_USB_DESC_STRING) { - ++string_num; - if (string_num == 4) - break; + if (AO_USB_DESCRIPTORS) { + unsigned usb_descriptors; + usb_descriptors = AO_USB_DESCRIPTORS - image->address; + string_num = 0; + while (image->data[usb_descriptors] != 0 && usb_descriptors < image->length) { + if (image->data[usb_descriptors+1] == AO_USB_DESC_STRING) { + ++string_num; + if (string_num == 4) + break; + } + usb_descriptors += image->data[usb_descriptors]; + } + if (usb_descriptors >= image->length || image->data[usb_descriptors] == 0 ) { + fprintf(stderr, "Cannot rewrite serial string at %04x\n", AO_USB_DESCRIPTORS); + exit(1); } - usb_descriptors += image->data[usb_descriptors]; - } - if (usb_descriptors >= image->length || image->data[usb_descriptors] == 0 ) { - fprintf(stderr, "Cannot rewrite serial string at %04x\n", AO_USB_DESCRIPTORS); - exit(1); - } - serial_ucs2_len = image->data[usb_descriptors] - 2; - serial_ucs2 = malloc(serial_ucs2_len); - if (!serial_ucs2) { - fprintf(stderr, "Malloc(%d) failed\n", serial_ucs2_len); - exit(1); - } - s = serial; - for (i = serial_ucs2_len / 2; i; i--) { - serial_ucs2[i * 2 - 1] = 0; - serial_ucs2[i * 2 - 2] = (s % 10) + '0'; - s /= 10; + serial_ucs2_len = image->data[usb_descriptors] - 2; + serial_ucs2 = malloc(serial_ucs2_len); + if (!serial_ucs2) { + fprintf(stderr, "Malloc(%d) failed\n", serial_ucs2_len); + exit(1); + } + s = serial; + for (i = serial_ucs2_len / 2; i; i--) { + serial_ucs2[i * 2 - 1] = 0; + serial_ucs2[i * 2 - 2] = (s % 10) + '0'; + s /= 10; + } + if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len)) + usage(argv[0]); } - if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len)) - usage(argv[0]); if (cal) { cal_int[0] = cal & 0xff; -- cgit v1.2.3 From 3b87dd6f46922cf5f98deb2dffa2148c4244e48e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Aug 2011 15:00:14 -0700 Subject: ao-tools: ao-list was crashing with more than 3 devices connected the list of devices was getting realloced for each new device, but that realloc was too small. Signed-off-by: Keith Packard --- ao-tools/lib/cc-usbdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/lib/cc-usbdev.c b/ao-tools/lib/cc-usbdev.c index afa91d49..a19e231c 100644 --- a/ao-tools/lib/cc-usbdev.c +++ b/ao-tools/lib/cc-usbdev.c @@ -223,7 +223,7 @@ cc_usbdevs_scan(void) if (dev->idVendor == 0xfffe && dev->tty) { if (devs->dev) devs->dev = realloc(devs->dev, - devs->ndev + 1 * sizeof (struct usbdev *)); + (devs->ndev + 1) * sizeof (struct usbdev *)); else devs->dev = malloc (sizeof (struct usbdev *)); devs->dev[devs->ndev++] = dev; -- cgit v1.2.3 From 63808e0392f43633f92fee137d968e969dd364c9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Aug 2011 23:20:00 -0700 Subject: Remove stale tools (ao-dumplog, ao-postflight, ao-view) These tools have all been supplanted by altosui at this point, and keeping them around increases the build dependencies by quite a lot. Signed-off-by: Keith Packard --- ao-tools/Makefile.am | 2 +- ao-tools/lib/Makefile.am | 4 +++- configure.ac | 25 ------------------------- debian/control | 4 ++-- 4 files changed, 6 insertions(+), 29 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 2850e909..8144be1c 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-dumplog ao-bitbang ao-eeprom ao-list ao-load ao-postflight ao-view +SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list ao-load diff --git a/ao-tools/lib/Makefile.am b/ao-tools/lib/Makefile.am index 79972f46..da355db5 100644 --- a/ao-tools/lib/Makefile.am +++ b/ao-tools/lib/Makefile.am @@ -2,6 +2,9 @@ noinst_LIBRARIES = libao-tools.a AM_CFLAGS=$(WARN_CFLAGS) $(LIBUSB_CFLAGS) $(GNOME_CFLAGS) +libao_tools_a_uneeded = \ + cc-log.c + libao_tools_a_SOURCES = \ ccdbg-command.c \ ccdbg-debug.c \ @@ -17,7 +20,6 @@ libao_tools_a_SOURCES = \ cc-analyse.c \ cc-convert.c \ cc-dsp.c \ - cc-log.c \ cc-integrate.c \ cc-period.c \ cc-process.c \ diff --git a/configure.ac b/configure.ac index 93f53115..0a6001b8 100644 --- a/configure.ac +++ b/configure.ac @@ -95,20 +95,6 @@ if test "x$GCC" = "xyes"; then fi AC_SUBST(WARN_CFLAGS) -AC_CHECK_HEADERS(flite/flite.h,HAVE_FLITE_H=yes,HAVE_FLITE_H=no) -AC_CHECK_LIB(flite, flite_init,HAVE_LIBFLITE=yes,HAVE_LIBFLITE=no,-lasound -lm) - -if test "x$HAVE_FLITE_H" = "xyes" -a "x$HAVE_LIBFLITE" = "xyes"; then - AC_DEFINE(HAVE_FLITE,1,[Define if the flite library is usable]) - AC_SUBST(FLITE_LIBS,"-lflite_cmu_us_kal16 -lflite_usenglish -lflite_cmulex -lflite -lasound -lm") - AC_SUBST(FLITE_INCS,-Iflite) - save_LIBS="$LIBS" - LIBS="$LIBS $FLITE_LIBS" - AC_CHECK_FUNCS([register_cmu_us_kal16 register_cmu_us_kal],break) - LIBS="$save_LIBS" -fi -AM_CONDITIONAL(USE_FLITE,test "x$HAVE_FLITE_H" = "xyes" -a "x$HAVE_LIBFLITE" = "xyes") - AC_CHECK_PROG([HAVE_SDCC], [sdcc], yes, no) if test "x$HAVE_SDCC" = "xno"; then AC_MSG_ERROR([Please install sdcc to build AltOs]) @@ -121,16 +107,8 @@ fi AC_CHECK_LIB(readline, readline) -PKG_CHECK_MODULES([GNOME], [gtk+-2.0 libglade-2.0 gconf-2.0]) - PKG_CHECK_MODULES([LIBUSB], [libusb-1.0]) -PKG_CHECK_MODULES([ALSA], [alsa]) - -PKG_CHECK_MODULES([PLPLOT], [plplotd]) - -PKG_CHECK_MODULES([SNDFILE], [sndfile]) - AC_OUTPUT([ Makefile altosui/Makefile @@ -140,13 +118,10 @@ ao-tools/Makefile ao-tools/lib/Makefile ao-tools/ao-rawload/Makefile ao-tools/ao-dbg/Makefile -ao-tools/ao-dumplog/Makefile ao-tools/ao-bitbang/Makefile ao-tools/ao-eeprom/Makefile ao-tools/ao-list/Makefile ao-tools/ao-load/Makefile -ao-tools/ao-postflight/Makefile -ao-tools/ao-view/Makefile ao-utils/Makefile src/Version ]) diff --git a/debian/control b/debian/control index fc70c8e0..f784a702 100644 --- a/debian/control +++ b/debian/control @@ -3,13 +3,13 @@ Section: otherosfs Priority: extra Maintainer: Bdale Garbee Uploaders: Keith Packard -Build-Depends: debhelper (>= 7), autoconf, automake, flite1-dev, gawk, libasound2-dev, libgconf2-dev, libglade2-dev, libgtk2.0-dev, libreadline-dev, libusb-1.0-0-dev, nickle, sdcc, libplplot-dev, xsltproc, fop, docbook-xml, docbook-xsl, libsndfile1-dev, swig, openjdk-6-jdk, freetts, libtool, libjfreechart-java, libbluetooth-dev +Build-Depends: debhelper (>= 7), autoconf, automake, gawk, libreadline-dev, libusb-1.0-0-dev, nickle, sdcc, xsltproc, fop, docbook-xml, docbook-xsl, swig, openjdk-6-jdk, freetts, libtool, libjfreechart-java, libbluetooth-dev Standards-Version: 3.9.2 Homepage: http://altusmetrum.org/AltOS Package: altos Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, default-jre | java2-runtime, freetts, nickle, plplot9-driver-cairo +Depends: ${shlibs:Depends}, ${misc:Depends}, default-jre | java2-runtime, freetts, nickle Suggests: slim | gdm Replaces: altusmetrum-themes, slim-altusmetrum Conflicts: altusmetrum-themes, slim-altusmetrum -- cgit v1.2.3 From 82604193ed0c522c1fba0072b504fe88b027f1ee Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 8 Oct 2011 11:50:24 -0600 Subject: ao-telem: Add new program to convert telem data to ascii This reads telem files and displays them in ascii form. It's not done, and it's not documented, but it's a start. Signed-off-by: Keith Packard --- ao-tools/Makefile.am | 2 +- ao-tools/ao-telem/Makefile.am | 12 +++ ao-tools/ao-telem/ao-telem.1 | 61 ++++++++++++++ ao-tools/ao-telem/ao-telem.c | 112 +++++++++++++++++++++++++ ao-tools/lib/Makefile.am | 2 + ao-tools/lib/cc-telemetry.c | 62 ++++++++++++++ ao-tools/lib/cc-telemetry.h | 188 ++++++++++++++++++++++++++++++++++++++++++ ao-tools/lib/cc.h | 1 + configure.ac | 1 + 9 files changed, 440 insertions(+), 1 deletion(-) create mode 100644 ao-tools/ao-telem/Makefile.am create mode 100644 ao-tools/ao-telem/ao-telem.1 create mode 100644 ao-tools/ao-telem/ao-telem.c create mode 100644 ao-tools/lib/cc-telemetry.c create mode 100644 ao-tools/lib/cc-telemetry.h (limited to 'ao-tools') diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 8144be1c..611bb7dc 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list ao-load +SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list ao-load ao-telem diff --git a/ao-tools/ao-telem/Makefile.am b/ao-tools/ao-telem/Makefile.am new file mode 100644 index 00000000..3436443e --- /dev/null +++ b/ao-tools/ao-telem/Makefile.am @@ -0,0 +1,12 @@ +bin_PROGRAMS=ao-telem + +AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS) +AO_POSTFLIGHT_LIBS=$(top_builddir)/ao-tools/lib/libao-tools.a + +ao_telem_DEPENDENCIES = $(AO_POSTFLIGHT_LIBS) + +ao_telem_LDADD=$(AO_POSTFLIGHT_LIBS) $(LIBUSB_LIBS) + +ao_telem_SOURCES = ao-telem.c + +man_MANS = ao-telem.1 diff --git a/ao-tools/ao-telem/ao-telem.1 b/ao-tools/ao-telem/ao-telem.1 new file mode 100644 index 00000000..8e6699d5 --- /dev/null +++ b/ao-tools/ao-telem/ao-telem.1 @@ -0,0 +1,61 @@ +.\" +.\" 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-TELEM 1 "ao-telem" "" +.SH NAME +ao-telem \- Analyse a flight log (either telemetry or eeprom) +.SH SYNOPSIS +.B "ao-telem" +[\-s ] +[\--summary=] +[\-d ] +[\--detail=] +[\-r ] +[\--raw=] +[\-p ] +[\--plot=] +[\-g + * + * 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 _GNU_SOURCE +#include +#include +#include +#include +#include +#include "cc.h" + +static const struct option options[] = { + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s\n" + "\t{flight-log} ...\n", program); + exit(1); +} + +int +main (int argc, char **argv) +{ + char line[80]; + int c, i, ret; + char *s; + FILE *file; + int serial; + while ((c = getopt_long(argc, argv, "", options, NULL)) != -1) { + switch (c) { + default: + usage(argv[0]); + break; + } + } + for (i = optind; i < argc; i++) { + file = fopen(argv[i], "r"); + if (!file) { + perror(argv[i]); + ret++; + continue; + } + s = strstr(argv[i], "-serial-"); + if (s) + serial = atoi(s + 8); + else + serial = 0; + while (fgets(line, sizeof (line), file)) { + union ao_telemetry_all telem; + char call[AO_MAX_CALLSIGN+1]; + char version[AO_MAX_VERSION+1]; + + if (cc_telemetry_parse(line, &telem)) { + printf ("serial %5d tick %5d type %3d ", + telem.generic.serial, telem.generic.tick, telem.generic.type); + switch (telem.generic.type) { + case AO_TELEMETRY_SENSOR_TELEMETRUM: + case AO_TELEMETRY_SENSOR_TELEMINI: + case AO_TELEMETRY_SENSOR_TELENANO: + printf ("state %1d accel %5d pres %5d ", + telem.sensor.state, telem.sensor.accel, telem.sensor.pres); + printf ("accel %5d speed %5d height %5d ", + telem.sensor.acceleration, + telem.sensor.speed, + telem.sensor.height); + printf ("ground_pres %5d ground_accel %5d accel_plus %5d accel_minus %5d\n", + telem.sensor.ground_pres, + telem.sensor.ground_accel, + telem.sensor.accel_plus_g, + telem.sensor.accel_minus_g); + break; + case AO_TELEMETRY_CONFIGURATION: + memcpy(call, telem.configuration.callsign, AO_MAX_CALLSIGN); + memcpy(version, telem.configuration.version, AO_MAX_VERSION); + call[AO_MAX_CALLSIGN] = '\0'; + version[AO_MAX_CALLSIGN] = '\0'; + printf ("device %3d flight %5d config %3d.%03d delay %2d main %4d", + telem.configuration.device, + telem.configuration.flight, + telem.configuration.config_major, + telem.configuration.config_minor, + telem.configuration.apogee_delay, + telem.configuration.main_deploy, + telem.configuration.flight_log_max); + printf (" call %8s version %8s\n", call, version); + break; + default: + printf("\n"); + } + } + } + fclose (file); + + } + return ret; +} diff --git a/ao-tools/lib/Makefile.am b/ao-tools/lib/Makefile.am index da355db5..1f8f2e42 100644 --- a/ao-tools/lib/Makefile.am +++ b/ao-tools/lib/Makefile.am @@ -32,6 +32,8 @@ libao_tools_a_SOURCES = \ cc-bitbang.h \ cc-logfile.c \ cc-telem.c \ + cc-telemetry.c \ + cc-telemetry.h \ cp-usb-async.c \ cp-usb-async.h \ i0.c \ diff --git a/ao-tools/lib/cc-telemetry.c b/ao-tools/lib/cc-telemetry.c new file mode 100644 index 00000000..2cdb9cac --- /dev/null +++ b/ao-tools/lib/cc-telemetry.c @@ -0,0 +1,62 @@ +/* + * Copyright © 2011 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 "cc.h" +#include + +static int +parse_byte(char *data, uint8_t *byte) +{ + char d[3]; + int x; + d[0] = data[0]; + d[1] = data[1]; + d[2] = '\0'; + + if (sscanf(d, "%x", &x) != 1) + return FALSE; + *byte = x; + return TRUE; +} + +int +cc_telemetry_parse(const char *input_line, union ao_telemetry_all *telemetry) +{ + uint8_t *byte; + char *data; + uint8_t hex[35]; + int i; + + if (strncmp(input_line, "TELEM", 5) != 0) + return FALSE; + + data = strchr (input_line, ' '); + if (!data) + return FALSE; + data++; + byte = hex; + for (i = 0; i < 35; i++) { + if (!parse_byte(data, byte)) + return FALSE; + data += 2; + byte++; + } + if (hex[0] != 34) + return FALSE; + memcpy(telemetry, hex+1, 32); + return TRUE; +} diff --git a/ao-tools/lib/cc-telemetry.h b/ao-tools/lib/cc-telemetry.h new file mode 100644 index 00000000..5a66b971 --- /dev/null +++ b/ao-tools/lib/cc-telemetry.h @@ -0,0 +1,188 @@ +/* + * Copyright © 2011 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. + */ + +#ifndef _CC_TELEMETRY_H_ +#define _CC_TELEMETRY_H_ +/* + * ao_telemetry.c + */ +#define AO_MAX_CALLSIGN 8 +#define AO_MAX_VERSION 8 +#define AO_MAX_TELEMETRY 128 + +struct ao_telemetry_generic { + uint16_t serial; /* 0 */ + uint16_t tick; /* 2 */ + uint8_t type; /* 4 */ + uint8_t payload[27]; /* 5 */ + /* 32 */ +}; + +#define AO_TELEMETRY_SENSOR_TELEMETRUM 0x01 +#define AO_TELEMETRY_SENSOR_TELEMINI 0x02 +#define AO_TELEMETRY_SENSOR_TELENANO 0x03 + +struct ao_telemetry_sensor { + uint16_t serial; /* 0 */ + uint16_t tick; /* 2 */ + uint8_t type; /* 4 */ + + uint8_t state; /* 5 flight state */ + int16_t accel; /* 6 accelerometer (TM only) */ + int16_t pres; /* 8 pressure sensor */ + int16_t temp; /* 10 temperature sensor */ + int16_t v_batt; /* 12 battery voltage */ + int16_t sense_d; /* 14 drogue continuity sense (TM/Tm) */ + int16_t sense_m; /* 16 main continuity sense (TM/Tm) */ + + int16_t acceleration; /* 18 m/s² * 16 */ + int16_t speed; /* 20 m/s * 16 */ + int16_t height; /* 22 m */ + + int16_t ground_pres; /* 24 average pres on pad */ + int16_t ground_accel; /* 26 average accel on pad */ + int16_t accel_plus_g; /* 28 accel calibration at +1g */ + int16_t accel_minus_g; /* 30 accel calibration at -1g */ + /* 32 */ +}; + +#define AO_TELEMETRY_CONFIGURATION 0x04 + +struct ao_telemetry_configuration { + uint16_t serial; /* 0 */ + uint16_t tick; /* 2 */ + uint8_t type; /* 4 */ + + uint8_t device; /* 5 device type */ + uint16_t flight; /* 6 flight number */ + uint8_t config_major; /* 8 Config major version */ + uint8_t config_minor; /* 9 Config minor version */ + uint16_t apogee_delay; /* 10 Apogee deploy delay in seconds */ + uint16_t main_deploy; /* 12 Main deploy alt in meters */ + uint16_t flight_log_max; /* 14 Maximum flight log size in kB */ + char callsign[AO_MAX_CALLSIGN]; /* 16 Radio operator identity */ + char version[AO_MAX_VERSION]; /* 24 Software version */ + /* 32 */ +}; + +#define AO_TELEMETRY_LOCATION 0x05 + +#define AO_GPS_MODE_NOT_VALID 'N' +#define AO_GPS_MODE_AUTONOMOUS 'A' +#define AO_GPS_MODE_DIFFERENTIAL 'D' +#define AO_GPS_MODE_ESTIMATED 'E' +#define AO_GPS_MODE_MANUAL 'M' +#define AO_GPS_MODE_SIMULATED 'S' + +struct ao_telemetry_location { + uint16_t serial; /* 0 */ + uint16_t tick; /* 2 */ + uint8_t type; /* 4 */ + + uint8_t flags; /* 5 Number of sats and other flags */ + int16_t altitude; /* 6 GPS reported altitude (m) */ + int32_t latitude; /* 8 latitude (degrees * 10⁷) */ + int32_t longitude; /* 12 longitude (degrees * 10⁷) */ + uint8_t year; /* 16 (- 2000) */ + uint8_t month; /* 17 (1-12) */ + uint8_t day; /* 18 (1-31) */ + uint8_t hour; /* 19 (0-23) */ + uint8_t minute; /* 20 (0-59) */ + uint8_t second; /* 21 (0-59) */ + uint8_t pdop; /* 22 (m * 5) */ + uint8_t hdop; /* 23 (m * 5) */ + uint8_t vdop; /* 24 (m * 5) */ + uint8_t mode; /* 25 */ + uint16_t ground_speed; /* 26 cm/s */ + int16_t climb_rate; /* 28 cm/s */ + uint8_t course; /* 30 degrees / 2 */ + uint8_t unused[1]; /* 31 */ + /* 32 */ +}; + +#define AO_TELEMETRY_SATELLITE 0x06 + +struct ao_telemetry_satellite_info { + uint8_t svid; + uint8_t c_n_1; +}; + +struct ao_telemetry_satellite { + uint16_t serial; /* 0 */ + uint16_t tick; /* 2 */ + uint8_t type; /* 4 */ + uint8_t channels; /* 5 number of reported sats */ + + struct ao_telemetry_satellite_info sats[12]; /* 6 */ + uint8_t unused[2]; /* 30 */ + /* 32 */ +}; + +#define AO_TELEMETRY_COMPANION 0x07 + +#define AO_COMPANION_MAX_CHANNELS 12 + +struct ao_telemetry_companion { + uint16_t serial; /* 0 */ + uint16_t tick; /* 2 */ + uint8_t type; /* 4 */ + uint8_t board_id; /* 5 */ + + uint8_t update_period; /* 6 */ + uint8_t channels; /* 7 */ + uint16_t companion_data[AO_COMPANION_MAX_CHANNELS]; /* 8 */ + /* 32 */ +}; + +/* #define AO_SEND_ALL_BARO */ + +#define AO_TELEMETRY_BARO 0x80 + +/* + * This packet allows the full sampling rate baro + * data to be captured over the RF link so that the + * flight software can be tested using 'real' data. + * + * Along with this telemetry packet, the flight + * code is modified to send full-rate telemetry all the time + * and never send an RDF tone; this ensure that the full radio + * link is available. + */ +struct ao_telemetry_baro { + uint16_t serial; /* 0 */ + uint16_t tick; /* 2 */ + uint8_t type; /* 4 */ + uint8_t samples; /* 5 number samples */ + + int16_t baro[12]; /* 6 samples */ + /* 32 */ +}; + +union ao_telemetry_all { + struct ao_telemetry_generic generic; + struct ao_telemetry_sensor sensor; + struct ao_telemetry_configuration configuration; + struct ao_telemetry_location location; + struct ao_telemetry_satellite satellite; + struct ao_telemetry_companion companion; + struct ao_telemetry_baro baro; +}; + +int +cc_telemetry_parse(const char *input_line, union ao_telemetry_all *telemetry); + +#endif diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index ede46aa0..6257ee44 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -20,6 +20,7 @@ #include #include +#include "cc-telemetry.h" char * cc_fullname (char *dir, char *file); diff --git a/configure.ac b/configure.ac index 9f1921b9..1a2cc813 100644 --- a/configure.ac +++ b/configure.ac @@ -122,6 +122,7 @@ ao-tools/ao-bitbang/Makefile ao-tools/ao-eeprom/Makefile ao-tools/ao-list/Makefile ao-tools/ao-load/Makefile +ao-tools/ao-telem/Makefile ao-utils/Makefile src/Version ]) -- cgit v1.2.3 From df08b2f6de464f4546c1809b931eb4910d88b558 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 27 Oct 2011 01:01:11 -0700 Subject: altos: A bunch of missing .gitignore files (mostly) Signed-off-by: Keith Packard --- ao-tools/ao-telem/.gitignore | 1 + src/.gitignore | 1 + src/avr-demo/.gitignore | 3 + src/telepyro-v0.1/.gitignore | 2 + src/telescience-v0.1/.gitignore | 2 + src/teleterra-v0.1/.gitignore | 2 + src/teleterra-v0.1/ao_pins.h | 217 ++++++++++++++++++++++++++++++++++++++++ src/test/run-full | 31 ++++++ src/test/run-noisy | 23 +++++ 9 files changed, 282 insertions(+) create mode 100644 ao-tools/ao-telem/.gitignore create mode 100644 src/.gitignore create mode 100644 src/avr-demo/.gitignore create mode 100644 src/telepyro-v0.1/.gitignore create mode 100644 src/telescience-v0.1/.gitignore create mode 100644 src/teleterra-v0.1/.gitignore create mode 100644 src/teleterra-v0.1/ao_pins.h create mode 100755 src/test/run-full create mode 100755 src/test/run-noisy (limited to 'ao-tools') diff --git a/ao-tools/ao-telem/.gitignore b/ao-tools/ao-telem/.gitignore new file mode 100644 index 00000000..5ab6f649 --- /dev/null +++ b/ao-tools/ao-telem/.gitignore @@ -0,0 +1 @@ +ao-telem diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 00000000..7a5d6ef5 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +altitude.h diff --git a/src/avr-demo/.gitignore b/src/avr-demo/.gitignore new file mode 100644 index 00000000..e7d16343 --- /dev/null +++ b/src/avr-demo/.gitignore @@ -0,0 +1,3 @@ +avr-demo +avr-demo.hex +ao_product.h diff --git a/src/telepyro-v0.1/.gitignore b/src/telepyro-v0.1/.gitignore new file mode 100644 index 00000000..5166481c --- /dev/null +++ b/src/telepyro-v0.1/.gitignore @@ -0,0 +1,2 @@ +telepyro-v0.1* +ao_product.h diff --git a/src/telescience-v0.1/.gitignore b/src/telescience-v0.1/.gitignore new file mode 100644 index 00000000..dfccadf8 --- /dev/null +++ b/src/telescience-v0.1/.gitignore @@ -0,0 +1,2 @@ +telescience-v0.1* +ao_product.h diff --git a/src/teleterra-v0.1/.gitignore b/src/teleterra-v0.1/.gitignore new file mode 100644 index 00000000..447007ce --- /dev/null +++ b/src/teleterra-v0.1/.gitignore @@ -0,0 +1,2 @@ +teleterra-v0.1* +ao_product.h diff --git a/src/teleterra-v0.1/ao_pins.h b/src/teleterra-v0.1/ao_pins.h new file mode 100644 index 00000000..33de055e --- /dev/null +++ b/src/teleterra-v0.1/ao_pins.h @@ -0,0 +1,217 @@ +/* + * Copyright © 2011 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. + */ + +#ifndef _AO_PINS_H_ +#define _AO_PINS_H_ + +#ifdef TELETERRA_V_0_1 + #define HAS_FLIGHT 0 + #define HAS_USB 1 + #define HAS_BEEP 0 + #define HAS_GPS 0 + #define HAS_SERIAL_1 0 + #define HAS_ADC 0 + #define USE_SERIAL_STDIN 0 + #define HAS_EEPROM 1 + #define HAS_LOG 1 + #define USE_INTERNAL_FLASH 0 + #define HAS_DBG 1 + #define DBG_ON_P1 1 + #define DBG_ON_P0 0 + #define IGNITE_ON_P2 0 + #define IGNITE_ON_P0 0 + #define PACKET_HAS_MASTER 1 + #define PACKET_HAS_SLAVE 0 + + #define HAS_COMPANION 1 + #define COMPANION_CS_ON_P1 1 + #define COMPANION_CS_MASK 0x4 /* CS1 is P1_2 */ + #define COMPANION_CS P1_2 + + #define AO_LED_RED 1 + #define LEDS_AVAILABLE (AO_LED_RED) + #define HAS_EXTERNAL_TEMP 0 + #define HAS_ACCEL_REF 0 + #define HAS_ACCEL 0 + #define HAS_IGNITE 0 + #define HAS_MONITOR 1 + #define HAS_RSSI 0 + #define HAS_AES 1 + + #define SPI_CS_ON_P1 0 + #define SPI_CS_ON_P0 1 + #define M25_CS_MASK 0xf + #define M25_MAX_CHIPS 4 +#endif + +#if DBG_ON_P1 + + #define DBG_CLOCK (1 << 4) /* mi0 */ + #define DBG_DATA (1 << 5) /* mo0 */ + #define DBG_RESET_N (1 << 3) /* c0 */ + + #define DBG_CLOCK_PIN (P1_4) + #define DBG_DATA_PIN (P1_5) + #define DBG_RESET_N_PIN (P1_3) + + #define DBG_PORT_NUM 1 + #define DBG_PORT P1 + #define DBG_PORT_SEL P1SEL + #define DBG_PORT_INP P1INP + #define DBG_PORT_DIR P1DIR + +#endif /* DBG_ON_P1 */ + +#if DBG_ON_P0 + + #define DBG_CLOCK (1 << 3) + #define DBG_DATA (1 << 4) + #define DBG_RESET_N (1 << 5) + + #define DBG_CLOCK_PIN (P0_3) + #define DBG_DATA_PIN (P0_4) + #define DBG_RESET_N_PIN (P0_5) + + #define DBG_PORT_NUM 0 + #define DBG_PORT P0 + #define DBG_PORT_SEL P0SEL + #define DBG_PORT_INP P0INP + #define DBG_PORT_DIR P0DIR + +#endif /* DBG_ON_P0 */ + +#if COMPANION_CS_ON_P1 + #define COMPANION_CS_PORT P1 + #define COMPANION_CS_SEL P1SEL + #define COMPANION_CS_DIR P1DIR +#endif + +#if SPI_CS_ON_P1 + #define SPI_CS_PORT P1 + #define SPI_CS_SEL P1SEL + #define SPI_CS_DIR P1DIR +#endif + +#if SPI_CS_ON_P0 + #define SPI_CS_PORT P0 + #define SPI_CS_SEL P0SEL + #define SPI_CS_DIR P0DIR +#endif + +#ifndef IGNITE_ON_P2 +#error Please define IGNITE_ON_P2 +#endif + +#ifndef IGNITE_ON_P0 +#error Please define IGNITE_ON_P0 +#endif + +#ifndef HAS_SERIAL_1 +#error Please define HAS_SERIAL_1 +#endif + +#ifndef USE_SERIAL_STDIN +#error Please define USE_SERIAL_STDIN +#endif + +#ifndef HAS_ADC +#error Please define HAS_ADC +#endif + +#ifndef HAS_EEPROM +#error Please define HAS_EEPROM +#endif + +#ifndef HAS_LOG +#error Please define HAS_LOG +#endif + +#if HAS_EEPROM +#ifndef USE_INTERNAL_FLASH +#error Please define USE_INTERNAL_FLASH +#endif +#endif + +#ifndef HAS_DBG +#error Please define HAS_DBG +#endif + +#ifndef HAS_IGNITE +#error Please define HAS_IGNITE +#endif + +#if HAS_IGNITE +#define HAS_IGNITE_REPORT 1 +#endif + +#ifndef PACKET_HAS_MASTER +#error Please define PACKET_HAS_MASTER +#endif + +#ifndef PACKET_HAS_SLAVE +#error Please define PACKET_HAS_SLAVE +#endif + +#ifndef HAS_MONITOR +#error Please define HAS_MONITOR +#endif + +#if HAS_MONITOR +#ifndef HAS_RSSI +#error Please define HAS_RSSI +#endif +#endif + +#ifndef HAS_ADC +#error Please define HAS_ADC +#endif + +#if HAS_ADC + +#if HAS_ACCEL +#ifndef HAS_ACCEL_REF +#error Please define HAS_ACCEL_REF +#endif +#else +#define HAS_ACCEL_REF 0 +#endif + +#endif /* HAS_ADC */ + +#if IGNITE_ON_P2 +#define AO_IGNITER_DROGUE P2_3 +#define AO_IGNITER_MAIN P2_4 +#define AO_IGNITER_DIR P2DIR +#define AO_IGNITER_DROGUE_BIT (1 << 3) +#define AO_IGNITER_MAIN_BIT (1 << 4) +#endif + +#if IGNITE_ON_P0 +#define AO_IGNITER_DROGUE P0_5 +#define AO_IGNITER_MAIN P0_4 +#define AO_IGNITER_DIR P0DIR +#define AO_IGNITER_DROGUE_BIT (1 << 5) +#define AO_IGNITER_MAIN_BIT (1 << 4) +#endif + +/* test these values with real igniters */ +#define AO_IGNITER_OPEN 1000 +#define AO_IGNITER_CLOSED 7000 +#define AO_IGNITER_FIRE_TIME AO_MS_TO_TICKS(50) +#define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000) + +#endif /* _AO_PINS_H_ */ diff --git a/src/test/run-full b/src/test/run-full new file mode 100755 index 00000000..50ab7b5b --- /dev/null +++ b/src/test/run-full @@ -0,0 +1,31 @@ +#!/bin/sh + +for i in "$@"; do +./ao_flight_test "$i" > run-out.full + +#./ao_flight_test_accel "$i" > run-out.accel +#"run-out.accel" using 1:9 with lines lt 4 axes x1y1 title "accel height",\ +#"run-out.accel" using 1:11 with lines lt 4 axes x1y2 title "accel speed",\ +#"run-out.accel" using 1:13 with lines lt 4 axes x1y2 title "accel accel",\ +#"run-out.accel" using 1:15 with lines lt 4 axes x1y1 title "accel drogue",\ +#"run-out.accel" using 1:17 with lines lt 4 axes x1y1 title "accel main",\ +# + +gnuplot << EOF +set ylabel "altitude (m)" +set y2label "velocity (m/s), acceleration(m/s²)" +set xlabel "time (s)" +set xtics border out nomirror +set ytics border out nomirror +set y2tics border out nomirror +set title "$i" +plot "run-out.full" using 1:3 with lines lw 2 lt 1 axes x1y1 title "raw height",\ +"run-out.full" using 1:5 with lines lw 2 lt 2 axes x1y2 title "raw accel",\ +"run-out.full" using 1:9 with lines lt 3 axes x1y1 title "full height",\ +"run-out.full" using 1:11 with lines lt 4 axes x1y2 title "full speed",\ +"run-out.full" using 1:13 with lines lt 5 axes x1y2 title "full accel",\ +"run-out.full" using 1:17 with lines lt 6 axes x1y1 title "full drogue",\ +"run-out.full" using 1:19 with lines lt 7 axes x1y1 title "full main" +pause mouse close +EOF +done \ No newline at end of file diff --git a/src/test/run-noisy b/src/test/run-noisy new file mode 100755 index 00000000..2e3cddc7 --- /dev/null +++ b/src/test/run-noisy @@ -0,0 +1,23 @@ +#!/bin/sh + +for i in "$@"; do +./ao_flight_test_noisy_accel "$i" > run-out.noisy + +gnuplot << EOF +set ylabel "altitude (m)" +set y2label "velocity (m/s), acceleration(m/s²)" +set xlabel "time (s)" +set xtics border out nomirror +set ytics border out nomirror +set y2tics border out nomirror +set title "$i" +plot "run-out.noisy" using 1:3 with lines lw 2 lt 1 axes x1y1 title "raw height",\ +"run-out.noisy" using 1:5 with lines lw 2 lt 2 axes x1y2 title "raw accel",\ +"run-out.noisy" using 1:9 with lines lt 3 axes x1y1 title "noisy height",\ +"run-out.noisy" using 1:11 with lines lt 4 axes x1y2 title "noisy speed",\ +"run-out.noisy" using 1:13 with lines lt 5 axes x1y2 title "noisy accel",\ +"run-out.noisy" using 1:17 with lines lt 6 axes x1y1 title "noisy drogue",\ +"run-out.noisy" using 1:19 with lines lt 7 axes x1y1 title "noisy main" +pause mouse close +EOF +done \ No newline at end of file -- cgit v1.2.3 From 69feb1e3d94a028d04529edb015654bafd06353b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 1 May 2012 18:12:41 -0700 Subject: ao-tools: Add GPS and rssi printing to ao-telem This prints all of the basic telemetrum messages now. Signed-off-by: Keith Packard --- ao-tools/ao-telem/ao-telem.c | 64 +++++++++++++++++++++++++++++++++++++++----- ao-tools/lib/cc-telemetry.c | 2 +- ao-tools/lib/cc-telemetry.h | 4 ++- 3 files changed, 62 insertions(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-telem/ao-telem.c b/ao-tools/ao-telem/ao-telem.c index 0f671e1b..6207d433 100644 --- a/ao-tools/ao-telem/ao-telem.c +++ b/ao-tools/ao-telem/ao-telem.c @@ -34,6 +34,8 @@ static void usage(char *program) exit(1); } +#define bool(b) ((b) ? "true" : "false") + int main (int argc, char **argv) { @@ -63,21 +65,28 @@ main (int argc, char **argv) serial = 0; while (fgets(line, sizeof (line), file)) { union ao_telemetry_all telem; - char call[AO_MAX_CALLSIGN+1]; + char call[AO_MAX_CALLSIGN+1]; char version[AO_MAX_VERSION+1]; if (cc_telemetry_parse(line, &telem)) { - printf ("serial %5d tick %5d type %3d ", - telem.generic.serial, telem.generic.tick, telem.generic.type); + int rssi = (int8_t) telem.generic.rssi / 2 - 74; + + printf ("serial %5d rssi %d status %02x tick %5d type %3d ", + telem.generic.serial, rssi, telem.generic.status, + telem.generic.tick, telem.generic.type); + if ((telem.generic.status & (1 << 7)) == 0) { + printf ("CRC error\n"); + continue; + } switch (telem.generic.type) { case AO_TELEMETRY_SENSOR_TELEMETRUM: case AO_TELEMETRY_SENSOR_TELEMINI: case AO_TELEMETRY_SENSOR_TELENANO: printf ("state %1d accel %5d pres %5d ", telem.sensor.state, telem.sensor.accel, telem.sensor.pres); - printf ("accel %5d speed %5d height %5d ", - telem.sensor.acceleration, - telem.sensor.speed, + printf ("accel %6.2f speed %6.2f height %5d ", + telem.sensor.acceleration / 16.0, + telem.sensor.speed / 16.0, telem.sensor.height); printf ("ground_pres %5d ground_accel %5d accel_plus %5d accel_minus %5d\n", telem.sensor.ground_pres, @@ -100,6 +109,49 @@ main (int argc, char **argv) telem.configuration.flight_log_max); printf (" call %8s version %8s\n", call, version); break; + case AO_TELEMETRY_LOCATION: + printf ("sats %d flags %s%s%s%s", + telem.location.flags & 0xf, + (telem.location.flags & (1 << 4)) ? "valid" : "invalid", + (telem.location.flags & (1 << 5)) ? ",running" : "", + (telem.location.flags & (1 << 6)) ? ",date" : "", + (telem.location.flags & (1 << 7)) ? ",course" : ""); + printf (" alt %5d lat %12.7f lon %12.7f", + telem.location.altitude, + telem.location.latitude / 1e7, + telem.location.longitude / 1e7); + if ((telem.location.flags & (1 << 6)) != 0) { + printf (" year %2d month %2d day %2d", + telem.location.year, + telem.location.month, + telem.location.day); + printf (" hour %2d minute %2d second %2d", + telem.location.hour, + telem.location.minute, + telem.location.second); + } + printf (" pdop %3.1f hdop %3.1f vdop %3.1f mode %d", + telem.location.pdop / 5.0, + telem.location.hdop / 5.0, + telem.location.vdop / 5.0, + telem.location.mode); + if ((telem.location.flags & (1 << 7)) != 0) + printf (" ground_speed %6.2f climb_rate %6.2f course %d", + telem.location.ground_speed / 100.0, + telem.location.climb_rate / 100.0, + telem.location.course * 2); + printf ("\n"); + break; + case AO_TELEMETRY_SATELLITE: + printf ("sats %d", telem.satellite.channels); + for (c = 0; c < 12 && c < telem.satellite.channels; c++) { + printf (" sat %d svid %d c_n_1 %d", + c, + telem.satellite.sats[c].svid, + telem.satellite.sats[c].c_n_1); + } + printf ("\n"); + break; default: printf("\n"); } diff --git a/ao-tools/lib/cc-telemetry.c b/ao-tools/lib/cc-telemetry.c index 2cdb9cac..99da2680 100644 --- a/ao-tools/lib/cc-telemetry.c +++ b/ao-tools/lib/cc-telemetry.c @@ -57,6 +57,6 @@ cc_telemetry_parse(const char *input_line, union ao_telemetry_all *telemetry) } if (hex[0] != 34) return FALSE; - memcpy(telemetry, hex+1, 32); + memcpy(telemetry, hex+1, 34); return TRUE; } diff --git a/ao-tools/lib/cc-telemetry.h b/ao-tools/lib/cc-telemetry.h index 5a66b971..71f6844d 100644 --- a/ao-tools/lib/cc-telemetry.h +++ b/ao-tools/lib/cc-telemetry.h @@ -29,7 +29,9 @@ struct ao_telemetry_generic { uint16_t tick; /* 2 */ uint8_t type; /* 4 */ uint8_t payload[27]; /* 5 */ - /* 32 */ + uint8_t rssi; /* 32 */ + uint8_t status; /* 33 */ + /* 34 */ }; #define AO_TELEMETRY_SENSOR_TELEMETRUM 0x01 -- cgit v1.2.3 From 9b24f413da0b6d989b32e8654a91c8deee4c81dd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 17 Jun 2012 19:02:50 -0700 Subject: ao-tools: add rudimentary support for MM telemetry to ao-telem Just pretends they're TM packets for now Signed-off-by: Keith Packard --- ao-tools/ao-telem/ao-telem.c | 1 + ao-tools/lib/cc-telemetry.h | 1 + 2 files changed, 2 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/ao-telem/ao-telem.c b/ao-tools/ao-telem/ao-telem.c index 6207d433..384b2fc8 100644 --- a/ao-tools/ao-telem/ao-telem.c +++ b/ao-tools/ao-telem/ao-telem.c @@ -82,6 +82,7 @@ main (int argc, char **argv) case AO_TELEMETRY_SENSOR_TELEMETRUM: case AO_TELEMETRY_SENSOR_TELEMINI: case AO_TELEMETRY_SENSOR_TELENANO: + case AO_TELEMETRY_SENSOR_MEGAMETRUM: printf ("state %1d accel %5d pres %5d ", telem.sensor.state, telem.sensor.accel, telem.sensor.pres); printf ("accel %6.2f speed %6.2f height %5d ", diff --git a/ao-tools/lib/cc-telemetry.h b/ao-tools/lib/cc-telemetry.h index 71f6844d..4e064a97 100644 --- a/ao-tools/lib/cc-telemetry.h +++ b/ao-tools/lib/cc-telemetry.h @@ -37,6 +37,7 @@ struct ao_telemetry_generic { #define AO_TELEMETRY_SENSOR_TELEMETRUM 0x01 #define AO_TELEMETRY_SENSOR_TELEMINI 0x02 #define AO_TELEMETRY_SENSOR_TELENANO 0x03 +#define AO_TELEMETRY_SENSOR_MEGAMETRUM 0x08 struct ao_telemetry_sensor { uint16_t serial; /* 0 */ -- cgit v1.2.3 From 0b5548d6ced67201311e1072d37fbedd3d9929c9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 21 Jun 2012 09:51:17 -0700 Subject: ao-tools: Support MM telemetry packets in ao-telem Parse the new packet formats Signed-off-by: Keith Packard --- ao-tools/ao-telem/ao-telem.c | 38 ++++++++++++++++++++++++++++++- ao-tools/lib/cc-telemetry.h | 54 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-telem/ao-telem.c b/ao-tools/ao-telem/ao-telem.c index 384b2fc8..e7fc8e26 100644 --- a/ao-tools/ao-telem/ao-telem.c +++ b/ao-tools/ao-telem/ao-telem.c @@ -82,7 +82,6 @@ main (int argc, char **argv) case AO_TELEMETRY_SENSOR_TELEMETRUM: case AO_TELEMETRY_SENSOR_TELEMINI: case AO_TELEMETRY_SENSOR_TELENANO: - case AO_TELEMETRY_SENSOR_MEGAMETRUM: printf ("state %1d accel %5d pres %5d ", telem.sensor.state, telem.sensor.accel, telem.sensor.pres); printf ("accel %6.2f speed %6.2f height %5d ", @@ -152,6 +151,43 @@ main (int argc, char **argv) telem.satellite.sats[c].c_n_1); } printf ("\n"); + break; + case AO_TELEMETRY_MEGA_SENSOR: + printf ("accel %5d pres %9d temp %5d accel_x %5d accel_y %5d accel_z %5d gyro_x %5d gyro_y %5d gyro_z %5d mag_x %5d mag_y %5d mag_z %5d\n", + telem.mega_sensor.accel, + telem.mega_sensor.pres, + telem.mega_sensor.temp, + telem.mega_sensor.accel_x, + telem.mega_sensor.accel_y, + telem.mega_sensor.accel_z, + telem.mega_sensor.gyro_x, + telem.mega_sensor.gyro_y, + telem.mega_sensor.gyro_z, + telem.mega_sensor.mag_x, + telem.mega_sensor.mag_y, + telem.mega_sensor.mag_z); + break; + case AO_TELEMETRY_MEGA_DATA: + printf ("state %1d v_batt %5d v_pyro %5d ", + telem.mega_data.state, + telem.mega_data.v_batt, + telem.mega_data.v_pyro); + for (c = 0; c < 6; c++) + printf ("s%1d %5d ", c, + telem.mega_data.sense[c] | + (telem.mega_data.sense[c] << 8)); + + printf ("ground_pres %5d ground_accel %5d accel_plus %5d accel_minus %5d ", + telem.mega_data.ground_pres, + telem.mega_data.ground_accel, + telem.mega_data.accel_plus_g, + telem.mega_data.accel_minus_g); + + printf ("accel %6.2f speed %6.2f height %5d\n", + telem.mega_data.acceleration / 16.0, + telem.mega_data.speed / 16.0, + telem.mega_data.height); + break; default: printf("\n"); diff --git a/ao-tools/lib/cc-telemetry.h b/ao-tools/lib/cc-telemetry.h index 4e064a97..e849cd3b 100644 --- a/ao-tools/lib/cc-telemetry.h +++ b/ao-tools/lib/cc-telemetry.h @@ -37,7 +37,6 @@ struct ao_telemetry_generic { #define AO_TELEMETRY_SENSOR_TELEMETRUM 0x01 #define AO_TELEMETRY_SENSOR_TELEMINI 0x02 #define AO_TELEMETRY_SENSOR_TELENANO 0x03 -#define AO_TELEMETRY_SENSOR_MEGAMETRUM 0x08 struct ao_telemetry_sensor { uint16_t serial; /* 0 */ @@ -151,6 +150,57 @@ struct ao_telemetry_companion { /* 32 */ }; +#define AO_TELEMETRY_MEGA_SENSOR 0x08 + +struct ao_telemetry_mega_sensor { + uint16_t serial; /* 0 */ + uint16_t tick; /* 2 */ + uint8_t type; /* 4 */ + + uint8_t pad5; /* 5 */ + int16_t accel; /* 6 Z axis */ + + int32_t pres; /* 8 Pa * 10 */ + int16_t temp; /* 12 °C * 100 */ + + int16_t accel_x; /* 14 */ + int16_t accel_y; /* 16 */ + int16_t accel_z; /* 18 */ + + int16_t gyro_x; /* 20 */ + int16_t gyro_y; /* 22 */ + int16_t gyro_z; /* 24 */ + + int16_t mag_x; /* 26 */ + int16_t mag_y; /* 28 */ + int16_t mag_z; /* 30 */ + /* 32 */ +}; + +#define AO_TELEMETRY_MEGA_DATA 0x09 + +struct ao_telemetry_mega_data { + 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 v_pyro; /* 8 pyro battery voltage */ + int8_t sense[6]; /* 10 continuity sense */ + + int32_t ground_pres; /* 16 average pres on pad */ + int16_t ground_accel; /* 20 average accel on pad */ + int16_t accel_plus_g; /* 22 accel calibration at +1g */ + int16_t accel_minus_g; /* 24 accel calibration at -1g */ + + int16_t acceleration; /* 26 m/s² * 16 */ + int16_t speed; /* 28 m/s * 16 */ + int16_t height; /* 30 m */ + /* 32 */ +}; + /* #define AO_SEND_ALL_BARO */ #define AO_TELEMETRY_BARO 0x80 @@ -182,6 +232,8 @@ union ao_telemetry_all { struct ao_telemetry_location location; struct ao_telemetry_satellite satellite; struct ao_telemetry_companion companion; + struct ao_telemetry_mega_sensor mega_sensor; + struct ao_telemetry_mega_data mega_data; struct ao_telemetry_baro baro; }; -- cgit v1.2.3 From 20877ae9de8bb5d3a29e2a96024e53afbd396f55 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 17 Jul 2012 01:18:45 -0700 Subject: Add ao-stmload tool This loads an ELF image through the STlink programming interface using the stlink utility library Signed-off-by: Keith Packard --- ao-tools/Makefile.am | 2 +- ao-tools/ao-stmload/Makefile.am | 14 + ao-tools/ao-stmload/ao-stmload.1 | 61 ++++ ao-tools/ao-stmload/ao-stmload.c | 591 +++++++++++++++++++++++++++++++++++++++ configure.ac | 1 + 5 files changed, 668 insertions(+), 1 deletion(-) create mode 100644 ao-tools/ao-stmload/Makefile.am create mode 100644 ao-tools/ao-stmload/ao-stmload.1 create mode 100644 ao-tools/ao-stmload/ao-stmload.c (limited to 'ao-tools') diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 611bb7dc..6c315dd1 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list ao-load ao-telem +SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list ao-load ao-telem ao-stmload diff --git a/ao-tools/ao-stmload/Makefile.am b/ao-tools/ao-stmload/Makefile.am new file mode 100644 index 00000000..77979daf --- /dev/null +++ b/ao-tools/ao-stmload/Makefile.am @@ -0,0 +1,14 @@ +bin_PROGRAMS=ao-stmload + +LIBSTLINKDIR=/local/src/stlink + +AM_CFLAGS=-I$(LIBSTLINKDIR)/src $(LIBUSB_CFLAGS) -I../lib + +AO_STMLOAD_LIBS=$(LIBSTLINKDIR)/libstlink.a +ao_stmload_DEPENDENCIES = $(AO_STMLOAD_LIBS) + +ao_stmload_LDADD=$(AO_STMLOAD_LIBS) $(LIBUSB_LIBS) -lelf + +ao_stmload_SOURCES=ao-stmload.c + +man_MANS = ao-stmload.1 diff --git a/ao-tools/ao-stmload/ao-stmload.1 b/ao-tools/ao-stmload/ao-stmload.1 new file mode 100644 index 00000000..38e9c177 --- /dev/null +++ b/ao-tools/ao-stmload/ao-stmload.1 @@ -0,0 +1,61 @@ +.\" +.\" 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-stmload" "" +.SH NAME +ao-stmload \- flash a program to an STM32-based AltOS device +.SH SYNOPSIS +.B "ao-stmload" +[\-D \fI/dev/sgX\fP] +[\--device \fI/dev/sgX\fP] +[\--cal \fIradio-calibration\fP] +[\--serial \fserial-number\fP] +\fIfile.elf\fP +.SH DESCRIPTION +.I ao-stmload +loads the specified .elf file into the target device flash memory, +using either existing serial number and radio calibration values or +taking either of those from the command line. +.SH OPTIONS +.TP +\-D /dev/sgX | --device /dev/sgX +This targets an STlinkV1 connection rather than STlinkV2 +.TP +\-s serial-number | --serial serial-number +This programs the device serial number into the image. If no serial +number is specified, then the existing serial number, if any, will be +read from the device. +.TP +\-c radio-calibration | --cal radio-calibration This programs the +radio calibration value into the image for hardware which doesn't have +any eeprom storage for this value. If no calibration value is +specified, an existing calibration value will be used. The value here +can be computed given the current radio calibration value, the +measured frequency and the desired frequency: +.IP + cal' = cal * (desired/measured) +.IP +The default calibration value is 7119667. +.SH USAGE +.I ao-stmload +reads the specified .elf file into memory, edits the image to +customize it using the specified serial number and radio calibration +values. It then connects to the debug dongle and writes the program to +the target device flash memory. +.SH AUTHOR +Keith Packard diff --git a/ao-tools/ao-stmload/ao-stmload.c b/ao-tools/ao-stmload/ao-stmload.c new file mode 100644 index 00000000..e689539b --- /dev/null +++ b/ao-tools/ao-stmload/ao-stmload.c @@ -0,0 +1,591 @@ +/* + * Copyright © 2012 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 "stlink-common.h" + +#define AO_USB_DESC_STRING 3 + +struct sym { + unsigned addr; + char *name; + int required; +} ao_symbols[] = { + + { 0, "ao_romconfig_version", 1 }, +#define AO_ROMCONFIG_VERSION (ao_symbols[0].addr) + + { 0, "ao_romconfig_check", 1 }, +#define AO_ROMCONFIG_CHECK (ao_symbols[1].addr) + + { 0, "ao_serial_number", 1 }, +#define AO_SERIAL_NUMBER (ao_symbols[2].addr) + + { 0, "ao_usb_descriptors", 0 }, +#define AO_USB_DESCRIPTORS (ao_symbols[3].addr) + + { 0, "ao_radio_cal", 0 }, +#define AO_RADIO_CAL (ao_symbols[4].addr) +}; + +#define NUM_SYMBOLS 5 +#define NUM_REQUIRED_SYMBOLS 3 + +/* + * Look through the Elf file for the AltOS symbols + * that can be adjusted before the image is written + * to the device + */ +static int +find_symbols (Elf *e) +{ + Elf_Scn *scn; + Elf_Data *symbol_data = NULL; + GElf_Shdr shdr; + GElf_Sym sym; + int i, symbol_count, s; + int required = 0; + char *symbol_name; + + /* + * Find the symbols + */ + + scn = NULL; + while ((scn = elf_nextscn(e, scn)) != NULL) { + if (gelf_getshdr(scn, &shdr) != &shdr) + return 0; + + if (shdr.sh_type == SHT_SYMTAB) { + symbol_data = elf_getdata(scn, NULL); + symbol_count = shdr.sh_size / shdr.sh_entsize; + break; + } + } + + if (!symbol_data) + return 0; + + for (i = 0; i < symbol_count; i++) { + gelf_getsym(symbol_data, i, &sym); + + symbol_name = elf_strptr(e, shdr.sh_link, sym.st_name); + + for (s = 0; s < NUM_SYMBOLS; s++) + if (!strcmp (ao_symbols[s].name, symbol_name)) { + int t; + ao_symbols[s].addr = sym.st_value; + if (ao_symbols[s].required) + ++required; + } + } + + return required >= NUM_REQUIRED_SYMBOLS; +} + +struct load { + uint32_t addr; + uint32_t len; + uint8_t buf[0]; +}; + +struct load * +new_load (uint32_t addr, uint32_t len) +{ + struct load *new = calloc (1, sizeof (struct load) + len); + if (!new) + abort(); + + new->addr = addr; + new->len = len; + return new; +} + +void +load_paste(struct load *into, struct load *from) +{ + if (from->addr < into->addr || into->addr + into->len < from->addr + from->len) + abort(); + + memcpy(into->buf + from->addr - into->addr, from->buf, from->len); +} + +/* + * Make a new load structure large enough to hold the old one and + * the new data + */ +struct load * +expand_load(struct load *from, uint32_t addr, uint32_t len) +{ + struct load *new; + + if (from) { + uint32_t from_last = from->addr + from->len; + uint32_t last = addr + len; + + if (addr > from->addr) + addr = from->addr; + if (last < from_last) + last = from_last; + + len = last - addr; + + if (addr == from->addr && len == from->len) + return from; + } + new = new_load(addr, len); + if (from) { + load_paste(new, from); + free (from); + } + return new; +} + +/* + * Create a new load structure with data from the existing one + * and the new data + */ +struct load * +load_write(struct load *from, uint32_t addr, uint32_t len, void *data) +{ + struct load *new; + + new = expand_load(from, addr, len); + memcpy(new->buf + addr - new->addr, data, len); + return new; +} + +/* + * Construct a large in-memory block for all + * of the loaded sections of the program + */ +static struct load * +get_load(Elf *e) +{ + Elf_Scn *scn; + size_t shstrndx; + GElf_Shdr shdr; + Elf_Data *data; + uint8_t *buf; + char *got_name; + size_t nphdr; + int p; + GElf_Phdr phdr; + struct load *load = NULL; + + if (elf_getshdrstrndx(e, &shstrndx) < 0) + return 0; + + if (elf_getphdrnum(e, &nphdr) < 0) + return 0; + + /* + * As far as I can tell, all of the phdr sections should + * be flashed to memory + */ + for (p = 0; p < nphdr; p++) { + + /* Find this phdr */ + gelf_getphdr(e, p, &phdr); + + /* Get the associated file section */ + scn = gelf_offscn(e, phdr.p_offset); + + if (gelf_getshdr(scn, &shdr) != &shdr) + abort(); + + data = elf_getdata(scn, NULL); + + /* Write the section data into the memory block */ + load = load_write(load, phdr.p_paddr, phdr.p_filesz, data->d_buf); + } + return load; +} + +/* + * Edit the to-be-written memory block + */ +static int +rewrite(struct load *load, unsigned addr, uint8_t *data, int len) +{ + int i; + + if (addr < load->addr || load->addr + load->len < addr + len) + return 0; + + printf("rewrite %04x:", addr); + for (i = 0; i < len; i++) + printf (" %02x", load->buf[addr - load->addr + i]); + printf(" ->"); + for (i = 0; i < len; i++) + printf (" %02x", data[i]); + printf("\n"); + memcpy(load->buf + addr - load->addr, data, len); +} + +/* + * Open the specified ELF file and + * check for the symbols we need + */ + +Elf * +ao_open_elf(char *name) +{ + int fd; + Elf *e; + Elf_Scn *scn; + Elf_Data *symbol_data = NULL; + GElf_Shdr shdr; + GElf_Sym sym; + size_t n, shstrndx, sz; + int i, symbol_count, s; + int required = 0; + + if (elf_version(EV_CURRENT) == EV_NONE) + return NULL; + + fd = open(name, O_RDONLY, 0); + + if (fd < 0) + return NULL; + + e = elf_begin(fd, ELF_C_READ, NULL); + + if (!e) + return NULL; + + if (elf_kind(e) != ELF_K_ELF) + return NULL; + + if (elf_getshdrstrndx(e, &shstrndx) != 0) + return NULL; + + if (!find_symbols(e)) { + fprintf (stderr, "Cannot find required symbols\n"); + return NULL; + } + + return e; +} + +/* + * Read a 32-bit value from the target device with arbitrary + * alignment + */ +static uint32_t +get_uint32(stlink_t *sl, uint32_t addr) +{ + const uint8_t *data = sl->q_buf; + uint32_t actual_addr; + int off; + uint32_t result; + + sl->q_len = 0; + + printf ("read 0x%x\n", addr); + + actual_addr = addr & ~3; + + stlink_read_mem32(sl, actual_addr, 8); + + if (sl->q_len != 8) + abort(); + + off = addr & 3; + result = data[off] | (data[off + 1] << 8) | (data[off+2] << 16) | (data[off+3] << 24); + printf ("read 0x%08x = 0x%08x\n", addr, result); + return result; +} + +/* + * Read a 16-bit value from the target device with arbitrary + * alignment + */ +static uint16_t +get_uint16(stlink_t *sl, uint32_t addr) +{ + const uint8_t *data = sl->q_buf; + uint32_t actual_addr; + int off; + uint16_t result; + + sl->q_len = 0; + + + actual_addr = addr & ~3; + + stlink_read_mem32(sl, actual_addr, 8); + + if (sl->q_len != 8) + abort(); + + off = addr & 3; + result = data[off] | (data[off + 1] << 8); + printf ("read 0x%08x = 0x%04x\n", addr, result); + return result; +} + +/* + * Check to see if the target device has been + * flashed with a similar firmware image before + * + * This is done by looking for the same romconfig version, + * which should be at the same location as the linker script + * places this at 0x100 from the start of the rom section + */ +static int +check_flashed(stlink_t *sl) +{ + uint16_t romconfig_version = get_uint16(sl, AO_ROMCONFIG_VERSION); + uint16_t romconfig_check = get_uint16(sl, AO_ROMCONFIG_CHECK); + + if (romconfig_version != (uint16_t) ~romconfig_check) { + fprintf (stderr, "Device has not been flashed before\n"); + return 0; + } + return 1; +} + +static const struct option options[] = { + { .name = "device", .has_arg = 1, .val = 'D' }, + { .name = "cal", .has_arg = 1, .val = 'c' }, + { .name = "serial", .has_arg = 1, .val = 's' }, + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s [--cal=] [--serial=] file.elf\n", program); + exit(1); +} + +void +done(stlink_t *sl, int code) +{ + if (sl) { + stlink_reset(sl); + stlink_run(sl); + stlink_exit_debug_mode(sl); + stlink_close(sl); + } + exit (code); +} + +int +main (int argc, char **argv) +{ + char *device = NULL; + char *filename; + Elf *e; + char *serial_end; + unsigned int serial = 0; + char *serial_ucs2; + int serial_ucs2_len; + char serial_int[2]; + unsigned int s; + int i; + int string_num; + uint32_t cal = 0; + char cal_int[4]; + char *cal_end; + int c; + stlink_t *sl; + int was_flashed = 0; + struct load *load; + + while ((c = getopt_long(argc, argv, "D:c:s:", options, NULL)) != -1) { + switch (c) { + case 'D': + device = optarg; + break; + case 'c': + cal = strtoul(optarg, &cal_end, 10); + if (cal_end == optarg || *cal_end != '\0') + usage(argv[0]); + break; + case 's': + serial = strtoul(optarg, &serial_end, 10); + if (serial_end == optarg || *serial_end != '\0') + usage(argv[0]); + break; + default: + usage(argv[0]); + break; + } + } + + filename = argv[optind]; + if (filename == NULL) + usage(argv[0]); + + /* + * Open the source file and load the symbols and + * flash data + */ + + e = ao_open_elf(filename); + if (!e) { + fprintf(stderr, "Cannot open file \"%s\"\n", filename); + exit(1); + } + + if (!find_symbols(e)) { + fprintf(stderr, "Cannot find symbols in \"%s\"\n", filename); + exit(1); + } + + if (!(load = get_load(e))) { + fprintf(stderr, "Cannot find program data in \"%s\"\n", filename); + exit(1); + } + + /* Connect to the programming dongle + */ + + if (device) { + sl = stlink_v1_open(50); + } else { + sl = stlink_open_usb(50); + + } + if (!sl) { + fprintf (stderr, "No STLink devices present\n"); + done (sl, 1); + } + + sl->verbose = 50; + + /* Verify that the loaded image fits entirely within device flash + */ + if (load->addr < sl->flash_base || + sl->flash_base + sl->flash_size < load->addr + load->len) { + fprintf (stderr, "\%s\": Invalid memory range 0x%08x - 0x%08x\n", filename, + load->addr, load->addr + load->len); + done(sl, 1); + } + + /* Enter debugging mode + */ + if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) + stlink_exit_dfu_mode(sl); + + if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) + stlink_enter_swd_mode(sl); + + /* Go fetch existing config values + * if available + */ + was_flashed = check_flashed(sl); + + if (!serial) { + if (!was_flashed) { + fprintf (stderr, "Must provide serial number\n"); + done(sl, 1); + } + serial = get_uint16(sl, AO_SERIAL_NUMBER); + if (!serial || serial == 0xffff) { + fprintf (stderr, "Invalid existing serial %d\n", serial); + done(sl, 1); + } + } + + if (!cal && AO_RADIO_CAL && was_flashed) { + cal = get_uint32(sl, AO_RADIO_CAL); + if (!cal || cal == 0xffffffff) { + fprintf (stderr, "Invalid existing rf cal %d\n", cal); + done(sl, 1); + } + } + + /* Write the config values into the flash image + */ + + serial_int[0] = serial & 0xff; + serial_int[1] = (serial >> 8) & 0xff; + + if (!rewrite(load, AO_SERIAL_NUMBER, serial_int, sizeof (serial_int))) { + fprintf(stderr, "Cannot rewrite serial integer at %08x\n", + AO_SERIAL_NUMBER); + done(sl, 1); + } + + if (AO_USB_DESCRIPTORS) { + unsigned usb_descriptors; + usb_descriptors = AO_USB_DESCRIPTORS - load->addr; + string_num = 0; + + while (load->buf[usb_descriptors] != 0 && usb_descriptors < load->len) { + if (load->buf[usb_descriptors+1] == AO_USB_DESC_STRING) { + ++string_num; + if (string_num == 4) + break; + } + usb_descriptors += load->buf[usb_descriptors]; + } + if (usb_descriptors >= load->len || load->buf[usb_descriptors] == 0 ) { + fprintf(stderr, "Cannot rewrite serial string at %08x\n", AO_USB_DESCRIPTORS); + done(sl, 1); + } + + serial_ucs2_len = load->buf[usb_descriptors] - 2; + serial_ucs2 = malloc(serial_ucs2_len); + if (!serial_ucs2) { + fprintf(stderr, "Malloc(%d) failed\n", serial_ucs2_len); + done(sl, 1); + } + s = serial; + for (i = serial_ucs2_len / 2; i; i--) { + serial_ucs2[i * 2 - 1] = 0; + serial_ucs2[i * 2 - 2] = (s % 10) + '0'; + s /= 10; + } + if (!rewrite(load, usb_descriptors + 2 + load->addr, serial_ucs2, serial_ucs2_len)) { + fprintf (stderr, "Cannot rewrite USB descriptor at %08x\n", AO_USB_DESCRIPTORS); + done(sl, 1); + } + } + + if (cal && AO_RADIO_CAL) { + cal_int[0] = cal & 0xff; + cal_int[1] = (cal >> 8) & 0xff; + cal_int[2] = (cal >> 16) & 0xff; + cal_int[3] = (cal >> 24) & 0xff; + + if (!rewrite(load, AO_RADIO_CAL, cal_int, sizeof (cal_int))) { + fprintf(stderr, "Cannot rewrite radio calibration at %08x\n", AO_RADIO_CAL); + exit(1); + } + } + + /* And flash the resulting image to the device + */ + if (stlink_write_flash(sl, load->addr, load->buf, load->len) < 0) { + fprintf (stderr, "\"%s\": Write failed\n", filename); + done(sl, 1); + } + + done(sl, 0); +} diff --git a/configure.ac b/configure.ac index e78f5873..10bf9abf 100644 --- a/configure.ac +++ b/configure.ac @@ -154,6 +154,7 @@ ao-tools/ao-eeprom/Makefile ao-tools/ao-list/Makefile ao-tools/ao-load/Makefile ao-tools/ao-telem/Makefile +ao-tools/ao-stmload/Makefile ao-utils/Makefile src/Version ]) -- cgit v1.2.3 From a5d873d47b3b16ca32559b4de668bf07b25eddb0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 17 Jul 2012 01:24:52 -0700 Subject: altos: Place STM config values at fixed addresses for re-use Just like cc1111, stick the serial number and radio calibration values at known fixed addresses so that when re-flashing the board, we can go find the existing values. Signed-off-by: Keith Packard --- ao-tools/ao-load/ao-load.c | 2 +- src/avr/ao_arch.h | 6 +++++- src/avr/ao_romconfig.c | 2 +- src/cc1111/ao_arch.h | 10 ++++++---- src/core/ao_product.c | 2 +- src/drivers/ao_cc1120.c | 2 +- src/drivers/ao_companion.c | 4 +++- src/megametrum-v0.1/Makefile | 2 +- src/megametrum-v0.1/ao_pins.h | 4 ++++ src/stm-bringup/Makefile | 4 ++-- src/stm/altos.ld | 21 +++++++++++---------- src/stm/ao_arch.h | 12 ++++++++++++ src/stm/ao_romconfig.c | 7 ++++++- 13 files changed, 54 insertions(+), 24 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-load/ao-load.c b/ao-tools/ao-load/ao-load.c index 1b729d39..e3cef4a5 100644 --- a/ao-tools/ao-load/ao-load.c +++ b/ao-tools/ao-load/ao-load.c @@ -197,7 +197,7 @@ main (int argc, char **argv) serial = strtoul(serial_string, NULL, 0); if (!serial) -(argv[0]); + usage(argv[0]); serial_int[0] = serial & 0xff; serial_int[1] = (serial >> 8) & 0xff; diff --git a/src/avr/ao_arch.h b/src/avr/ao_arch.h index c775dab6..a14d0ade 100644 --- a/src/avr/ao_arch.h +++ b/src/avr/ao_arch.h @@ -67,7 +67,11 @@ extern void putchar(char c); extern char getchar(void); extern void ao_avr_stdio_init(void); -extern const uint16_t ao_serial_number; +#define AO_ROMCONFIG_VERSION 2 + +#define AO_ROMCONFIG_SYMBOL(a) const + +extern AO_ROMCONFIG_SYMBOL(0) uint16_t ao_serial_number; #define AVR_PUSH8(stack, val) (*((stack)--) = (val)) diff --git a/src/avr/ao_romconfig.c b/src/avr/ao_romconfig.c index bbb677e2..ecc19c76 100644 --- a/src/avr/ao_romconfig.c +++ b/src/avr/ao_romconfig.c @@ -17,4 +17,4 @@ #include "ao.h" -const uint16_t ao_serial_number = 0; +AO_ROMCONFIG_SYMBOL (0) uint16_t ao_serial_number = 0; diff --git a/src/cc1111/ao_arch.h b/src/cc1111/ao_arch.h index 8d9e4952..06b04b93 100644 --- a/src/cc1111/ao_arch.h +++ b/src/cc1111/ao_arch.h @@ -59,10 +59,12 @@ #define AO_ROMCONFIG_VERSION 2 -extern __code __at (0x00a0) uint16_t ao_romconfig_version; -extern __code __at (0x00a2) uint16_t ao_romconfig_check; -extern __code __at (0x00a4) uint16_t ao_serial_number; -extern __code __at (0x00a6) uint32_t ao_radio_cal; +#define AO_ROMCONFIG_SYMBOL(a) __code __at(a) + +extern AO_ROMCONFIG_SYMBOL(0x00a0) uint16_t ao_romconfig_version; +extern AO_ROMCONFIG_SYMBOL(0x00a2) uint16_t ao_romconfig_check; +extern AO_ROMCONFIG_SYMBOL(0x00a4) uint16_t ao_serial_number; +extern AO_ROMCONFIG_SYMBOL(0x00a6) uint32_t ao_radio_cal; #ifndef HAS_USB #error Please define HAS_USB diff --git a/src/core/ao_product.c b/src/core/ao_product.c index 67ec6793..ec91b978 100644 --- a/src/core/ao_product.c +++ b/src/core/ao_product.c @@ -29,7 +29,7 @@ const char ao_product[] = AO_iProduct_STRING; #if HAS_USB #include "ao_usb.h" /* USB descriptors in one giant block of bytes */ -__code __at(0x00aa) uint8_t ao_usb_descriptors [] = +AO_ROMCONFIG_SYMBOL(0x00aa) uint8_t ao_usb_descriptors [] = { /* Device descriptor */ 0x12, diff --git a/src/drivers/ao_cc1120.c b/src/drivers/ao_cc1120.c index 569df3b7..97a434d8 100644 --- a/src/drivers/ao_cc1120.c +++ b/src/drivers/ao_cc1120.c @@ -29,7 +29,7 @@ uint8_t ao_radio_in_recv; #define CC1120_DEBUG AO_FEC_DEBUG #define CC1120_TRACE 0 -const uint32_t ao_radio_cal = 0x6ca333; +extern const uint32_t ao_radio_cal; #define FOSC 32000000 diff --git a/src/drivers/ao_companion.c b/src/drivers/ao_companion.c index 6e0bd2ec..c749adea 100644 --- a/src/drivers/ao_companion.c +++ b/src/drivers/ao_companion.c @@ -68,7 +68,7 @@ ao_companion_get_setup(void) ao_spi_recv(&ao_companion_setup, sizeof (ao_companion_setup), AO_COMPANION_SPI_BUS); COMPANION_DESELECT(); return (ao_companion_setup.board_id == - ~ao_companion_setup.board_id_inverse); + (uint16_t) ~ao_companion_setup.board_id_inverse); } static void @@ -116,6 +116,8 @@ ao_companion_status(void) __reentrant { uint8_t i; printf("Companion running: %d\n", ao_companion_running); + if (!ao_companion_running) + return; printf("device: %d\n", ao_companion_setup.board_id); printf("update period: %d\n", ao_companion_setup.update_period); printf("channels: %d\n", ao_companion_setup.channels); diff --git a/src/megametrum-v0.1/Makefile b/src/megametrum-v0.1/Makefile index a519609e..4a4c983a 100644 --- a/src/megametrum-v0.1/Makefile +++ b/src/megametrum-v0.1/Makefile @@ -92,7 +92,7 @@ OBJ=$(SRC:.c=.o) all: $(PROG) -$(PROG): Makefile $(OBJ) +$(PROG): Makefile $(OBJ) altos.ld $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(SAT_CLIB) -lgcc ../altitude.h: make-altitude diff --git a/src/megametrum-v0.1/ao_pins.h b/src/megametrum-v0.1/ao_pins.h index 2c438f6c..6b0f9832 100644 --- a/src/megametrum-v0.1/ao_pins.h +++ b/src/megametrum-v0.1/ao_pins.h @@ -268,6 +268,10 @@ struct ao_adc { * Radio (cc1120) */ +/* gets pretty close to 434.550 */ + +#define AO_RADIO_CAL_DEFAULT 0x6ca333 + #define AO_FEC_DEBUG 0 #define AO_CC1120_SPI_CS_PORT (&stm_gpioc) #define AO_CC1120_SPI_CS_PIN 5 diff --git a/src/stm-bringup/Makefile b/src/stm-bringup/Makefile index 01c80614..d45e836d 100644 --- a/src/stm-bringup/Makefile +++ b/src/stm-bringup/Makefile @@ -16,7 +16,7 @@ DEF_CFLAGS=-g -std=gnu99 -Os -mlittle-endian -mthumb -ffreestanding -nostdlib -I # to run from SRAM LD_FLAGS_RAM=-L../stm -Wl,-Taltos-ram.ld -LD_FLAGS=-L../stm -Wl,-Taltos.ld +LD_FLAGS=-L../stm -Wl,-Tbringup.ld CFLAGS=$(DEF_CFLAGS) -mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY @@ -28,7 +28,7 @@ all: bringup-ram.elf bringup.elf %.bin: %.elf $(OBJCOPY) -O binary $^ $@ -bringup.elf: $(OBJ) $(C_LIB) altos.ld +bringup.elf: $(OBJ) $(C_LIB) bringup.ld $(CC) $(CFLAGS) $(LD_FLAGS) -o $@ $(OBJ) $(C_LIB) -lgcc bringup-ram.elf: $(OBJ) $(C_LIB) altos-ram.ld diff --git a/src/stm/altos.ld b/src/stm/altos.ld index f5a84f4c..f78a45d6 100644 --- a/src/stm/altos.ld +++ b/src/stm/altos.ld @@ -25,18 +25,22 @@ INCLUDE registers.ld EXTERN (stm_interrupt_vector) SECTIONS { - . = ORIGIN(rom); - /* * Rom contents */ - __text_start__ = .; - - .text : { + .text ORIGIN(rom) : { + __text_start__ = .; *(.interrupt) /* Interrupt vectors */ + + . = ORIGIN(rom) + 0x100; + + ao_romconfig.o(.romconfig*) + ao_product.o(.romconfig*) + *(.text*) /* Executable code */ *(.rodata*) /* Constants */ + } > rom .ARM.exidx : { @@ -44,12 +48,10 @@ SECTIONS { __text_end__ = .; } > rom - . = ORIGIN(ram); - __data_start__ = .; - /* Data -- relocated to RAM, but written to ROM */ - .data : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) { + .data ORIGIN(ram) : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) { + __data_start__ = .; *(.data) /* initialized data */ __data_end__ = .; __bss_start__ = .; @@ -63,7 +65,6 @@ SECTIONS { PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram)); PROVIDE(end = .); - } ENTRY(start); diff --git a/src/stm/ao_arch.h b/src/stm/ao_arch.h index d8fa3e89..484ce89e 100644 --- a/src/stm/ao_arch.h +++ b/src/stm/ao_arch.h @@ -59,7 +59,19 @@ extern void putchar(char c); extern char getchar(void); extern void ao_avr_stdio_init(void); + +/* + * ao_romconfig.c + */ + +#define AO_ROMCONFIG_VERSION 2 + +#define AO_ROMCONFIG_SYMBOL(a) __attribute__((section(".romconfig"))) const + +extern const uint16_t ao_romconfig_version; +extern const uint16_t ao_romconfig_check; extern const uint16_t ao_serial_number; +extern const uint32_t ao_radio_cal; #define ARM_PUSH32(stack, val) (*(--(stack)) = (val)) diff --git a/src/stm/ao_romconfig.c b/src/stm/ao_romconfig.c index 84317458..cbb922ec 100644 --- a/src/stm/ao_romconfig.c +++ b/src/stm/ao_romconfig.c @@ -17,4 +17,9 @@ #include "ao.h" -const uint16_t ao_serial_number = 58; +AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_version = AO_ROMCONFIG_VERSION; +AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_check = ~AO_ROMCONFIG_VERSION; +AO_ROMCONFIG_SYMBOL (0) uint16_t ao_serial_number = 0; +#ifdef AO_RADIO_CAL_DEFAULT +AO_ROMCONFIG_SYMBOL (0) uint32_t ao_radio_cal = AO_RADIO_CAL_DEFAULT; +#endif -- cgit v1.2.3 From 38f66a31174dd367e39d717c527f555add60a9d4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 20 Jul 2012 12:04:17 -0700 Subject: tools: Use pkgconfig to find stlink for ao-stmload Signed-off-by: Keith Packard --- ao-tools/ao-stmload/Makefile.am | 7 ++----- configure.ac | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-stmload/Makefile.am b/ao-tools/ao-stmload/Makefile.am index 77979daf..375896ea 100644 --- a/ao-tools/ao-stmload/Makefile.am +++ b/ao-tools/ao-stmload/Makefile.am @@ -2,12 +2,9 @@ bin_PROGRAMS=ao-stmload LIBSTLINKDIR=/local/src/stlink -AM_CFLAGS=-I$(LIBSTLINKDIR)/src $(LIBUSB_CFLAGS) -I../lib +AM_CFLAGS=$(LIBSTLINK_CFLAGS) $(LIBUSB_CFLAGS) -I../lib -AO_STMLOAD_LIBS=$(LIBSTLINKDIR)/libstlink.a -ao_stmload_DEPENDENCIES = $(AO_STMLOAD_LIBS) - -ao_stmload_LDADD=$(AO_STMLOAD_LIBS) $(LIBUSB_LIBS) -lelf +ao_stmload_LDADD=$(LIBSTLINK_LIBS) $(LIBUSB_LIBS) -lelf ao_stmload_SOURCES=ao-stmload.c diff --git a/configure.ac b/configure.ac index 10bf9abf..bcd2dcac 100644 --- a/configure.ac +++ b/configure.ac @@ -136,6 +136,11 @@ AC_CHECK_LIB(readline, readline) PKG_CHECK_MODULES([LIBUSB], [libusb-1.0]) +AC_CHECK_HEADERS(libelf.h libelf/libelf.h, [break]) +AC_CHECK_HEADERS(gelf.h libelf/gelf.h, [break]) + +PKG_CHECK_MODULES([LIBSTLINK], [stlink]) + AC_OUTPUT([ Makefile altoslib/Makefile -- cgit v1.2.3 From 59588ba34159b27c02e1a886b46497ecfa0cf4d3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Jul 2012 16:22:23 -0700 Subject: Add ability to re-play telemetry through TeleDongle This adds a new command to TeleDongle to send arbitrary data, and then creates a new tool, 'ao-send-telem' that replays existing telemetry files through TeleDongle. Signed-off-by: Keith Packard --- ao-tools/Makefile.am | 2 +- ao-tools/ao-send-telem/Makefile.am | 12 ++ ao-tools/ao-send-telem/ao-send-telem.1 | 64 +++++++++ ao-tools/ao-send-telem/ao-send-telem.c | 238 +++++++++++++++++++++++++++++++++ configure.ac | 1 + src/core/ao_send_packet.c | 74 ++++++++++ src/core/ao_send_packet.h | 24 ++++ src/product/Makefile.teledongle | 1 + src/product/ao_teledongle.c | 2 + 9 files changed, 417 insertions(+), 1 deletion(-) create mode 100644 ao-tools/ao-send-telem/Makefile.am create mode 100644 ao-tools/ao-send-telem/ao-send-telem.1 create mode 100644 ao-tools/ao-send-telem/ao-send-telem.c create mode 100644 src/core/ao_send_packet.c create mode 100644 src/core/ao_send_packet.h (limited to 'ao-tools') diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 6c315dd1..257fdaec 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list ao-load ao-telem ao-stmload +SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list ao-load ao-telem ao-stmload ao-send-telem diff --git a/ao-tools/ao-send-telem/Makefile.am b/ao-tools/ao-send-telem/Makefile.am new file mode 100644 index 00000000..bfddf131 --- /dev/null +++ b/ao-tools/ao-send-telem/Makefile.am @@ -0,0 +1,12 @@ +bin_PROGRAMS=ao-send-telem + +AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS) +AO_POSTFLIGHT_LIBS=$(top_builddir)/ao-tools/lib/libao-tools.a + +ao_send_telem_DEPENDENCIES = $(AO_POSTFLIGHT_LIBS) + +ao_send_telem_LDADD=$(AO_POSTFLIGHT_LIBS) $(LIBUSB_LIBS) + +ao_send_telem_SOURCES = ao-send-telem.c + +man_MANS = ao-send-telem.1 diff --git a/ao-tools/ao-send-telem/ao-send-telem.1 b/ao-tools/ao-send-telem/ao-send-telem.1 new file mode 100644 index 00000000..fbdb2fe9 --- /dev/null +++ b/ao-tools/ao-send-telem/ao-send-telem.1 @@ -0,0 +1,64 @@ +.\" +.\" 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-SEND-TELEM 1 "ao-send-telem" "" +.SH NAME +ao-send-telem \- Re-transmit stored telemetry file +.SH SYNOPSIS +.B "ao-send-telem" +[\-T \fItty-device\fP] +[\--tty \fItty-device\fP] +[\-D \fIaltos-device\fP] +[\--device \fIaltos-device\fP] +[\-F \fIfrequency (kHz)\fP] +[\--frequency \fIfrequency (kHz)\fP] +[\-R] +[\--realtime] + +.SH OPTIONS +.TP +\-T tty-device | --tty tty-device +This selects which tty device ao-dumplog uses to communicate with +the target device. +.TP +\-D AltOS-device | --device AltOS-device +Search for a connected device. This requires an argument of one of the +following forms: +.IP +TeleDongle:2 +.br +TeleDongle +.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. +.TP +\-F kHz | --frequency kHz +This selects which frequency to send the specified packets on. +.TP +\-R | --realtime +This makes the program delay between packets in pad mode. Normally, +pad mode packets are sent as quickly as possible. +.SH DESCRIPTION +.I ao-send-telem +reads the specified flight telemetry log and re-transmits it via the +specified ground station device +.SH AUTHOR +Keith Packard diff --git a/ao-tools/ao-send-telem/ao-send-telem.c b/ao-tools/ao-send-telem/ao-send-telem.c new file mode 100644 index 00000000..c4c354e0 --- /dev/null +++ b/ao-tools/ao-send-telem/ao-send-telem.c @@ -0,0 +1,238 @@ +/* + * Copyright © 2011 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. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include "cc.h" +#include "cc-usb.h" + +static const struct option options[] = { + { .name = "tty", .has_arg = 1, .val = 'T' }, + { .name = "device", .has_arg = 1, .val = 'D' }, + { .name = "frequency", .has_arg = 1, .val = 'F' }, + { .name = "realtime", .has_arg = 0, .val = 'R' }, + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s [--tty ] [--device ] [--frequency ] [--realtime] file.telem ...\n", program); + exit(1); +} + +#define bool(b) ((b) ? "true" : "false") + +struct ao_telem_list { + struct ao_telem_list *next; + union ao_telemetry_all telem; +}; + +static struct ao_telem_list *telem_list, **telem_last; + +static void +trim_telem(uint16_t time) +{ + while (telem_list && (int16_t) (time - telem_list->telem.generic.tick) > 0) { + struct ao_telem_list *next = telem_list->next; + free(telem_list); + telem_list = next; + } + if (!telem_list) + telem_last = &telem_list; +} + +static void +add_telem(union ao_telemetry_all *telem) +{ + struct ao_telem_list *new = malloc (sizeof (struct ao_telem_list)); + trim_telem((uint16_t) (telem->generic.tick - 20 * 100)); + new->telem = *telem; + new->next = 0; + *telem_last = new; + telem_last = &new->next; +} + +static enum ao_flight_state cur_state = ao_flight_invalid; +static enum ao_flight_state last_state = ao_flight_invalid; + +static enum ao_flight_state +packet_state(union ao_telemetry_all *telem) +{ + switch (telem->generic.type) { + case AO_TELEMETRY_SENSOR_TELEMETRUM: + case AO_TELEMETRY_SENSOR_TELEMINI: + case AO_TELEMETRY_SENSOR_TELENANO: + cur_state = telem->sensor.state; + break; + case AO_TELEMETRY_MEGA_DATA: + cur_state = telem->mega_data.state; + break; + } + return cur_state; +} + +static const char *state_names[] = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid" +}; + +static void +send_telem(struct cc_usb *cc, union ao_telemetry_all *telem) +{ + int rssi = (int8_t) telem->generic.rssi / 2 - 74; + int i; + uint8_t *b; + + packet_state(telem); + if (cur_state != last_state) { + if (0 <= cur_state && cur_state < sizeof(state_names) / sizeof (state_names[0])) + printf ("%s\n", state_names[cur_state]); + last_state = cur_state; + } + cc_usb_printf(cc, "S 20\n"); + b = (uint8_t *) telem; + for (i = 0; i < 0x20; i++) + cc_usb_printf(cc, "%02x", b[i]); + cc_usb_sync(cc); +} + +static void +do_delay(uint16_t now, uint16_t then) +{ + int16_t delay = (int16_t) (now - then); + + if (delay > 0 && delay < 1000) + usleep(delay * 10 * 1000); +} + +static uint16_t +send_queued(struct cc_usb *cc, int pause) +{ + struct ao_telem_list *next; + uint16_t tick = 0; + int started = 0; + + while (telem_list) { + if (started && pause) + do_delay(telem_list->telem.generic.tick, tick); + tick = telem_list->telem.generic.tick; + started = 1; + send_telem(cc, &telem_list->telem); + + next = telem_list->next; + free(telem_list); + telem_list = next; + } + return tick; +} + +int +main (int argc, char **argv) +{ + struct cc_usb *cc; + char *tty = NULL; + char *device = NULL; + char line[80]; + int c, i, ret = 0; + int freq = 434550; + char *s; + FILE *file; + int serial; + uint16_t last_tick; + int started; + int realtime = 0; + + + while ((c = getopt_long(argc, argv, "RT:D:F:", options, NULL)) != -1) { + switch (c) { + case 'T': + tty = optarg; + break; + case 'D': + device = optarg; + break; + case 'F': + freq = atoi(optarg); + break; + case 'R': + realtime = 1; + default: + usage(argv[0]); + break; + } + } + if (!tty) + tty = cc_usbdevs_find_by_arg(device, "TeleDongle"); + if (!tty) + tty = getenv("ALTOS_TTY"); + if (!tty) + tty="/dev/ttyACM0"; + cc = cc_usb_open(tty); + if (!cc) + exit (1); + + cc_usb_printf(cc, "m 0\n"); + cc_usb_printf(cc, "F %d\n", freq); + for (i = optind; i < argc; i++) { + file = fopen(argv[i], "r"); + if (!file) { + perror(argv[i]); + ret++; + continue; + } + started = 0; + last_tick = 0; + while (fgets(line, sizeof (line), file)) { + union ao_telemetry_all telem; + + if (cc_telemetry_parse(line, &telem)) { + /* + * Skip packets with CRC errors. + */ + if ((telem.generic.status & (1 << 7)) == 0) + continue; + + if (started) { + do_delay(telem.generic.tick, last_tick); + last_tick = telem.generic.tick; + send_telem(cc, &telem); + } else { + add_telem(&telem); + if (packet_state(&telem) > ao_flight_pad) { + started = 1; + last_tick = send_queued(cc, realtime); + } + } + } + } + fclose (file); + + } + return ret; +} diff --git a/configure.ac b/configure.ac index bcd2dcac..c59261af 100644 --- a/configure.ac +++ b/configure.ac @@ -160,6 +160,7 @@ ao-tools/ao-list/Makefile ao-tools/ao-load/Makefile ao-tools/ao-telem/Makefile ao-tools/ao-stmload/Makefile +ao-tools/ao-send-telem/Makefile ao-utils/Makefile src/Version ]) diff --git a/src/core/ao_send_packet.c b/src/core/ao_send_packet.c new file mode 100644 index 00000000..1a8e74de --- /dev/null +++ b/src/core/ao_send_packet.c @@ -0,0 +1,74 @@ +/* + * Copyright © 2012 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 "ao.h" + +#define AO_MAX_SEND 128 + +static __xdata uint8_t ao_send[AO_MAX_SEND]; + +static uint8_t +getnibble(void) +{ + char c; + + c = getchar(); + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - ('a' - 10); + if ('A' <= c && c <= 'F') + return c - ('A' - 10); + ao_cmd_status = ao_cmd_lex_error; + return 0; +} + +static void +ao_send_packet(void) +{ + __pdata uint16_t count; + uint8_t b; + __pdata uint8_t i; + + ao_cmd_hex(); + count = ao_cmd_lex_i; + if (ao_cmd_status != ao_cmd_success) + return; + if (count > AO_MAX_SEND - 2) { + ao_cmd_status = ao_cmd_syntax_error; + return; + } + for (i = 0; i < count; i++) { + b = getnibble() << 4; + b |= getnibble(); + if (ao_cmd_status != ao_cmd_success) + return; + ao_send[i] = b; + } + ao_radio_send(ao_send, count); +} + +static __code struct ao_cmds ao_send_packet_cmds[] = { + { ao_send_packet, "S \0Send packet. Data on next line" }, + { 0, NULL } +}; + +void +ao_send_packet_init(void) +{ + ao_cmd_register(&ao_send_packet_cmds[0]); +} diff --git a/src/core/ao_send_packet.h b/src/core/ao_send_packet.h new file mode 100644 index 00000000..526f7b55 --- /dev/null +++ b/src/core/ao_send_packet.h @@ -0,0 +1,24 @@ +/* + * Copyright © 2012 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. + */ + +#ifndef _AO_SEND_PACKET_H_ +#define _AO_SEND_PACKET_H_ + +void +ao_send_packet_init(void); + +#endif /* _AO_SEND_PACKET_H_ */ diff --git a/src/product/Makefile.teledongle b/src/product/Makefile.teledongle index 5105b567..3101b777 100644 --- a/src/product/Makefile.teledongle +++ b/src/product/Makefile.teledongle @@ -43,6 +43,7 @@ CC1111_SRC = \ ao_packet.c \ ao_packet_master.c \ ao_radio.c \ + ao_send_packet.c \ ao_romconfig.c \ ao_string.c \ ao_timer.c \ diff --git a/src/product/ao_teledongle.c b/src/product/ao_teledongle.c index 0c829e97..25ebe73e 100644 --- a/src/product/ao_teledongle.c +++ b/src/product/ao_teledongle.c @@ -16,6 +16,7 @@ */ #include "ao.h" +#include void main(void) @@ -32,6 +33,7 @@ main(void) ao_rssi_init(AO_LED_RED); ao_radio_init(); ao_packet_master_init(); + ao_send_packet_init(); #if HAS_DBG ao_dbg_init(); #endif -- cgit v1.2.3 From fb79f8fb358f8df25674336cd558fc3998cb7d9e Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Tue, 31 Jul 2012 20:04:34 +1200 Subject: Don't build ao-stmload if stlink is not available. Signed-off-by: Mike Beattie --- ao-tools/ao-stmload/Makefile.am | 4 ++++ configure.ac | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-stmload/Makefile.am b/ao-tools/ao-stmload/Makefile.am index 375896ea..5aea7db4 100644 --- a/ao-tools/ao-stmload/Makefile.am +++ b/ao-tools/ao-stmload/Makefile.am @@ -1,3 +1,5 @@ +if LIBSTLINK + bin_PROGRAMS=ao-stmload LIBSTLINKDIR=/local/src/stlink @@ -9,3 +11,5 @@ ao_stmload_LDADD=$(LIBSTLINK_LIBS) $(LIBUSB_LIBS) -lelf ao_stmload_SOURCES=ao-stmload.c man_MANS = ao-stmload.1 + +endif diff --git a/configure.ac b/configure.ac index c59261af..a54ef626 100644 --- a/configure.ac +++ b/configure.ac @@ -139,7 +139,9 @@ PKG_CHECK_MODULES([LIBUSB], [libusb-1.0]) AC_CHECK_HEADERS(libelf.h libelf/libelf.h, [break]) AC_CHECK_HEADERS(gelf.h libelf/gelf.h, [break]) -PKG_CHECK_MODULES([LIBSTLINK], [stlink]) +PKG_CHECK_MODULES([LIBSTLINK], [stlink], [HAVE_STLINK=yes], [HAVE_STLINK=no]) + +AM_CONDITIONAL([LIBSTLINK], [test x$HAVE_STLINK != xno]) AC_OUTPUT([ Makefile -- cgit v1.2.3 From 00abbbb79de67dc95176fe48b23ce3e8614e8d3a Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Wed, 8 Aug 2012 07:07:49 +1200 Subject: ao-send-telem: make --realtime work (add "break;" to the case statement for options) Signed-off-by: Mike Beattie --- ao-tools/ao-send-telem/ao-send-telem.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/ao-send-telem/ao-send-telem.c b/ao-tools/ao-send-telem/ao-send-telem.c index c4c354e0..c6cc51a1 100644 --- a/ao-tools/ao-send-telem/ao-send-telem.c +++ b/ao-tools/ao-send-telem/ao-send-telem.c @@ -182,6 +182,7 @@ main (int argc, char **argv) break; case 'R': realtime = 1; + break; default: usage(argv[0]); break; -- cgit v1.2.3 From ac5d053e6d766d243b7a425ae19779810c350125 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 28 Aug 2012 18:02:25 -0700 Subject: ao-stmload: Always round up load amount to 4 byte boundary The flashing code doesn't deal with partial writes. Signed-off-by: Keith Packard --- ao-tools/ao-stmload/ao-stmload.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-stmload/ao-stmload.c b/ao-tools/ao-stmload/ao-stmload.c index e689539b..a471dcc4 100644 --- a/ao-tools/ao-stmload/ao-stmload.c +++ b/ao-tools/ao-stmload/ao-stmload.c @@ -112,10 +112,17 @@ struct load { uint8_t buf[0]; }; +uint32_t round4(uint32_t a) { + return (a + 3) & ~3; +} + struct load * new_load (uint32_t addr, uint32_t len) { - struct load *new = calloc (1, sizeof (struct load) + len); + struct load *new; + + len = round4(len); + new = calloc (1, sizeof (struct load) + len); if (!new) abort(); -- cgit v1.2.3 From 354c1fed7f06c2c45c661e7265c2ac4bc47e2750 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 30 Aug 2012 16:22:51 -0500 Subject: altos: Add a bunch of .gitignore entries Clean up the git status output Signed-off-by: Keith Packard --- ao-tools/ao-stmload/.gitignore | 1 + src/spiradio-v0.1/.gitignore | 2 ++ src/stm-bringup/bringup.ld | 69 ++++++++++++++++++++++++++++++++++++++++++ src/telefire-v0.1/.gitignore | 2 ++ src/test/.gitignore | 3 ++ 5 files changed, 77 insertions(+) create mode 100644 ao-tools/ao-stmload/.gitignore create mode 100644 src/spiradio-v0.1/.gitignore create mode 100644 src/stm-bringup/bringup.ld create mode 100644 src/telefire-v0.1/.gitignore (limited to 'ao-tools') diff --git a/ao-tools/ao-stmload/.gitignore b/ao-tools/ao-stmload/.gitignore new file mode 100644 index 00000000..dedb0094 --- /dev/null +++ b/ao-tools/ao-stmload/.gitignore @@ -0,0 +1 @@ +ao-stmload diff --git a/src/spiradio-v0.1/.gitignore b/src/spiradio-v0.1/.gitignore new file mode 100644 index 00000000..8e39138e --- /dev/null +++ b/src/spiradio-v0.1/.gitignore @@ -0,0 +1,2 @@ +spiradio-* +ao_product.h diff --git a/src/stm-bringup/bringup.ld b/src/stm-bringup/bringup.ld new file mode 100644 index 00000000..10d50cd6 --- /dev/null +++ b/src/stm-bringup/bringup.ld @@ -0,0 +1,69 @@ +/* + * Copyright © 2012 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. + */ + +MEMORY { + rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K + ram (!w) : ORIGIN = 0x20000000, LENGTH = 16K +} + +INCLUDE registers.ld + +EXTERN (stm_interrupt_vector) + +SECTIONS { + /* + * Rom contents + */ + + .text ORIGIN(rom) : { + __text_start__ = .; + *(.interrupt) /* Interrupt vectors */ + + *(.text*) /* Executable code */ + *(.rodata*) /* Constants */ + } > rom + + .ARM.exidx : { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __text_end__ = .; + } > rom + + . = ORIGIN(ram); + __data_start__ = .; + + /* Data -- relocated to RAM, but written to ROM + */ + .data : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) { + *(.data) /* initialized data */ + __data_end__ = .; + __bss_start__ = .; + } >ram + + .bss : { + *(.bss) + *(COMMON) + __bss_end__ = .; + } >ram + + PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram)); + PROVIDE(end = .); + +} + +ENTRY(start); + + diff --git a/src/telefire-v0.1/.gitignore b/src/telefire-v0.1/.gitignore new file mode 100644 index 00000000..4d4f4200 --- /dev/null +++ b/src/telefire-v0.1/.gitignore @@ -0,0 +1,2 @@ +telefire-* +ao_product.h diff --git a/src/test/.gitignore b/src/test/.gitignore index 33c7ef35..5d528ab9 100644 --- a/src/test/.gitignore +++ b/src/test/.gitignore @@ -4,3 +4,6 @@ ao_flight_test_accel ao_gps_test ao_gps_test_skytraq ao_convert_test +ao_convert_pa_test +ao_fec_test +ao_flight_test_noisy_accel -- cgit v1.2.3 From b6a21856c68ca8cca93eb755285be1927acb91e7 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 31 Aug 2012 16:39:10 +1200 Subject: ao-send-telem: fix frequency set command Signed-off-by: Mike Beattie --- ao-tools/ao-send-telem/ao-send-telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-send-telem/ao-send-telem.c b/ao-tools/ao-send-telem/ao-send-telem.c index c6cc51a1..db061377 100644 --- a/ao-tools/ao-send-telem/ao-send-telem.c +++ b/ao-tools/ao-send-telem/ao-send-telem.c @@ -199,7 +199,7 @@ main (int argc, char **argv) exit (1); cc_usb_printf(cc, "m 0\n"); - cc_usb_printf(cc, "F %d\n", freq); + cc_usb_printf(cc, "c F %d\n", freq); for (i = optind; i < argc; i++) { file = fopen(argv[i], "r"); if (!file) { -- cgit v1.2.3 From bb5ab29b6744b382bb2f09486a7a6db7d12a3608 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 9 Sep 2012 13:10:07 -0700 Subject: ao_tools/ao-send-telem: Only start real-time on valid states Check state to make sure it is < ao_flight_landed to keep invalid states from switching to real-time playback mode. Signed-off-by: Keith Packard --- ao-tools/ao-send-telem/ao-send-telem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-send-telem/ao-send-telem.c b/ao-tools/ao-send-telem/ao-send-telem.c index db061377..3db44542 100644 --- a/ao-tools/ao-send-telem/ao-send-telem.c +++ b/ao-tools/ao-send-telem/ao-send-telem.c @@ -224,8 +224,10 @@ main (int argc, char **argv) last_tick = telem.generic.tick; send_telem(cc, &telem); } else { + enum ao_flight_state state = packet_state(&telem); add_telem(&telem); - if (packet_state(&telem) > ao_flight_pad) { + if (ao_flight_pad < state && state < ao_flight_landed) { + printf ("started\n"); started = 1; last_tick = send_queued(cc, realtime); } -- cgit v1.2.3