From: Keith Packard Date: Wed, 6 Jul 2011 04:41:44 +0000 (-0700) Subject: altosui: Parse remaining standard telemetry packets X-Git-Tag: 0.9.4.3~35 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=4132ac5896114e5f3d8fb3f219422e8933078cf4 altosui: Parse remaining standard telemetry packets Signed-off-by: Keith Packard --- diff --git a/altosui/Altos.java b/altosui/Altos.java index 25d97bcf..37a4f67b 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -231,10 +231,21 @@ public class Altos { static final Charset unicode_set = Charset.forName("UTF-8"); static String string(int[] bytes, int s, int l) { - byte[] b = new byte[bytes.length]; + if (s + l > bytes.length) { + if (s > bytes.length) { + s = bytes.length; + l = 0; + } else { + l = bytes.length - s; + } + } + + byte[] b = new byte[l]; + for (int i = 0; i < l; i++) b[i] = (byte) bytes[s+i]; - return new String(b, unicode_set); + String n = new String(b, unicode_set); + return n; } static int hexbyte(String s, int i) { diff --git a/altosui/AltosLog.java b/altosui/AltosLog.java index 64275f32..855ee2b4 100644 --- a/altosui/AltosLog.java +++ b/altosui/AltosLog.java @@ -82,7 +82,9 @@ class AltosLog implements Runnable { continue; try { AltosRecord telem = AltosTelemetry.parse(line.line, previous); - if (telem.serial != serial || telem.flight != flight || log_file == null) { + if (telem.serial != 0 && telem.flight != 0 && + (telem.serial != serial || telem.flight != flight || log_file == null)) + { close_log_file(); serial = telem.serial; flight = telem.flight; diff --git a/altosui/AltosRecord.java b/altosui/AltosRecord.java index 8976edf0..144b1c3c 100644 --- a/altosui/AltosRecord.java +++ b/altosui/AltosRecord.java @@ -67,6 +67,13 @@ public class AltosRecord { double time; /* seconds since boost */ + int device_type; + int config_major; + int config_minor; + int apogee_delay; + int main_deploy; + int flight_log_max; + String firmware_version; /* * Values for our MP3H6115A pressure sensor * diff --git a/altosui/AltosTelemetryRecordConfiguration.java b/altosui/AltosTelemetryRecordConfiguration.java new file mode 100644 index 00000000..98dc6ab9 --- /dev/null +++ b/altosui/AltosTelemetryRecordConfiguration.java @@ -0,0 +1,64 @@ +/* + * 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. + */ + +package altosui; + + +public class AltosTelemetryRecordConfiguration extends AltosTelemetryRecordRaw { + int device_type; + int flight; + int config_major; + int config_minor; + int apogee_delay; + int main_deploy; + int flight_log_max; + String callsign; + String version; + + public AltosTelemetryRecordConfiguration(int[] in_bytes) { + super(in_bytes); + + device_type = uint8(5); + flight = uint16(6); + config_major = uint8(8); + config_minor = uint8(9); + apogee_delay = uint16(10); + main_deploy = uint16(12); + flight_log_max = uint16(14); + callsign = string(16, 8); + version = string(24, 8); + } + + public AltosRecord update_state(AltosRecord previous) { + AltosRecord next = super.update_state(previous); + + next.device_type = device_type; + next.flight = flight; + next.config_major = config_major; + next.config_minor = config_minor; + next.apogee_delay = apogee_delay; + next.main_deploy = main_deploy; + next.flight_log_max = flight_log_max; + + next.callsign = callsign; + next.firmware_version = version; + + next.seen |= AltosRecord.seen_deploy; + + return next; + } +} diff --git a/altosui/AltosTelemetryRecordGeneral.java b/altosui/AltosTelemetryRecordGeneral.java index 55f6c495..722baba3 100644 --- a/altosui/AltosTelemetryRecordGeneral.java +++ b/altosui/AltosTelemetryRecordGeneral.java @@ -34,7 +34,6 @@ public class AltosTelemetryRecordGeneral { throw new AltosCRCException(AltosParse.parse_int(word[i++])); } - System.out.printf("First word \"%s\"\n", word[i]); if (word[i].equals("TELEM")) r = AltosTelemetryRecordRaw.parse(word[i+1]); else diff --git a/altosui/AltosTelemetryRecordLocation.java b/altosui/AltosTelemetryRecordLocation.java new file mode 100644 index 00000000..76bd106e --- /dev/null +++ b/altosui/AltosTelemetryRecordLocation.java @@ -0,0 +1,92 @@ +/* + * 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. + */ + +package altosui; + + +public class AltosTelemetryRecordLocation extends AltosTelemetryRecordRaw { + int flags; + int altitude; + int latitude; + int longitude; + int year; + int month; + int day; + int hour; + int minute; + int second; + int pdop; + int hdop; + int vdop; + int mode; + int ground_speed; + int climb_rate; + int course; + + public AltosTelemetryRecordLocation(int[] in_bytes) { + super(in_bytes); + + flags = uint8(5); + altitude = int16(6); + latitude = uint32(8); + longitude = uint32(12); + year = uint8(16); + month = uint8(17); + day = uint8(18); + hour = uint8(19); + minute = uint8(20); + second = uint8(21); + pdop = uint8(22); + hdop = uint8(23); + vdop = uint8(24); + mode = uint8(25); + ground_speed = uint16(26); + climb_rate = int16(28); + course = uint8(30); + } + + public AltosRecord update_state(AltosRecord previous) { + AltosRecord next = super.update_state(previous); + + if (next.gps == null) + next.gps = new AltosGPS(); + + next.gps.nsat = flags & 0xf; + next.gps.locked = (flags & (1 << 4)) != 0; + next.gps.connected = (flags & (1 << 5)) != 0; + + if (next.gps.locked) { + next.gps.lat = latitude * 1.0e-7; + next.gps.lon = longitude * 1.0e-7; + next.gps.alt = altitude; + next.gps.year = 2000 + year; + next.gps.month = month; + next.gps.day = day; + next.gps.hour = hour; + next.gps.minute = minute; + next.gps.second = second; + next.gps.ground_speed = ground_speed * 1.0e-2; + next.gps.course = course * 2; + next.gps.climb_rate = climb_rate * 1.0e-2; + next.gps.hdop = hdop; + next.gps.vdop = vdop; + next.seen |= AltosRecord.seen_gps_time | AltosRecord.seen_gps_lat | AltosRecord.seen_gps_lon; + } + + return next; + } +} diff --git a/altosui/AltosTelemetryRecordRaw.java b/altosui/AltosTelemetryRecordRaw.java index 35796a22..e6c4cfc8 100644 --- a/altosui/AltosTelemetryRecordRaw.java +++ b/altosui/AltosTelemetryRecordRaw.java @@ -30,9 +30,9 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord { final static int packet_type_TM_sensor = 0x01; final static int packet_type_Tm_sensor = 0x02; final static int packet_type_Tn_sensor = 0x03; - final static int packet_type_config = 0x04; - final static int packet_type_GPS_location = 0x05; - final static int packet_type_GPS_satellites = 0x06; + final static int packet_type_configuration = 0x04; + final static int packet_type_location = 0x05; + final static int packet_type_satellite = 0x06; final static int PKT_APPEND_STATUS_1_CRC_OK = (1 << 7); final static int PKT_APPEND_STATUS_1_LQI_MASK = (0x7f); @@ -43,8 +43,6 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord { for (int i = 1; i < bytes.length - 1; i++) sum += bytes[i]; sum &= 0xff; - System.out.printf("%d bytes sum 0x%x last byte 0x%x\n", - bytes.length, sum, bytes[bytes.length - 1]); return sum == bytes[bytes.length - 1]; } @@ -69,10 +67,6 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord { int rssi = Altos.int8(bytes, bytes.length - 3) / 2 - 74; int status = Altos.uint8(bytes, bytes.length - 2); - System.out.printf ("rssi 0x%x = %d status 0x%x\n", - Altos.uint8(bytes, bytes.length - 3), - rssi, status); - if ((status & PKT_APPEND_STATUS_1_CRC_OK) == 0) throw new AltosCRCException(rssi); @@ -84,12 +78,22 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord { case packet_type_TM_sensor: case packet_type_Tm_sensor: case packet_type_Tn_sensor: - r = new AltosTelemetryRecordSensor(bytes); + r = new AltosTelemetryRecordSensor(bytes, rssi); + break; + case packet_type_configuration: + r = new AltosTelemetryRecordConfiguration(bytes); + break; + case packet_type_location: + r = new AltosTelemetryRecordLocation(bytes); + break; + case packet_type_satellite: + r = new AltosTelemetryRecordSatellite(bytes); break; default: r = new AltosTelemetryRecordRaw(bytes); break; } + break; case Altos.ao_telemetry_legacy_len + 4: r = new AltosTelemetryRecordLegacy(bytes, rssi, status); break; @@ -119,6 +123,10 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord { return Altos.uint32(bytes, off + 1); } + public String string(int off, int l) { + return Altos.string(bytes, off + 1, l); + } + public AltosTelemetryRecordRaw(int[] in_bytes) { bytes = in_bytes; serial = uint16(0); @@ -127,9 +135,13 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord { } public AltosRecord update_state(AltosRecord previous) { + AltosRecord next; if (previous != null) - return new AltosRecord(previous); + next = new AltosRecord(previous); else - return new AltosRecord(); + next = new AltosRecord(); + next.serial = serial; + next.tick = tick; + return next; } } diff --git a/altosui/AltosTelemetryRecordSatellite.java b/altosui/AltosTelemetryRecordSatellite.java new file mode 100644 index 00000000..2dd782ad --- /dev/null +++ b/altosui/AltosTelemetryRecordSatellite.java @@ -0,0 +1,52 @@ +/* + * 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. + */ + +package altosui; + +public class AltosTelemetryRecordSatellite extends AltosTelemetryRecordRaw { + int channels; + AltosGPSSat[] sats; + + public AltosTelemetryRecordSatellite(int[] in_bytes) { + super(in_bytes); + + channels = uint8(5); + if (channels > 12) + channels = 12; + if (channels == 0) + sats = null; + else { + sats = new AltosGPSSat[channels]; + for (int i = 0; i < channels; i++) { + int svid = uint8(6 + i * 2 + 0); + int c_n_1 = uint8(6 + i * 2 + 1); + sats[i] = new AltosGPSSat(svid, c_n_1); + } + } + } + + public AltosRecord update_state(AltosRecord previous) { + AltosRecord next = super.update_state(previous); + + if (next.gps == null) + next.gps = new AltosGPS(); + + next.gps.cc_gps_sat = sats; + + return next; + } +} diff --git a/altosui/AltosTelemetryRecordSensor.java b/altosui/AltosTelemetryRecordSensor.java index 5ae9f891..3998437b 100644 --- a/altosui/AltosTelemetryRecordSensor.java +++ b/altosui/AltosTelemetryRecordSensor.java @@ -36,7 +36,9 @@ public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw { int accel_plus_g; int accel_minus_g; - public AltosTelemetryRecordSensor(int[] in_bytes) { + int rssi; + + public AltosTelemetryRecordSensor(int[] in_bytes, int in_rssi) { super(in_bytes); state = uint8(5); @@ -51,14 +53,53 @@ public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw { speed = int16(20); height = int16(22); - ground_accel = int16(24); - ground_pres = int16(26); + ground_pres = int16(24); + ground_accel = int16(26); accel_plus_g = int16(28); accel_minus_g = int16(30); + + rssi = in_rssi; } public AltosRecord update_state(AltosRecord previous) { AltosRecord next = super.update_state(previous); + + next.state = state; + if (type == packet_type_TM_sensor) + next.accel = accel; + else + next.accel = AltosRecord.MISSING; + next.pres = pres; + next.temp = temp; + next.batt = v_batt; + if (type == packet_type_TM_sensor || type == packet_type_Tm_sensor) { + next.drogue = sense_d; + next.main = sense_m; + } else { + next.drogue = AltosRecord.MISSING; + next.main = AltosRecord.MISSING; + } + + next.acceleration = acceleration / 16.0; + next.speed = speed / 16.0; + next.height = height; + + next.ground_pres = ground_pres; + if (type == packet_type_TM_sensor) { + next.ground_accel = ground_accel; + next.accel_plus_g = accel_plus_g; + next.accel_minus_g = accel_minus_g; + } else { + next.ground_accel = AltosRecord.MISSING; + next.accel_plus_g = AltosRecord.MISSING; + next.accel_minus_g = AltosRecord.MISSING; + } + + next.rssi = rssi; + + next.seen |= AltosRecord.seen_sensor | AltosRecord.seen_temp_volt; + + System.out.printf("Sensor record update - rssi %d\n", rssi); return next; } } diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 6a4d9d17..6e64acab 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -75,6 +75,9 @@ altosui_JAVA = \ AltosTelemetryRecordGeneral.java \ AltosTelemetryRecordRaw.java \ AltosTelemetryRecordSensor.java \ + AltosTelemetryRecordConfiguration.java \ + AltosTelemetryRecordLocation.java \ + AltosTelemetryRecordSatellite.java \ AltosTelemetryRecordLegacy.java \ AltosTelemetryMap.java \ AltosReplayReader.java \