2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 import altosui.AltosRecord;
26 import altosui.AltosReader;
28 public class AltosCSV {
31 boolean header_written;
34 LinkedList<AltosRecord> pad_records;
37 static final int ALTOS_CSV_VERSION = 1;
46 * time (seconds since boost)
58 * accelerometer speed (m/s)
59 * barometer speed (m/s)
68 * nsat (used for solution)
79 * from_pad_azimuth (deg true)
81 * from_pad_elevation (deg from horizon)
85 * C/N0 data for all 32 valid SDIDs
88 void write_general_header() {
89 out.printf("version serial flight call time rssi");
92 void write_general(AltosRecord record) {
93 out.printf("%s,%d,%d,%s,%8.2f,%4d",
94 record.version, record.serial, record.flight, record.callsign,
99 void write_flight_header() {
100 out.printf("state state_name");
103 void write_flight(AltosRecord record) {
104 out.printf("%d,%8s", record.state, record.state());
107 void write_basic_header() {
108 out.printf("acceleration pressure altitude height accel_speed baro_speed temperature battery_voltage drogue_voltage main_voltage");
111 void write_basic(AltosRecord record) {
112 out.printf("%8.2f,%10.2f,%8.2f,%8.2f,%8.2f,%8.2f,%5.1f,%5.2f,%5.2f,%5.2f",
113 record.acceleration(),
117 record.accel_speed(),
119 record.temperature(),
120 record.battery_voltage(),
121 record.drogue_voltage(),
122 record.main_voltage());
125 void write_gps_header() {
126 out.printf("connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_range pad_az pad_el");
129 void write_gps(AltosRecord record) {
130 AltosGPS gps = record.gps;
132 gps = new AltosGPS();
134 AltosGreatCircle from_pad = state.from_pad;
135 if (from_pad == null)
136 from_pad = new AltosGreatCircle();
138 out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d,%9.0f,%9.0f,%4.0f,%4.0f",
157 void write_header() {
158 out.printf("# "); write_general_header();
159 out.printf(" "); write_flight_header();
160 out.printf(" "); write_basic_header();
161 out.printf(" "); write_gps_header();
165 void write_one(AltosRecord record) {
166 state = new AltosState(record, state);
167 write_general(record); out.printf(",");
168 write_flight(record); out.printf(",");
169 write_basic(record); out.printf(",");
175 while (!pad_records.isEmpty()) {
176 write_one (pad_records.remove());
180 public void write(AltosRecord record) {
181 if (!header_written) {
183 header_written = true;
186 if (record.state >= Altos.ao_flight_boost) {
188 boost_tick = record.tick;
195 pad_records.add(record);
198 public PrintStream out() {
202 public void close() {
203 if (!pad_records.isEmpty()) {
204 boost_tick = pad_records.element().tick;
210 public void write(AltosReader reader) {
213 reader.write_comments(out());
216 record = reader.read();
221 } catch (IOException ie) {
222 System.out.printf("IOException\n");
223 } catch (ParseException pe) {
224 System.out.printf("ParseException %s\n", pe.getMessage());
228 public AltosCSV(File in_name) throws FileNotFoundException {
230 out = new PrintStream(name);
231 pad_records = new LinkedList<AltosRecord>();
234 public AltosCSV(String in_string) throws FileNotFoundException {
235 this(new File(in_string));