import android.widget.TextView;
import android.widget.Toast;
import android.app.AlertDialog;
+import android.location.Location;
import org.altusmetrum.altoslib_1.*;
public static final int MSG_STATE_CHANGE = 1;
public static final int MSG_TELEMETRY = 2;
public static final int MSG_UPDATE_AGE = 3;
+ public static final int MSG_LOCATION = 4;
+ public static final int MSG_CRC_ERROR = 5;
// Intent request codes
private static final int REQUEST_CONNECT_DEVICE = 1;
// Timer and Saved flight state for Age calculation
private Timer timer = new Timer();
AltosState saved_state;
+ Location saved_location;
// Service
private boolean mIsBound = false;
case MSG_TELEMETRY:
ad.update_ui((AltosState) msg.obj);
break;
+ case MSG_LOCATION:
+ ad.set_location((Location) msg.obj);
+ break;
+ case MSG_CRC_ERROR:
case MSG_UPDATE_AGE:
if (ad.saved_state != null) {
ad.mAgeView.setText(String.format("%d", (System.currentTimeMillis() - ad.saved_state.report_time + 500) / 1000));
mTabs.remove(mTab);
}
+ void set_location(Location location) {
+ saved_location = location;
+ if (saved_state != null) {
+ update_ui(saved_state);
+ }
+ }
+
void update_ui(AltosState state) {
if (saved_state != null) {
if (saved_state.state != state.state) {
}
saved_state = state;
+ AltosGreatCircle from_receiver = null;
+
+ if (saved_location != null && state.gps != null && state.gps.locked) {
+ from_receiver = new AltosGreatCircle(saved_location.getLatitude(),
+ saved_location.getLongitude(),
+ saved_location.getAltitude(),
+ state.gps.lat,
+ state.gps.lon,
+ state.gps.alt);
+ }
+
mCallsignView.setText(state.data.callsign);
mSerialView.setText(String.format("%d", state.data.serial));
mFlightView.setText(String.format("%d", state.data.flight));
mRSSIView.setText(String.format("%d", state.data.rssi));
for (AltosDroidTab mTab : mTabs)
- mTab.update_ui(state);
+ mTab.update_ui(state, from_receiver);
mAltosVoice.tell(state);
}
package org.altusmetrum.AltosDroid;
-import org.altusmetrum.altoslib_1.AltosState;
+import org.altusmetrum.altoslib_1.*;
public interface AltosDroidTab {
- public void update_ui(AltosState state);
+ public void update_ui(AltosState state, AltosGreatCircle from_receiver);
}
package org.altusmetrum.AltosDroid;
-import org.altusmetrum.altoslib_1.AltosState;
+import org.altusmetrum.altoslib_1.*;
import android.app.Activity;
import android.os.Bundle;
mAltosDroid = null;
}
- public void update_ui(AltosState state) {
+ public void update_ui(AltosState state, AltosGreatCircle from_receiver) {
mHeightView.setText(String.format("%6.0f m", state.height));
mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
package org.altusmetrum.AltosDroid;
-import org.altusmetrum.altoslib_1.AltosGreatCircle;
-import org.altusmetrum.altoslib_1.AltosState;
+import org.altusmetrum.altoslib_1.*;
import android.app.Activity;
import android.os.Bundle;
mAltosDroid = null;
}
- public void update_ui(AltosState state) {
+ public void update_ui(AltosState state, AltosGreatCircle from_receiver) {
mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
mHeightView.setText(String.format("%6.0f m", state.height));
- mElevationView.setText(String.format("%3.0f°", state.elevation));
- mRangeView.setText(String.format("%6.0f m", state.range));
- if (state.from_pad != null) {
- mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
- mCompassView.setText(state.from_pad.bearing_words(AltosGreatCircle.BEARING_LONG));
+ if (from_receiver != null) {
+ mElevationView.setText(String.format("%3.0f°", from_receiver.elevation));
+ mRangeView.setText(String.format("%6.0f m", from_receiver.range));
+ mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
+ mCompassView.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
+ mDistanceView.setText(String.format("%6.0f m", from_receiver.distance));
+ } else {
+ mElevationView.setText("<unknown>");
+ mRangeView.setText("<unknown>");
+ mBearingView.setText("<unknown>");
+ mCompassView.setText("<unknown>");
+ mDistanceView.setText("<unknown>");
}
- mDistanceView.setText(String.format("%6.0f m", state.range));
mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
package org.altusmetrum.AltosDroid;
-import org.altusmetrum.altoslib_1.AltosState;
+import org.altusmetrum.altoslib_1.*;
import android.app.Activity;
import android.os.Bundle;
mAltosDroid = null;
}
- public void update_ui(AltosState state) {
- if (state.from_pad != null) {
- mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
- mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance));
+ public void update_ui(AltosState state, AltosGreatCircle from_receiver) {
+ if (from_receiver != null) {
+ mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
+ mDistanceView.setText(String.format("%6.0f m", from_receiver.distance));
}
mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
}
}
- public void update_ui(AltosState state) {
+ public void update_ui(AltosState state, AltosGreatCircle from_receiver) {
if (state.from_pad != null) {
mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance));
mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
mAltosDroid = null;
}
- public void update_ui(AltosState state) {
+ public void update_ui(AltosState state, AltosGreatCircle from_receiver) {
mBatteryVoltageView.setText(String.format("%4.2f V", state.battery));
mBatteryLights.set(state.battery > 3.7);
\r
Handler handler;\r
\r
- TelemetryService service;\r
AltosLink link;\r
AltosRecord previous;\r
\r
if (record == null)\r
break;\r
state = new AltosState(record, state);\r
- service.sendTelemetry(state);\r
+ handler.obtainMessage(TelemetryService.MSG_TELEMETRY, state).sendToTarget();\r
} catch (ParseException pp) {\r
Log.e(TAG, String.format("Parse error: %d \"%s\"", pp.getErrorOffset(), pp.getMessage()));\r
} catch (AltosCRCException ce) {\r
++crc_errors;\r
- service.sendCrcErrors(crc_errors);\r
+ handler.obtainMessage(TelemetryService.MSG_CRC_ERROR, new Integer(crc_errors)).sendToTarget();\r
}\r
}\r
} catch (InterruptedException ee) {\r
}\r
}\r
\r
- public TelemetryReader (TelemetryService in_service, AltosLink in_link, Handler in_handler) {\r
- service = in_service;\r
+ public TelemetryReader (AltosLink in_link, Handler in_handler) {\r
link = in_link;\r
handler = in_handler;\r
\r
import org.altusmetrum.altoslib_1.*;
class AltosLocationListener implements LocationListener {
- TelemetryService service;
+ Handler handler;
public void onLocationChanged(Location location) {
- service.sendLocation(location);
+ handler.obtainMessage(TelemetryService.MSG_LOCATION, location).sendToTarget();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
public void onProviderDisabled(String provider) {
}
- public AltosLocationListener(TelemetryService service) {
- this.service = service;
+ public AltosLocationListener(Handler handler) {
+ this.handler = handler;
}
}
}
break;
case MSG_TELEMETRY:
+ // forward telemetry messages
+ s.last_state = (AltosState) msg.obj;
s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_TELEMETRY, msg.obj));
break;
+ case MSG_LOCATION:
+ // forward location messages
+ s.last_location = (Location) msg.obj;
+ s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_LOCATION, msg.obj));
+ break;
+ case MSG_CRC_ERROR:
+ // forward crc error messages
+ s.last_crc_errors = (Integer) msg.obj;
+ s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_CRC_ERROR, msg.obj));
+ break;
case MSG_SETFREQUENCY:
if (s.state == STATE_CONNECTED) {
try {
}
public void sendTelemetry(AltosState state) {
- last_state = state;
- mHandler.obtainMessage(MSG_TELEMETRY, state).sendToTarget();
}
public void sendLocation(Location location) {
- last_location = location;
mHandler.obtainMessage(MSG_LOCATION, location).sendToTarget();
}
public void sendCrcErrors(int crc_errors) {
- last_crc_errors = crc_errors;
- mHandler.obtainMessage(MSG_CRC_ERROR, new Integer(crc_errors)).sendToTarget();
}
private void sendMessageToClients(Message m) {
setState(STATE_CONNECTED);
- mTelemetryReader = new TelemetryReader(this, mAltosBluetooth, mHandler);
+ mTelemetryReader = new TelemetryReader(mAltosBluetooth, mHandler);
mTelemetryReader.start();
mTelemetryLogger = new TelemetryLogger(this, mAltosBluetooth);
timer.scheduleAtFixedRate(new TimerTask(){ public void run() {onTimerTick();}}, 10000L, 10000L);
// Listen for GPS and Network position updates
- locationListener = new AltosLocationListener(this);
+ locationListener = new AltosLocationListener(mHandler);
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);