summaryrefslogtreecommitdiff
path: root/altoslib/AltosSensorMM.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-04-09 00:28:05 -0700
committerKeith Packard <keithp@keithp.com>2013-04-09 00:30:36 -0700
commit398c02b945a58634c8932f07df2c2be8438da7d1 (patch)
tree2741e99555d58e9509271da719d039516e16819f /altoslib/AltosSensorMM.java
parent08eb1e3e1abb1aa4f5ea92b781a2ff8f480006c5 (diff)
altoslib/altosui: Carry receiver status around in AltosListenerState
This moves the crc_errors into the new structure and adds a receiver battery voltage value there as well. Now the receiver status can be monitored separately from the flight status. That also means that code receiving state updates should be prepared to accept missing listener or flight state values. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosSensorMM.java')
-rw-r--r--altoslib/AltosSensorMM.java122
1 files changed, 56 insertions, 66 deletions
diff --git a/altoslib/AltosSensorMM.java b/altoslib/AltosSensorMM.java
index 8372d047..6d1b61c0 100644
--- a/altoslib/AltosSensorMM.java
+++ b/altoslib/AltosSensorMM.java
@@ -28,75 +28,65 @@ class AltosSensorMM {
int accel_ref;
public AltosSensorMM(AltosLink link) throws InterruptedException, TimeoutException {
- link.printf("a\n");
- for (;;) {
- String line = link.get_reply_no_dialog(5000);
- if (line == null) {
- throw new TimeoutException();
+ String[] items = link.adc();
+ sense = new int[6];
+ for (int i = 0; i < items.length;) {
+ if (items[i].equals("tick:")) {
+ tick = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("0:")) {
+ sense[0] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("1:")) {
+ sense[1] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("2:")) {
+ sense[2] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("3:")) {
+ sense[3] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("4:")) {
+ sense[4] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("5:")) {
+ sense[5] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("6:")) {
+ v_batt = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("7:")) {
+ v_pyro = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("8:")) {
+ accel = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
}
- if (!line.startsWith("tick:"))
+ if (items[i].equals("9:")) {
+ accel_ref = Integer.parseInt(items[i+1]);
+ i += 2;
continue;
- String[] items = line.split("\\s+");
- sense = new int[6];
- for (int i = 0; i < items.length;) {
- if (items[i].equals("tick:")) {
- tick = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("0:")) {
- sense[0] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("1:")) {
- sense[1] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("2:")) {
- sense[2] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("3:")) {
- sense[3] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("4:")) {
- sense[4] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("5:")) {
- sense[5] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("6:")) {
- v_batt = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("7:")) {
- v_pyro = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("8:")) {
- accel = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("9:")) {
- accel_ref = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- i++;
}
- break;
+ i++;
}
}
}