X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao-tools%2Faltosui%2FAltosTelemetry.java;h=af29b8c04ef5e940e25dd1ca3e796e9dc895fbeb;hp=e072bb347394186491bcd93d3b3e3136f7f88d62;hb=a55b132668a819cc26478a609cb79bd9190deb9d;hpb=a06bee96e648d9ded8776f3d6cba9505e7be1a60 diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index e072bb34..af29b8c0 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -19,269 +19,106 @@ package altosui; import java.lang.*; import java.text.*; +import java.util.HashMap; +import altosui.AltosConvert; +import altosui.AltosRecord; +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(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); - } - } +/* + * 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 { String[] words = line.split("\\s+"); - 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++]); - - word (words[i++], "FLIGHT"); - flight = parse_int(words[i++]); - - word(words[i++], "RSSI"); - rssi = parse_int(words[i++]); + AltosParse.word (words[i++], "SERIAL"); + serial = AltosParse.parse_int(words[i++]); - word(words[i++], "STATUS"); - status = parse_hex(words[i++]); + AltosParse.word (words[i++], "FLIGHT"); + flight = AltosParse.parse_int(words[i++]); - word(words[i++], "STATE"); - state = words[i++]; + AltosParse.word(words[i++], "RSSI"); + rssi = AltosParse.parse_int(words[i++]); - tick = parse_int(words[i++]); + AltosParse.word(words[i++], "STATUS"); + status = AltosParse.parse_hex(words[i++]); - word(words[i++], "a:"); - accel = parse_int(words[i++]); + AltosParse.word(words[i++], "STATE"); + state = Altos.state(words[i++]); - word(words[i++], "p:"); - pres = parse_int(words[i++]); + tick = AltosParse.parse_int(words[i++]); - word(words[i++], "t:"); - temp = parse_int(words[i++]); + AltosParse.word(words[i++], "a:"); + accel = AltosParse.parse_int(words[i++]); - word(words[i++], "v:"); - batt = parse_int(words[i++]); + AltosParse.word(words[i++], "p:"); + pres = AltosParse.parse_int(words[i++]); - word(words[i++], "d:"); - drogue = parse_int(words[i++]); + AltosParse.word(words[i++], "t:"); + temp = AltosParse.parse_int(words[i++]); - word(words[i++], "m:"); - main = parse_int(words[i++]); + AltosParse.word(words[i++], "v:"); + batt = AltosParse.parse_int(words[i++]); - word(words[i++], "fa:"); - flight_accel = parse_int(words[i++]); + AltosParse.word(words[i++], "d:"); + drogue = AltosParse.parse_int(words[i++]); - word(words[i++], "ga:"); - ground_accel = parse_int(words[i++]); + AltosParse.word(words[i++], "m:"); + main = AltosParse.parse_int(words[i++]); - word(words[i++], "fv:"); - flight_vel = parse_int(words[i++]); + AltosParse.word(words[i++], "fa:"); + flight_accel = AltosParse.parse_int(words[i++]); - word(words[i++], "fp:"); - flight_pres = parse_int(words[i++]); + AltosParse.word(words[i++], "ga:"); + ground_accel = AltosParse.parse_int(words[i++]); - word(words[i++], "gp:"); - ground_pres = parse_int(words[i++]); + AltosParse.word(words[i++], "fv:"); + flight_vel = AltosParse.parse_int(words[i++]); - word(words[i++], "a+:"); - accel_plus_g = parse_int(words[i++]); + AltosParse.word(words[i++], "fp:"); + flight_pres = AltosParse.parse_int(words[i++]); - word(words[i++], "a-:"); - accel_minus_g = parse_int(words[i++]); + AltosParse.word(words[i++], "gp:"); + ground_pres = AltosParse.parse_int(words[i++]); - word(words[i++], "GPS"); - gps = new AltosGPS(); - gps.nsat = parse_int(words[i++]); - word(words[i++], "sat"); + AltosParse.word(words[i++], "a+:"); + accel_plus_g = AltosParse.parse_int(words[i++]); - 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; + AltosParse.word(words[i++], "a-:"); + accel_minus_g = AltosParse.parse_int(words[i++]); - 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++]); - } + gps = new AltosGPS(words, i); } }