- 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();
- }
+ File 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);
+ return false;
+ } else {
+ AltosWriter writer = open_csv(output);
+ if (writer == null)
+ return false;
+ writer.write(states);
+ writer.close();
+ }
+ return true;
+ }
+
+ static boolean process_kml(File input) {
+ AltosStateIterable states = open_logfile(input);
+ if (states == null)
+ return false;
+
+ File 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);
+ return false;
+ } else {
+ AltosWriter writer = open_kml(output);
+ if (writer == null)
+ return false;
+ writer.write(states);
+ writer.close();
+ return true;
+ }
+ }
+
+ static AltosStateIterable record_iterable(File file) {
+ FileInputStream in;
+ try {
+ in = new FileInputStream(file);
+ } catch (Exception e) {
+ System.out.printf("Failed to open file '%s'\n", file);
+ return null;
+ }
+ if (file.getName().endsWith("telem"))
+ return new AltosTelemetryFile(in);
+ else
+ return new AltosEepromFile(in);
+ }
+
+ static AltosReplayReader replay_file(File file) {
+ AltosStateIterable states = record_iterable(file);
+ if (states == null)
+ return null;
+ return new AltosReplayReader(states.iterator(), file, true);
+ }
+
+ static boolean process_replay(File file) {
+ AltosReplayReader reader = replay_file(file);
+ if (reader == null)
+ return false;
+ AltosFlightUI flight_ui = new AltosFlightUI(new AltosVoice(), reader);
+ return true;
+ }
+
+ static boolean process_graph(File file) {
+ AltosStateIterable states = record_iterable(file);
+ if (states == null)
+ return false;
+ try {
+ new AltosGraphUI(states, file);
+ return true;
+ } catch (InterruptedException ie) {
+ } catch (IOException ie) {
+ }
+ return false;
+ }
+
+ static boolean process_summary(File file) {
+ AltosStateIterable states = record_iterable(file);
+ if (states == null)
+ return false;
+ try {
+ AltosFlightStats stats = new AltosFlightStats(states);
+ if (stats.serial > 0)
+ System.out.printf("Serial: %5d\n", stats.serial);
+ if (stats.flight > 0)
+ System.out.printf("Flight: %5d\n", stats.flight);
+ if (stats.year > 0)
+ System.out.printf("Date: %04d-%02d-%02d\n",
+ stats.year, stats.month, stats.day);
+ if (stats.hour > 0)
+ System.out.printf("Time: %02d:%02d:%02d UTC\n",
+ stats.hour, stats.minute, stats.second);
+ System.out.printf("Max height: %6.0f m %6.0f ft\n",
+ stats.max_height,
+ AltosConvert.meters_to_feet(stats.max_height));
+ System.out.printf("Max speed: %6.0f m/s %6.0f ft/s %6.4f Mach\n",
+ stats.max_speed,
+ AltosConvert.meters_to_feet(stats.max_speed),
+ AltosConvert.meters_to_mach(stats.max_speed));
+ if (stats.max_acceleration != AltosLib.MISSING) {
+ System.out.printf("Max accel: %6.0f m/s² %6.0f ft/s² %6.2f g\n",
+ stats.max_acceleration,
+ AltosConvert.meters_to_feet(stats.max_acceleration),
+ AltosConvert.meters_to_g(stats.max_acceleration));