X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=micropeak%2FMicroData.java;h=e786ff1ed136de4e6800feb1263094f38af42a30;hp=473af44bc691da619c51deef5988039717d0582f;hb=8d0d59c51138dc1b1bbf6933354fe9faf4d67986;hpb=8d1d8d2a3c129cdbd55427bcda0f26715b02f1ee diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index 473af44b..e786ff1e 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -20,7 +20,8 @@ package org.altusmetrum.micropeak; import java.lang.*; import java.io.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_3.*; +import org.altusmetrum.altosuilib_1.*; class MicroIterator implements Iterator { int i; @@ -56,7 +57,40 @@ class MicroIterable implements Iterable { } } -public class MicroData { +class MicroUIIterator implements Iterator { + int i; + MicroData data; + + public boolean hasNext() { + return i < data.pressures.length; + } + + public AltosUIDataPoint next() { + return new MicroDataPoint(data, i++); + } + + public MicroUIIterator (MicroData data) { + this.data = data; + i = 0; + } + + public void remove() { + } +} + +class MicroUIIterable implements Iterable { + MicroData data; + + public Iterator iterator() { + return new MicroUIIterator(data); + } + + public MicroUIIterable(MicroData data) { + this.data = data; + } +} + +public class MicroData implements AltosUIDataSet { public int ground_pressure; public int min_pressure; public int[] pressures; @@ -64,15 +98,15 @@ public class MicroData { private double ground_altitude; private ArrayList bytes; String name; + MicroStats stats; - - class FileEndedException extends Exception { + public class FileEndedException extends Exception { } - class NonHexcharException extends Exception { + public class NonHexcharException extends Exception { } - class InvalidCrcException extends Exception { + public class InvalidCrcException extends Exception { } private int getc(InputStream f) throws IOException, FileEndedException { @@ -133,14 +167,10 @@ public class MicroData { return h; } - private boolean find_header(InputStream f) throws IOException { - try { - for (;;) { - if (get_nonwhite(f) == 'M' && get_nonwhite(f) == 'P') - return true; - } - } catch (FileEndedException fe) { - return false; + private boolean find_header(InputStream f) throws IOException, FileEndedException { + for (;;) { + if (get_nonwhite(f) == 'M' && get_nonwhite(f) == 'P') + return true; } } @@ -178,6 +208,14 @@ public class MicroData { return AltosConvert.pressure_to_altitude(pressures[i]); } + public String name() { + return name; + } + + public Iterable dataPoints() { + return new MicroUIIterable(this); + } + public Iterable points() { return new MicroIterable(this); } @@ -297,7 +335,7 @@ public class MicroData { this.name = name; } - public MicroData (InputStream f, String name) throws IOException, InterruptedException { + public MicroData (InputStream f, String name) throws IOException, InterruptedException, NonHexcharException, FileEndedException { this.name = name; bytes = new ArrayList(); if (!find_header(f)) @@ -339,10 +377,9 @@ public class MicroData { crc_valid = crc == current_crc; time_step = 0.192; + stats = new MicroStats(this); } catch (FileEndedException fe) { throw new IOException("File Ended Unexpectedly"); - } catch (NonHexcharException ne) { - throw new IOException("Non hexadecimal character found"); } }