1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

AndroidGCS: Add copyright header of the other files

This commit is contained in:
James Cotton 2012-08-08 09:22:09 -05:00
parent dc6b3af707
commit 07074ef41e
19 changed files with 832 additions and 335 deletions

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file AttitudeView.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A view for UAV attitude.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import android.content.Context; import android.content.Context;
@ -14,75 +37,75 @@ public class AttitudeView extends View {
initAttitudeView(); initAttitudeView();
} }
public AttitudeView(Context context, AttributeSet ats, int defaultStyle) { public AttitudeView(Context context, AttributeSet ats, int defaultStyle) {
super(context, ats, defaultStyle); super(context, ats, defaultStyle);
initAttitudeView(); initAttitudeView();
} }
public AttitudeView(Context context, AttributeSet ats) { public AttitudeView(Context context, AttributeSet ats) {
super(context, ats); super(context, ats);
initAttitudeView(); initAttitudeView();
} }
protected void initAttitudeView() { protected void initAttitudeView() {
setFocusable(true); setFocusable(true);
circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(R.color.background_color); circlePaint.setColor(getResources().getColor(R.color.background_color));
circlePaint.setStrokeWidth(1); circlePaint.setStrokeWidth(1);
circlePaint.setStyle(Paint.Style.FILL_AND_STROKE); circlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
Resources r = this.getResources(); Resources r = this.getResources();
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(r.getColor(R.color.text_color)); textPaint.setColor(r.getColor(R.color.text_color));
markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
markerPaint.setColor(r.getColor(R.color.marker_color)); markerPaint.setColor(r.getColor(R.color.marker_color));
} }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredWidth = measure(widthMeasureSpec); int measuredWidth = measure(widthMeasureSpec);
int measuredHeight = measure(heightMeasureSpec); int measuredHeight = measure(heightMeasureSpec);
int d = Math.min(measuredWidth, measuredHeight); int d = Math.min(measuredWidth, measuredHeight);
setMeasuredDimension(d/2, d/2); setMeasuredDimension(d/2, d/2);
} }
private int measure(int measureSpec) { private int measure(int measureSpec) {
int result = 0; int result = 0;
// Decode the measurement specifications. // Decode the measurement specifications.
int specMode = MeasureSpec.getMode(measureSpec); int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec); int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.UNSPECIFIED) { // Return a default size of 200 if no bounds are specified. if (specMode == MeasureSpec.UNSPECIFIED) { // Return a default size of 200 if no bounds are specified.
result = 200; result = 200;
} else { } else {
// As you want to fill the available space // As you want to fill the available space
// always return the full available bounds. // always return the full available bounds.
result = specSize; result = specSize;
} }
return result; return result;
} }
private double roll; private double roll;
public void setRoll(double roll) { public void setRoll(double roll) {
this.roll = roll; this.roll = roll;
} }
private double pitch; private double pitch;
public void setPitch(double d) { public void setPitch(double d) {
this.pitch = d; this.pitch = d;
} }
// Drawing related code // Drawing related code
private Paint markerPaint; private Paint markerPaint;
private Paint textPaint; private Paint textPaint;
private Paint circlePaint; private Paint circlePaint;
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
int px = getMeasuredWidth() / 2; int px = getMeasuredWidth() / 2;
int py = getMeasuredHeight() /2 ; int py = getMeasuredHeight() /2 ;
int radius = Math.min(px, py); int radius = Math.min(px, py);
canvas.drawLine(px,py, (int) (px+radius * Math.cos(roll)), (int) (py + radius * Math.sin(roll)), markerPaint); canvas.drawLine(px,py, (int) (px+radius * Math.cos(roll)), (int) (py + radius * Math.sin(roll)), markerPaint);
canvas.drawLine(px,py, (int) (px+radius * Math.cos(pitch)), (int) (py + radius * Math.sin(pitch)), markerPaint); canvas.drawLine(px,py, (int) (px+radius * Math.cos(pitch)), (int) (py + radius * Math.sin(pitch)), markerPaint);
} }

View File

@ -1,12 +1,38 @@
/**
******************************************************************************
* @file BluetoothDevicePreference.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A dialog in the preferences options that shows the paired BT
* devices.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import android.bluetooth.*; import java.util.Set;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.util.AttributeSet; import android.util.AttributeSet;
import java.util.Set;
public class BluetoothDevicePreference extends ListPreference { public class BluetoothDevicePreference extends ListPreference {
public BluetoothDevicePreference(Context context, AttributeSet attrs) { public BluetoothDevicePreference(Context context, AttributeSet attrs) {

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file BluetoothUAVTalk.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Telemetry over bluetooth.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.io.IOException; import java.io.IOException;
@ -24,19 +48,19 @@ import android.util.Log;
public static int LOGLEVEL = 2; public static int LOGLEVEL = 2;
public static boolean WARN = LOGLEVEL > 1; public static boolean WARN = LOGLEVEL > 1;
public static boolean DEBUG = LOGLEVEL > 0; public static boolean DEBUG = LOGLEVEL > 0;
// Temporarily define fixed device name // Temporarily define fixed device name
private String device_name = "RN42-222D"; private String device_name = "RN42-222D";
private final static UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); private final static UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private BluetoothAdapter mBluetoothAdapter; private BluetoothAdapter mBluetoothAdapter;
private BluetoothSocket socket; private BluetoothSocket socket;
private BluetoothDevice device; private BluetoothDevice device;
private UAVTalk uavTalk; private UAVTalk uavTalk;
private boolean connected; private boolean connected;
public BluetoothUAVTalk(Context caller) { public BluetoothUAVTalk(Context caller) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(caller); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(caller);
device_name = prefs.getString("bluetooth_mac",""); device_name = prefs.getString("bluetooth_mac","");
@ -44,52 +68,52 @@ import android.util.Log;
connected = false; connected = false;
device = null; device = null;
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) { if (mBluetoothAdapter == null) {
// Device does not support Bluetooth // Device does not support Bluetooth
Log.e(TAG, "Device does not support Bluetooth"); Log.e(TAG, "Device does not support Bluetooth");
return; return;
} }
if (!mBluetoothAdapter.isEnabled()) { if (!mBluetoothAdapter.isEnabled()) {
// Enable bluetooth if it isn't already // Enable bluetooth if it isn't already
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
caller.sendOrderedBroadcast(enableBtIntent, "android.permission.BLUETOOTH_ADMIN", new BroadcastReceiver() { caller.sendOrderedBroadcast(enableBtIntent, "android.permission.BLUETOOTH_ADMIN", new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.e(TAG,"Received " + context + intent); Log.e(TAG,"Received " + context + intent);
//TODO: some logic here to see if it worked //TODO: some logic here to see if it worked
queryDevices(); queryDevices();
} }
}, null, Activity.RESULT_OK, null, null); }, null, Activity.RESULT_OK, null, null);
} else { } else {
queryDevices(); queryDevices();
} }
} }
public boolean connect(UAVObjectManager objMngr) { public boolean connect(UAVObjectManager objMngr) {
if( getConnected() ) if( getConnected() )
return true; return true;
if( !getFoundDevice() ) if( !getFoundDevice() )
return false; return false;
if( !openTelemetryBluetooth(objMngr) ) if( !openTelemetryBluetooth(objMngr) )
return false; return false;
return true; return true;
} }
public boolean getConnected() { public boolean getConnected() {
return connected; return connected;
} }
public boolean getFoundDevice() { public boolean getFoundDevice() {
return (device != null); return (device != null);
} }
public UAVTalk getUavtalk() { public UAVTalk getUavtalk() {
return uavTalk; return uavTalk;
} }
private void queryDevices() { private void queryDevices() {
Log.d(TAG, "Searching for devices"); Log.d(TAG, "Searching for devices");
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
@ -107,7 +131,7 @@ import android.util.Log;
} }
} }
} }
} }
private boolean openTelemetryBluetooth(UAVObjectManager objMngr) { private boolean openTelemetryBluetooth(UAVObjectManager objMngr) {
@ -119,11 +143,11 @@ import android.util.Log;
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG,"Unable to create Rfcomm socket"); Log.e(TAG,"Unable to create Rfcomm socket");
return false; return false;
//e.printStackTrace(); //e.printStackTrace();
} }
mBluetoothAdapter.cancelDiscovery(); mBluetoothAdapter.cancelDiscovery();
try { try {
socket.connect(); socket.connect();
} }
@ -138,7 +162,7 @@ import android.util.Log;
} }
connected = true; connected = true;
try { try {
uavTalk = new UAVTalk(socket.getInputStream(), socket.getOutputStream(), objMngr); uavTalk = new UAVTalk(socket.getInputStream(), socket.getOutputStream(), objMngr);
} catch (IOException e) { } catch (IOException e) {
@ -147,7 +171,7 @@ import android.util.Log;
//e.printStackTrace(); //e.printStackTrace();
return false; return false;
} }
return true; return true;
} }

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file CompassView.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A view of the compass heading.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import android.content.Context; import android.content.Context;
@ -14,104 +38,104 @@ public class CompassView extends View {
initCompassView(); initCompassView();
} }
public CompassView(Context context, AttributeSet ats, int defaultStyle) { public CompassView(Context context, AttributeSet ats, int defaultStyle) {
super(context, ats, defaultStyle); super(context, ats, defaultStyle);
initCompassView(); initCompassView();
} }
public CompassView(Context context, AttributeSet ats) { public CompassView(Context context, AttributeSet ats) {
super(context, ats); super(context, ats);
initCompassView(); initCompassView();
} }
protected void initCompassView() { protected void initCompassView() {
setFocusable(true); setFocusable(true);
circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(R.color.background_color); circlePaint.setColor(getResources().getColor(R.color.background_color));
circlePaint.setStrokeWidth(1); circlePaint.setStrokeWidth(1);
circlePaint.setStyle(Paint.Style.FILL_AND_STROKE); circlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
Resources r = this.getResources(); Resources r = this.getResources();
northString = r.getString(R.string.cardinal_north); northString = r.getString(R.string.cardinal_north);
eastString = r.getString(R.string.cardinal_east); eastString = r.getString(R.string.cardinal_east);
southString = r.getString(R.string.cardinal_south); southString = r.getString(R.string.cardinal_south);
westString = r.getString(R.string.cardinal_west); westString = r.getString(R.string.cardinal_west);
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(r.getColor(R.color.text_color)); textPaint.setColor(r.getColor(R.color.text_color));
textHeight = (int)textPaint.measureText("yY"); textHeight = (int)textPaint.measureText("yY");
markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
markerPaint.setColor(r.getColor(R.color.marker_color)); markerPaint.setColor(r.getColor(R.color.marker_color));
} }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredWidth = measure(widthMeasureSpec); int measuredWidth = measure(widthMeasureSpec);
int measuredHeight = measure(heightMeasureSpec); int measuredHeight = measure(heightMeasureSpec);
int d = Math.min(measuredWidth, measuredHeight); int d = Math.min(measuredWidth, measuredHeight);
setMeasuredDimension(d/2, d/2); setMeasuredDimension(d/2, d/2);
} }
private int measure(int measureSpec) { private int measure(int measureSpec) {
int result = 0; int result = 0;
// Decode the measurement specifications. // Decode the measurement specifications.
int specMode = MeasureSpec.getMode(measureSpec); int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec); int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.UNSPECIFIED) { // Return a default size of 200 if no bounds are specified. if (specMode == MeasureSpec.UNSPECIFIED) { // Return a default size of 200 if no bounds are specified.
result = 200; result = 200;
} else { } else {
// As you want to fill the available space // As you want to fill the available space
// always return the full available bounds. // always return the full available bounds.
result = specSize; result = specSize;
} }
return result; return result;
} }
private double bearing; private double bearing;
public void setBearing(double bearing) { public void setBearing(double bearing) {
this.bearing = bearing; this.bearing = bearing;
} }
// Drawing related code // Drawing related code
private Paint markerPaint; private Paint markerPaint;
private Paint textPaint; private Paint textPaint;
private Paint circlePaint; private Paint circlePaint;
private String northString; private String northString;
private String eastString; private String eastString;
private String southString; private String southString;
private String westString; private String westString;
private int textHeight; private int textHeight;
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
int px = getMeasuredWidth() / 2; int px = getMeasuredWidth() / 2;
int py = getMeasuredHeight() /2 ; int py = getMeasuredHeight() /2 ;
int radius = Math.min(px, py); int radius = Math.min(px, py);
// Draw the background // Draw the background
canvas.drawCircle(px, py, radius, circlePaint); canvas.drawCircle(px, py, radius, circlePaint);
// Rotate our perspective so that the ÔtopÕ is // Rotate our perspective so that the ÔtopÕ is
// facing the current bearing. // facing the current bearing.
canvas.save(); canvas.save();
canvas.rotate((float) -bearing, px, py); canvas.rotate((float) -bearing, px, py);
int textWidth = (int)textPaint.measureText("W"); int textWidth = (int)textPaint.measureText("W");
int cardinalX = px-textWidth/2; int cardinalX = px-textWidth/2;
int cardinalY = py-radius+textHeight; int cardinalY = py-radius+textHeight;
// Draw the marker every 15 degrees and text every 45. // Draw the marker every 15 degrees and text every 45.
for (int i = 0; i < 24; i++) { for (int i = 0; i < 24; i++) {
// Draw a marker. // Draw a marker.
canvas.drawLine(px, py-radius, px, py-radius+10, markerPaint); canvas.drawLine(px, py-radius, px, py-radius+10, markerPaint);
canvas.save(); canvas.save();
canvas.translate(0, textHeight); canvas.translate(0, textHeight);
// Draw the cardinal points // Draw the cardinal points
if (i % 6 == 0) { if (i % 6 == 0) {
String dirString = null; String dirString = null;
switch (i) { switch (i) {
case 0 : { case 0 : {
dirString = northString; dirString = northString;
int arrowY = 2*textHeight; int arrowY = 2*textHeight;
canvas.drawLine(px, arrowY, px-5, 3*textHeight, markerPaint); canvas.drawLine(px, arrowY, px-5, 3*textHeight, markerPaint);
canvas.drawLine(px, arrowY, px+5, 3*textHeight, markerPaint); canvas.drawLine(px, arrowY, px+5, 3*textHeight, markerPaint);
break; break;
@ -122,18 +146,18 @@ public class CompassView extends View {
} }
canvas.drawText(dirString, cardinalX, cardinalY, textPaint); canvas.drawText(dirString, cardinalX, cardinalY, textPaint);
} }
else if (i % 3 == 0) { else if (i % 3 == 0) {
// Draw the text every alternate 45deg // Draw the text every alternate 45deg
String angle = String.valueOf(i*15); String angle = String.valueOf(i*15);
float angleTextWidth = textPaint.measureText(angle); float angleTextWidth = textPaint.measureText(angle);
int angleTextX = (int)(px-angleTextWidth/2); int angleTextX = (int)(px-angleTextWidth/2);
int angleTextY = py-radius+textHeight; int angleTextY = py-radius+textHeight;
canvas.drawText(angle, angleTextX, angleTextY, textPaint); canvas.drawText(angle, angleTextX, angleTextY, textPaint);
} }
canvas.restore(); canvas.restore();
canvas.rotate(15, px, py); canvas.rotate(15, px, py);
} }
canvas.restore(); canvas.restore();
} }
} }

View File

@ -1,3 +1,28 @@
/**
******************************************************************************
* @file Controller.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Allows controlling the UAV over telemetry. This activity
* pushes the appropriate settings to the remote device for it to
* listen to the GCSReceiver.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.util.Observable; import java.util.Observable;
@ -9,16 +34,16 @@ import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectField; import org.openpilot.uavtalk.UAVObjectField;
import com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickView;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickView;
public class Controller extends ObjectManagerActivity { public class Controller extends ObjectManagerActivity {
private final String TAG = "Controller"; private final String TAG = "Controller";
@ -29,18 +54,18 @@ public class Controller extends ObjectManagerActivity {
private final int PITCH_CHANNEL = 2; private final int PITCH_CHANNEL = 2;
private final int YAW_CHANNEL = 3; private final int YAW_CHANNEL = 3;
private final int FLIGHTMODE_CHANNEL = 4; private final int FLIGHTMODE_CHANNEL = 4;
private final int CHANNEL_MIN = 1000; private final int CHANNEL_MIN = 1000;
private final int CHANNEL_MAX = 2000; private final int CHANNEL_MAX = 2000;
private final int CHANNEL_NEUTRAL = 1500; private final int CHANNEL_NEUTRAL = 1500;
private final int CHANNEL_NEUTRAL_THROTTLE = 1100; private final int CHANNEL_NEUTRAL_THROTTLE = 1100;
private double throttle = 0.1, roll = 0.1, pitch = -0.1, yaw = 0; private double throttle = 0.1, roll = 0.1, pitch = -0.1, yaw = 0;
private boolean updated; private boolean updated;
private boolean leftJoystickHeld, rightJoystickHeld; private boolean leftJoystickHeld, rightJoystickHeld;
Timer sendTimer = new Timer(); Timer sendTimer = new Timer();
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -63,7 +88,7 @@ public class Controller extends ObjectManagerActivity {
} }
} }
}; };
@Override @Override
void onOPConnected() { void onOPConnected() {
super.onOPConnected(); super.onOPConnected();
@ -74,43 +99,48 @@ public class Controller extends ObjectManagerActivity {
manualControl.addUpdatedObserver(updatedObserver); manualControl.addUpdatedObserver(updatedObserver);
} }
UAVDataObject manualControlSettings = (UAVDataObject) objMngr.getObject("ManualControlSettings"); UAVDataObject manualControlSettings = (UAVDataObject) objMngr.getObject("ManualControlSettings");
if(manualControlSettings != null) { if(manualControlSettings != null) {
Log.d(TAG, "Requested settings update"); Log.d(TAG, "Requested settings update");
manualControlSettings.addUpdatedObserver(updatedObserver); manualControlSettings.addUpdatedObserver(updatedObserver);
manualControlSettings.updateRequested(); manualControlSettings.updateRequested();
} }
final double MOVEMENT_RANGE = 50.0; final double MOVEMENT_RANGE = 50.0;
DualJoystickView joystick = (DualJoystickView) findViewById(R.id.dualjoystickView); DualJoystickView joystick = (DualJoystickView) findViewById(R.id.dualjoystickView);
joystick.setMovementConstraint(JoystickView.CONSTRAIN_BOX); joystick.setMovementConstraint(JoystickView.CONSTRAIN_BOX);
joystick.setMovementRange((int)MOVEMENT_RANGE, (int)MOVEMENT_RANGE); joystick.setMovementRange((int)MOVEMENT_RANGE, (int)MOVEMENT_RANGE);
// Hardcode a Mode 1 listener for now // Hardcode a Mode 1 listener for now
joystick.setOnJostickMovedListener(new JoystickMovedListener() { joystick.setOnJostickMovedListener(new JoystickMovedListener() {
@Override
public void OnMoved(int pan, int tilt) { public void OnMoved(int pan, int tilt) {
pitch = (double) tilt / MOVEMENT_RANGE; pitch = tilt / MOVEMENT_RANGE;
yaw = (double) pan / MOVEMENT_RANGE; yaw = pan / MOVEMENT_RANGE;
leftJoystickHeld = true; leftJoystickHeld = true;
} }
@Override
public void OnReleased() { leftJoystickHeld = false; throttle = -1; updated = true; } public void OnReleased() { leftJoystickHeld = false; throttle = -1; updated = true; }
@Override @Override
public void OnReturnedToCenter() { } public void OnReturnedToCenter() { }
}, new JoystickMovedListener() { }, new JoystickMovedListener() {
@Override
public void OnMoved(int pan, int tilt) { public void OnMoved(int pan, int tilt) {
throttle = (double) (-tilt + (MOVEMENT_RANGE -5)) / (MOVEMENT_RANGE - 5); throttle = (-tilt + (MOVEMENT_RANGE -5)) / (MOVEMENT_RANGE - 5);
throttle *= 0.5; throttle *= 0.5;
if (throttle < 0) if (throttle < 0)
throttle = -1; throttle = -1;
roll = (double) pan / MOVEMENT_RANGE; roll = pan / MOVEMENT_RANGE;
rightJoystickHeld = true; rightJoystickHeld = true;
} }
@Override
public void OnReleased() { rightJoystickHeld = false; throttle = -1; updated = true; } public void OnReleased() { rightJoystickHeld = false; throttle = -1; updated = true; }
@Override @Override
public void OnReturnedToCenter() { } public void OnReturnedToCenter() { }
}) ; }) ;
TimerTask controllerTask = new TimerTask() { TimerTask controllerTask = new TimerTask() {
@Override
public void run() { public void run() {
uavobjHandler.post(new Runnable() { uavobjHandler.post(new Runnable() {
@Override @Override
@ -152,17 +182,19 @@ public class Controller extends ObjectManagerActivity {
* The callbacks from the UAVOs must run in the correct thread to update the * The callbacks from the UAVOs must run in the correct thread to update the
* UI. This is what using a runnable does. * UI. This is what using a runnable does.
*/ */
final Handler uavobjHandler = new Handler(); final Handler uavobjHandler = new Handler();
final Runnable updateText = new Runnable() { final Runnable updateText = new Runnable() {
@Override
public void run() { public void run() {
updateManualControl(); updateManualControl();
} }
}; };
private final Observer updatedObserver = new Observer() { private final Observer updatedObserver = new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
uavobjHandler.post(updateText); uavobjHandler.post(updateText);
} }
}; };
/** /**
@ -174,33 +206,33 @@ public class Controller extends ObjectManagerActivity {
if (manualView != null && manualControl != null) if (manualView != null && manualControl != null)
manualView.setText(manualControl.toStringData()); manualView.setText(manualControl.toStringData());
} }
/** /**
* Active GCS receiver mode * Active GCS receiver mode
*/ */
private void activateGcsReceiver() { private void activateGcsReceiver() {
UAVObject manualControlSettings = objMngr.getObject("ManualControlSettings"); UAVObject manualControlSettings = objMngr.getObject("ManualControlSettings");
if (manualControlSettings == null) { if (manualControlSettings == null) {
Toast.makeText(this, "Failed to get manual control settings", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Failed to get manual control settings", Toast.LENGTH_SHORT).show();
return; return;
} }
UAVObjectField channelGroups = manualControlSettings.getField("ChannelGroups"); UAVObjectField channelGroups = manualControlSettings.getField("ChannelGroups");
UAVObjectField channelNumber = manualControlSettings.getField("ChannelNumber"); UAVObjectField channelNumber = manualControlSettings.getField("ChannelNumber");
UAVObjectField channelMax = manualControlSettings.getField("ChannelMax"); UAVObjectField channelMax = manualControlSettings.getField("ChannelMax");
UAVObjectField channelNeutral = manualControlSettings.getField("ChannelNeutral"); UAVObjectField channelNeutral = manualControlSettings.getField("ChannelNeutral");
UAVObjectField channelMin = manualControlSettings.getField("ChannelMin"); UAVObjectField channelMin = manualControlSettings.getField("ChannelMin");
if (channelGroups == null || channelMax == null || channelNeutral == null || if (channelGroups == null || channelMax == null || channelNeutral == null ||
channelMin == null || channelNumber == null) { channelMin == null || channelNumber == null) {
Toast.makeText(this, "Manual control settings not formatted correctly", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Manual control settings not formatted correctly", Toast.LENGTH_SHORT).show();
return; return;
} }
/* Configure the manual control module how the GCS controller expects /* Configure the manual control module how the GCS controller expects
* This order MUST correspond to the enumeration order of ChannelNumber in * This order MUST correspond to the enumeration order of ChannelNumber in
* ManualControlSettings. * ManualControlSettings.
*/ */
int channels[] = { THROTTLE_CHANNEL, ROLL_CHANNEL, PITCH_CHANNEL, YAW_CHANNEL, FLIGHTMODE_CHANNEL }; int channels[] = { THROTTLE_CHANNEL, ROLL_CHANNEL, PITCH_CHANNEL, YAW_CHANNEL, FLIGHTMODE_CHANNEL };
for (int i = 0; i < channels.length; i++) { for (int i = 0; i < channels.length; i++) {
channelGroups.setValue("GCS", channels[i]); channelGroups.setValue("GCS", channels[i]);
@ -216,23 +248,23 @@ public class Controller extends ObjectManagerActivity {
break; break;
} }
} }
// Send settings to the UAV // Send settings to the UAV
manualControlSettings.updated(); manualControlSettings.updated();
} }
/** /**
* Scale the channels to the output range the flight controller expects * Scale the channels to the output range the flight controller expects
*/ */
private float scaleChannel(double in, double neutral) { private float scaleChannel(double in, double neutral) {
// Check bounds // Check bounds
if (in > 1) if (in > 1)
in = 1; in = 1;
if (in < -1) if (in < -1)
in = -1; in = -1;
if (in >= 0) if (in >= 0)
return (float) (neutral + (CHANNEL_MAX - neutral) * in); return (float) (neutral + (CHANNEL_MAX - neutral) * in);
return (float) (neutral + (neutral - CHANNEL_MIN) * in); return (float) (neutral + (neutral - CHANNEL_MIN) * in);

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file HomePage.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Main launch page for the Android GCS actitivies
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import android.content.Intent; import android.content.Intent;
@ -10,48 +33,54 @@ public class HomePage extends ObjectManagerActivity {
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.gcs_home); setContentView(R.layout.gcs_home);
Button objectBrowser = (Button) findViewById(R.id.launch_object_browser); Button objectBrowser = (Button) findViewById(R.id.launch_object_browser);
objectBrowser.setOnClickListener(new OnClickListener() { objectBrowser.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) { public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, ObjectBrowser.class)); startActivity(new Intent(HomePage.this, ObjectBrowser.class));
} }
}); });
Button pfd = (Button) findViewById(R.id.launch_pfd); Button pfd = (Button) findViewById(R.id.launch_pfd);
pfd.setOnClickListener(new OnClickListener() { pfd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) { public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, PFD.class)); startActivity(new Intent(HomePage.this, PFD.class));
} }
}); });
Button location = (Button) findViewById(R.id.launch_location); Button location = (Button) findViewById(R.id.launch_location);
location.setOnClickListener(new OnClickListener() { location.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) { public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, UAVLocation.class)); startActivity(new Intent(HomePage.this, UAVLocation.class));
} }
}); });
Button controller = (Button) findViewById(R.id.launch_controller); Button controller = (Button) findViewById(R.id.launch_controller);
controller.setOnClickListener(new OnClickListener() { controller.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) { public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, Controller.class)); startActivity(new Intent(HomePage.this, Controller.class));
} }
}); });
Button logger = (Button) findViewById(R.id.launch_logger); Button logger = (Button) findViewById(R.id.launch_logger);
logger.setOnClickListener(new OnClickListener() { logger.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) { public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, Logger.class)); startActivity(new Intent(HomePage.this, Logger.class));
} }
}); });
Button alarms = (Button) findViewById(R.id.launch_alarms); Button alarms = (Button) findViewById(R.id.launch_alarms);
alarms.setOnClickListener(new OnClickListener() { alarms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) { public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, SystemAlarmActivity.class)); startActivity(new Intent(HomePage.this, SystemAlarmActivity.class));
} }
}); });
} }

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file Logger.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Controller for logging data as well as interface for getting that
* data on and off the tablet.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.io.File; import java.io.File;
@ -16,17 +40,17 @@ import android.widget.TextView;
public class Logger extends ObjectManagerActivity { public class Logger extends ObjectManagerActivity {
final String TAG = "Logger"; final String TAG = "Logger";
final boolean VERBOSE = false; final boolean VERBOSE = false;
final boolean DEBUG = true; final boolean DEBUG = true;
private File file; private File file;
private boolean logging; private boolean logging;
private FileOutputStream fileStream; private FileOutputStream fileStream;
private UAVTalk uavTalk; private UAVTalk uavTalk;
private int writtenBytes; private int writtenBytes;
private int writtenObjects; private int writtenObjects;
@ -36,15 +60,15 @@ public class Logger extends ObjectManagerActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.logger); setContentView(R.layout.logger);
} }
private void onStartLogging() { private void onStartLogging() {
File root = Environment.getExternalStorageDirectory(); File root = Environment.getExternalStorageDirectory();
Date d = new Date(); Date d = new Date();
String date = (new SimpleDateFormat("yyyyMMdd_hhmmss")).format(d); String date = (new SimpleDateFormat("yyyyMMdd_hhmmss")).format(d);
String fileName = "/logs/logs_" + date + ".opl"; String fileName = "/logs/logs_" + date + ".opl";
file = new File(root, fileName); file = new File(root, fileName);
if (DEBUG) Log.d(TAG, "Trying for file: " + file.getAbsolutePath()); if (DEBUG) Log.d(TAG, "Trying for file: " + file.getAbsolutePath());
try { try {
@ -60,10 +84,10 @@ public class Logger extends ObjectManagerActivity {
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Could not write file " + e.getMessage()); Log.e(TAG, "Could not write file " + e.getMessage());
} }
// TODO: if logging succeeded then retrieve all settings // TODO: if logging succeeded then retrieve all settings
} }
private void onStopLogging() { private void onStopLogging() {
if (DEBUG) Log.d(TAG, "Stop logging"); if (DEBUG) Log.d(TAG, "Stop logging");
logging = false; logging = false;
@ -74,11 +98,11 @@ public class Logger extends ObjectManagerActivity {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Override @Override
void onOPConnected() { void onOPConnected() {
super.onOPConnected(); super.onOPConnected();
if (DEBUG) Log.d(TAG, "onOPConnected()"); if (DEBUG) Log.d(TAG, "onOPConnected()");
onStartLogging(); onStartLogging();
registerObjectUpdates(objMngr.getObjects()); registerObjectUpdates(objMngr.getObjects());
@ -104,7 +128,7 @@ public class Logger extends ObjectManagerActivity {
onStartLogging(); onStartLogging();
} }
/** /**
* Called whenever any objects subscribed to via registerObjects * Called whenever any objects subscribed to via registerObjects
*/ */
@Override @Override
protected void objectUpdated(UAVObject obj) { protected void objectUpdated(UAVObject obj) {
@ -126,18 +150,18 @@ public class Logger extends ObjectManagerActivity {
fileStream.write((byte)(size & 0x0000ff0000000000l) >> 40); fileStream.write((byte)(size & 0x0000ff0000000000l) >> 40);
fileStream.write((byte)(size & 0x00ff000000000000l) >> 48); fileStream.write((byte)(size & 0x00ff000000000000l) >> 48);
fileStream.write((byte)(size & 0xff00000000000000l) >> 56); fileStream.write((byte)(size & 0xff00000000000000l) >> 56);
uavTalk.sendObject(obj, false, false); uavTalk.sendObject(obj, false, false);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
writtenBytes += obj.getNumBytes(); writtenBytes += obj.getNumBytes();
writtenObjects ++; writtenObjects ++;
((TextView) findViewById(R.id.logger_number_of_bytes)).setText(Integer.valueOf(writtenBytes).toString()); ((TextView) findViewById(R.id.logger_number_of_bytes)).setText(Integer.valueOf(writtenBytes).toString());
((TextView) findViewById(R.id.logger_number_of_objects)).setText(Integer.valueOf(writtenObjects).toString()); ((TextView) findViewById(R.id.logger_number_of_objects)).setText(Integer.valueOf(writtenObjects).toString());
} }
} }
} }

View File

@ -1,3 +1,29 @@
/**
******************************************************************************
* @file OPTelemetryService.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Provides UAVTalk telemetry over multiple physical links. The
* details of each of these are in their respective connection
* classes. This mostly creates those threads based on the selected
* preferences.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.io.IOException; import java.io.IOException;
@ -67,7 +93,7 @@ public class OPTelemetryService extends Service {
case MSG_START: case MSG_START:
stopSelf(msg.arg2); stopSelf(msg.arg2);
break; break;
case MSG_CONNECT: case MSG_CONNECT:
terminate = false; terminate = false;
int connection_type; int connection_type;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this);
@ -111,7 +137,7 @@ public class OPTelemetryService extends Service {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(INTENT_ACTION_DISCONNECTED); intent.setAction(INTENT_ACTION_DISCONNECTED);
sendBroadcast(intent,null); sendBroadcast(intent,null);
stopSelf(); stopSelf();
break; break;
@ -131,14 +157,14 @@ public class OPTelemetryService extends Service {
*/ */
public void startup() { public void startup() {
Toast.makeText(getApplicationContext(), "Telemetry service starting", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Telemetry service starting", Toast.LENGTH_SHORT).show();
thread = new HandlerThread("TelemetryServiceHandler", Process.THREAD_PRIORITY_BACKGROUND); thread = new HandlerThread("TelemetryServiceHandler", Process.THREAD_PRIORITY_BACKGROUND);
thread.start(); thread.start();
// Get the HandlerThread's Looper and use it for our Handler // Get the HandlerThread's Looper and use it for our Handler
mServiceLooper = thread.getLooper(); mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper); mServiceHandler = new ServiceHandler(mServiceLooper);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this);
if(prefs.getBoolean("autoconnect", false)) { if(prefs.getBoolean("autoconnect", false)) {
Message msg = mServiceHandler.obtainMessage(); Message msg = mServiceHandler.obtainMessage();
@ -148,7 +174,7 @@ public class OPTelemetryService extends Service {
} }
} }
@Override @Override
public void onCreate() { public void onCreate() {
startup(); startup();
@ -157,19 +183,19 @@ public class OPTelemetryService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
// Currently only using as bound service // Currently only using as bound service
// If we get killed, after returning from here, restart // If we get killed, after returning from here, restart
return START_STICKY; return START_STICKY;
} }
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return mBinder; return mBinder;
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
Toast.makeText(this, "Telemetry service done", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Telemetry service done", Toast.LENGTH_SHORT).show();
} }
public class LocalBinder extends Binder { public class LocalBinder extends Binder {
@ -206,9 +232,10 @@ public class OPTelemetryService extends Service {
public UAVObjectManager getObjectManager(); public UAVObjectManager getObjectManager();
}; };
// Fake class for testing, simply emits periodic updates on // Fake class for testing, simply emits periodic updates on
private class FakeTelemetryThread extends Thread implements TelemTask { private class FakeTelemetryThread extends Thread implements TelemTask {
private UAVObjectManager objMngr; private final UAVObjectManager objMngr;
@Override
public UAVObjectManager getObjectManager() { return objMngr; }; public UAVObjectManager getObjectManager() { return objMngr; };
FakeTelemetryThread() { FakeTelemetryThread() {
@ -216,6 +243,7 @@ public class OPTelemetryService extends Service {
UAVObjectsInitialize.register(objMngr); UAVObjectsInitialize.register(objMngr);
} }
@Override
public void run() { public void run() {
System.out.println("Running fake thread"); System.out.println("Running fake thread");
@ -229,22 +257,22 @@ public class OPTelemetryService extends Service {
UAVDataObject homeLocation = (UAVDataObject) objMngr.getObject("HomeLocation"); UAVDataObject homeLocation = (UAVDataObject) objMngr.getObject("HomeLocation");
UAVDataObject positionActual = (UAVDataObject) objMngr.getObject("PositionActual"); UAVDataObject positionActual = (UAVDataObject) objMngr.getObject("PositionActual");
UAVDataObject systemAlarms = (UAVDataObject) objMngr.getObject("SystemAlarms"); UAVDataObject systemAlarms = (UAVDataObject) objMngr.getObject("SystemAlarms");
systemAlarms.getField("Alarm").setValue("Warning",0); systemAlarms.getField("Alarm").setValue("Warning",0);
systemAlarms.getField("Alarm").setValue("OK",1); systemAlarms.getField("Alarm").setValue("OK",1);
systemAlarms.getField("Alarm").setValue("Critical",2); systemAlarms.getField("Alarm").setValue("Critical",2);
systemAlarms.getField("Alarm").setValue("Error",3); systemAlarms.getField("Alarm").setValue("Error",3);
systemAlarms.updated(); systemAlarms.updated();
homeLocation.getField("Latitude").setDouble(379420315); homeLocation.getField("Latitude").setDouble(379420315);
homeLocation.getField("Longitude").setDouble(-88330078); homeLocation.getField("Longitude").setDouble(-88330078);
homeLocation.getField("Be").setDouble(26702.78710938,0); homeLocation.getField("Be").setDouble(26702.78710938,0);
homeLocation.getField("Be").setDouble(-1468.33605957,1); homeLocation.getField("Be").setDouble(-1468.33605957,1);
homeLocation.getField("Be").setDouble(34181.78515625,2); homeLocation.getField("Be").setDouble(34181.78515625,2);
double roll = 0; double roll = 0;
double pitch = 0; double pitch = 0;
double yaw = 0; double yaw = 0;
double north = 0; double north = 0;
double east = 0; double east = 0;
@ -257,7 +285,7 @@ public class OPTelemetryService extends Service {
roll = (roll + 10) % 180; roll = (roll + 10) % 180;
pitch = (pitch + 10) % 180; pitch = (pitch + 10) % 180;
yaw = (yaw + 10) % 360; yaw = (yaw + 10) % 360;
systemStats.updated(); systemStats.updated();
attitudeActual.updated(); attitudeActual.updated();
positionActual.updated(); positionActual.updated();
@ -269,13 +297,14 @@ public class OPTelemetryService extends Service {
} }
} }
} }
private class BTTelemetryThread extends Thread implements TelemTask { private class BTTelemetryThread extends Thread implements TelemTask {
private UAVObjectManager objMngr; private final UAVObjectManager objMngr;
private UAVTalk uavTalk; private UAVTalk uavTalk;
private Telemetry tel; private Telemetry tel;
private TelemetryMonitor mon; private TelemetryMonitor mon;
@Override
public UAVObjectManager getObjectManager() { return objMngr; }; public UAVObjectManager getObjectManager() { return objMngr; };
BTTelemetryThread() { BTTelemetryThread() {
@ -283,10 +312,11 @@ public class OPTelemetryService extends Service {
UAVObjectsInitialize.register(objMngr); UAVObjectsInitialize.register(objMngr);
} }
public void run() { @Override
public void run() {
if (DEBUG) Log.d(TAG, "Telemetry Thread started"); if (DEBUG) Log.d(TAG, "Telemetry Thread started");
Looper.prepare(); Looper.prepare();
BluetoothUAVTalk bt = new BluetoothUAVTalk(OPTelemetryService.this); BluetoothUAVTalk bt = new BluetoothUAVTalk(OPTelemetryService.this);
for( int i = 0; i < 10; i++ ) { for( int i = 0; i < 10; i++ ) {
@ -318,14 +348,15 @@ public class OPTelemetryService extends Service {
tel = new Telemetry(uavTalk, objMngr); tel = new Telemetry(uavTalk, objMngr);
mon = new TelemetryMonitor(objMngr,tel); mon = new TelemetryMonitor(objMngr,tel);
mon.addObserver(new Observer() { mon.addObserver(new Observer() {
@Override
public void update(Observable arg0, Object arg1) { public void update(Observable arg0, Object arg1) {
System.out.println("Mon updated. Connected: " + mon.getConnected() + " objects updated: " + mon.getObjectsUpdated()); System.out.println("Mon updated. Connected: " + mon.getConnected() + " objects updated: " + mon.getObjectsUpdated());
if(mon.getConnected() /*&& mon.getObjectsUpdated()*/) { if(mon.getConnected() /*&& mon.getObjectsUpdated()*/) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(INTENT_ACTION_CONNECTED); intent.setAction(INTENT_ACTION_CONNECTED);
sendBroadcast(intent,null); sendBroadcast(intent,null);
} }
} }
}); });
@ -345,13 +376,14 @@ public class OPTelemetryService extends Service {
}; };
private class TcpTelemetryThread extends Thread implements TelemTask { private class TcpTelemetryThread extends Thread implements TelemTask {
private UAVObjectManager objMngr; private final UAVObjectManager objMngr;
private UAVTalk uavTalk; private UAVTalk uavTalk;
private Telemetry tel; private Telemetry tel;
private TelemetryMonitor mon; private TelemetryMonitor mon;
@Override
public UAVObjectManager getObjectManager() { return objMngr; }; public UAVObjectManager getObjectManager() { return objMngr; };
TcpTelemetryThread() { TcpTelemetryThread() {
@ -359,7 +391,8 @@ public class OPTelemetryService extends Service {
UAVObjectsInitialize.register(objMngr); UAVObjectsInitialize.register(objMngr);
} }
public void run() { @Override
public void run() {
if (DEBUG) Log.d(TAG, "Telemetry Thread started"); if (DEBUG) Log.d(TAG, "Telemetry Thread started");
Looper.prepare(); Looper.prepare();
@ -371,7 +404,7 @@ public class OPTelemetryService extends Service {
tcp.connect(objMngr); tcp.connect(objMngr);
if( tcp.getConnected() ) if( tcp.getConnected() )
break; break;
try { try {
@ -394,6 +427,7 @@ public class OPTelemetryService extends Service {
tel = new Telemetry(uavTalk, objMngr); tel = new Telemetry(uavTalk, objMngr);
mon = new TelemetryMonitor(objMngr,tel); mon = new TelemetryMonitor(objMngr,tel);
mon.addObserver(new Observer() { mon.addObserver(new Observer() {
@Override
public void update(Observable arg0, Object arg1) { public void update(Observable arg0, Object arg1) {
System.out.println("Mon updated. Connected: " + mon.getConnected() + " objects updated: " + mon.getObjectsUpdated()); System.out.println("Mon updated. Connected: " + mon.getConnected() + " objects updated: " + mon.getObjectsUpdated());
if(mon.getConnected() /*&& mon.getObjectsUpdated()*/) { if(mon.getConnected() /*&& mon.getObjectsUpdated()*/) {
@ -401,7 +435,7 @@ public class OPTelemetryService extends Service {
intent.setAction(INTENT_ACTION_CONNECTED); intent.setAction(INTENT_ACTION_CONNECTED);
sendBroadcast(intent,null); sendBroadcast(intent,null);
} }
} }
}); });
@ -417,16 +451,16 @@ public class OPTelemetryService extends Service {
} }
} }
Looper.myLooper().quit(); Looper.myLooper().quit();
// Shut down all the attached // Shut down all the attached
mon.stopMonitor(); mon.stopMonitor();
mon = null; mon = null;
tel.stopTelemetry(); tel.stopTelemetry();
tel = null; tel = null;
// Finally close the stream if it is still open // Finally close the stream if it is still open
tcp.disconnect(); tcp.disconnect();
if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected"); if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected");
toastMessage("TCP Thread finished"); toastMessage("TCP Thread finished");
} }

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file ObjectBrowser.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A simple object browser for UAVOs that allows viewing, editing,
* loading and saving.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.util.ArrayList; import java.util.ArrayList;
@ -6,6 +30,9 @@ import java.util.ListIterator;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
@ -16,6 +43,7 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
@ -23,10 +51,6 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject;
public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPreferenceChangeListener { public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPreferenceChangeListener {
@ -36,24 +60,26 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
SharedPreferences prefs; SharedPreferences prefs;
ArrayAdapter<UAVDataObject> adapter; ArrayAdapter<UAVDataObject> adapter;
List<UAVDataObject> allObjects; List<UAVDataObject> allObjects;
final Handler uavobjHandler = new Handler(); final Handler uavobjHandler = new Handler();
final Runnable updateText = new Runnable() { final Runnable updateText = new Runnable() {
@Override
public void run() { public void run() {
updateObject(); updateObject();
} }
}; };
private final Observer updatedObserver = new Observer() { private final Observer updatedObserver = new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
uavobjHandler.post(updateText); uavobjHandler.post(updateText);
} }
}; };
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.object_browser); setContentView(R.layout.object_browser);
prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this); prefs.registerOnSharedPreferenceChangeListener(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -63,7 +89,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
void onOPConnected() { void onOPConnected() {
super.onOPConnected(); super.onOPConnected();
Log.d(TAG, "onOPConnected()"); Log.d(TAG, "onOPConnected()");
OnCheckedChangeListener checkListener = new OnCheckedChangeListener() { OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
@ -71,10 +97,10 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
updateList(); updateList();
} }
}; };
((CheckBox) findViewById(R.id.dataCheck)).setOnCheckedChangeListener(checkListener); ((CheckBox) findViewById(R.id.dataCheck)).setOnCheckedChangeListener(checkListener);
((CheckBox) findViewById(R.id.settingsCheck)).setOnCheckedChangeListener(checkListener); ((CheckBox) findViewById(R.id.settingsCheck)).setOnCheckedChangeListener(checkListener);
((Button) findViewById(R.id.editButton)).setOnClickListener(new OnClickListener() { ((Button) findViewById(R.id.editButton)).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -87,7 +113,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
} }
} }
}); });
((Button) findViewById(R.id.object_load_button)).setOnClickListener(new OnClickListener() { ((Button) findViewById(R.id.object_load_button)).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -100,7 +126,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
objPer.getField("ObjectID").setValue(allObjects.get(selected_index).getObjID()); objPer.getField("ObjectID").setValue(allObjects.get(selected_index).getObjID());
objPer.getField("InstanceID").setValue(0); objPer.getField("InstanceID").setValue(0);
objPer.updated(); objPer.updated();
allObjects.get(selected_index).updateRequested(); allObjects.get(selected_index).updateRequested();
} }
} }
@ -137,6 +163,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
objects.setAdapter(adapter); objects.setAdapter(adapter);
objects.setOnItemClickListener(new OnItemClickListener() { objects.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, public void onItemClick(AdapterView<?> parent, View view,
int position, long id) { int position, long id) {
@ -149,9 +176,9 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
updateObject(); updateObject();
} }
}); });
} }
private void updateObject() { private void updateObject() {
//adapter.notifyDataSetChanged(); //adapter.notifyDataSetChanged();
TextView text = (TextView) findViewById(R.id.object_information); TextView text = (TextView) findViewById(R.id.object_information);
@ -161,6 +188,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
Log.d(TAG,"Update called but invalid index: " + selected_index); Log.d(TAG,"Update called but invalid index: " + selected_index);
} }
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) { String key) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file ObjectEditor.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A popup dialog for editing the contents of a UAVO.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.util.List; import java.util.List;
@ -17,7 +40,7 @@ import android.widget.Toast;
public class ObjectEditor extends ObjectManagerActivity { public class ObjectEditor extends ObjectManagerActivity {
static final String TAG = "ObjectEditor"; static final String TAG = "ObjectEditor";
String objectName; String objectName;
long objectID; long objectID;
long instID; long instID;
@ -58,6 +81,7 @@ public class ObjectEditor extends ObjectManagerActivity {
}); });
} }
@Override
public void onOPConnected() { public void onOPConnected() {
UAVObject obj = objMngr.getObject(objectID, instID); UAVObject obj = objMngr.getObject(objectID, instID);
if (obj == null) { if (obj == null) {
@ -86,15 +110,15 @@ public class ObjectEditor extends ObjectManagerActivity {
Toast.makeText(this, "Save failed", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Save failed", Toast.LENGTH_LONG).show();
return; return;
} }
long thisId = objectID < 0 ? ((Long) 0x100000000l) + objectID : objectID; long thisId = objectID < 0 ? 0x100000000l + objectID : objectID;
objPer.getField("Operation").setValue("Save"); objPer.getField("Operation").setValue("Save");
objPer.getField("Selection").setValue("SingleObject"); objPer.getField("Selection").setValue("SingleObject");
Log.d(TAG,"Saving with object id: " + objectID + " swapped to " + thisId); Log.d(TAG,"Saving with object id: " + objectID + " swapped to " + thisId);
objPer.getField("ObjectID").setValue(thisId); objPer.getField("ObjectID").setValue(thisId);
objPer.getField("InstanceID").setValue(instID); objPer.getField("InstanceID").setValue(instID);
objPer.updated(); objPer.updated();
Toast.makeText(this, "Save succeeded", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Save succeeded", Toast.LENGTH_LONG).show();
} }
@ -125,7 +149,7 @@ public class ObjectEditor extends ObjectManagerActivity {
default: default:
String val = ((EditText) editView.fields.get(field_idx)).getText().toString(); String val = ((EditText) editView.fields.get(field_idx)).getText().toString();
Double num = Double.parseDouble(val); Double num = Double.parseDouble(val);
Log.e(TAG, "Updating field: " + field.getName() + " value: " + num); Log.e(TAG, "Updating field: " + field.getName() + " value: " + num);
field.setValue(num, i); field.setValue(num, i);
break; break;

View File

@ -1,3 +1,32 @@
/**
******************************************************************************
* @file ObjectManagerActivity.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Base object for all activies that use the UAVObjectManager.
* This class takes care of binding to the service and getting the
* object manager as well as setting up callbacks to the objects of
* interest that run on the UI thread.
* Implements a new Android lifecycle: onOPConnected() / onOPDisconnected()
* which indicates when a valid telemetry is established as well as a
* valid object manager handle.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.util.List; import java.util.List;

View File

@ -1,3 +1,29 @@
/**
******************************************************************************
* @file ObjectManagerFragment.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Base class for all fragments that use the UAVObjectManager. This
* supports all the extensions the ObjectManagerActivity does, namely
* access to the UAVObjectManager and callbacks in the UI thread for
* object updates.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVObject;
@ -9,12 +35,12 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
public class ObjectManagerFragment extends Fragment { public class ObjectManagerFragment extends Fragment {
private static final String TAG = ObjectManagerFragment.class.getSimpleName(); private static final String TAG = ObjectManagerFragment.class.getSimpleName();
private static int LOGLEVEL = 1; private static int LOGLEVEL = 1;
// private static boolean WARN = LOGLEVEL > 1; // private static boolean WARN = LOGLEVEL > 1;
private static boolean DEBUG = LOGLEVEL > 0; private static boolean DEBUG = LOGLEVEL > 0;
UAVObjectManager objMngr; UAVObjectManager objMngr;
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@ -25,15 +51,16 @@ public class ObjectManagerFragment extends Fragment {
// For an activity this registers against the telemetry service intents. Fragments must be notified by their // For an activity this registers against the telemetry service intents. Fragments must be notified by their
// parent activity // parent activity
} }
/** /**
* Attach to the parent activity so it can notify us when the connection * Attach to the parent activity so it can notify us when the connection
* changed * changed
*/ */
public void onAttach(Activity activity) { @Override
public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
if (DEBUG) Log.d(TAG,"onAttach"); if (DEBUG) Log.d(TAG,"onAttach");
ObjectManagerActivity castActivity = null; ObjectManagerActivity castActivity = null;
try { try {
castActivity = (ObjectManagerActivity)activity; castActivity = (ObjectManagerActivity)activity;
@ -44,25 +71,25 @@ public class ObjectManagerFragment extends Fragment {
} }
castActivity.addOnConnectionListenerFragment(this); castActivity.addOnConnectionListenerFragment(this);
} }
// The below methods should all be called by the parent activity at the appropriate times // The below methods should all be called by the parent activity at the appropriate times
protected void onOPConnected(UAVObjectManager objMngr) { protected void onOPConnected(UAVObjectManager objMngr) {
this.objMngr = objMngr; this.objMngr = objMngr;
if (DEBUG) Log.d(TAG,"onOPConnected"); if (DEBUG) Log.d(TAG,"onOPConnected");
} }
protected void onOPDisconnected() { protected void onOPDisconnected() {
objMngr = null; objMngr = null;
if (DEBUG) Log.d(TAG,"onOPDisconnected"); if (DEBUG) Log.d(TAG,"onOPDisconnected");
} }
/** /**
* Called whenever any objects subscribed to via registerObjects * Called whenever any objects subscribed to via registerObjects
*/ */
protected void objectUpdated(UAVObject obj) { protected void objectUpdated(UAVObject obj) {
} }
/** /**
* Register on the activities object monitor handler so that updates * Register on the activities object monitor handler so that updates
@ -72,5 +99,5 @@ public class ObjectManagerFragment extends Fragment {
protected void registerObjectUpdates(UAVObject object) { protected void registerObjectUpdates(UAVObject object) {
((ObjectManagerActivity) getActivity()).registerObjectUpdates(object, this); ((ObjectManagerActivity) getActivity()).registerObjectUpdates(object, this);
} }
} }

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file PFD.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Shows the PFD activity.
* @see The GNU Public License (GPL) Version 3
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVObject;
@ -15,6 +38,7 @@ public class PFD extends ObjectManagerActivity {
/** /**
* Update the UI whenever the attitude is updated * Update the UI whenever the attitude is updated
*/ */
@Override
protected void objectUpdated(UAVObject obj) { protected void objectUpdated(UAVObject obj) {
// Throttle the UI redraws. Eventually this should maybe come from a periodic task // Throttle the UI redraws. Eventually this should maybe come from a periodic task
if ((System.currentTimeMillis() - lastUpdateMs) < MIN_UPDATE_PERIOD) if ((System.currentTimeMillis() - lastUpdateMs) < MIN_UPDATE_PERIOD)
@ -22,7 +46,7 @@ public class PFD extends ObjectManagerActivity {
if (obj.getName().compareTo("AttitudeActual") != 0) if (obj.getName().compareTo("AttitudeActual") != 0)
return; return;
lastUpdateMs = System.currentTimeMillis(); lastUpdateMs = System.currentTimeMillis();
heading = obj.getField("Yaw").getDouble(); heading = obj.getField("Yaw").getDouble();
pitch = obj.getField("Pitch").getDouble(); pitch = obj.getField("Pitch").getDouble();
@ -42,7 +66,7 @@ public class PFD extends ObjectManagerActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.pfd); setContentView(R.layout.pfd);
} }
@Override @Override
void onOPConnected() { void onOPConnected() {
@ -52,5 +76,5 @@ public class PFD extends ObjectManagerActivity {
UAVObject obj = objMngr.getObject("AttitudeActual"); UAVObject obj = objMngr.getObject("AttitudeActual");
if (obj != null) if (obj != null)
registerObjectUpdates(obj); registerObjectUpdates(obj);
} }
} }

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file Preferences.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Displays the preferences dialog.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import android.os.Bundle; import android.os.Bundle;

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file SystemAlarmActivity.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief An activity that displays the SystemAlarmsFragment.
* @see The GNU Public License (GPL) Version 3
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import android.os.Bundle; import android.os.Bundle;

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file SystemAlarmsFragment.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A fragment that will connect to the SystemAlarms and visualize them.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.util.List; import java.util.List;
@ -14,28 +37,30 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
public class SystemAlarmsFragment extends ObjectManagerFragment { public class SystemAlarmsFragment extends ObjectManagerFragment {
private static final String TAG = SystemAlarmsFragment.class.getSimpleName(); private static final String TAG = SystemAlarmsFragment.class.getSimpleName();
//@Override //@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
return inflater.inflate(R.layout.system_alarms_fragment, container, false); return inflater.inflate(R.layout.system_alarms_fragment, container, false);
} }
public void onOPConnected(UAVObjectManager objMngr) { @Override
public void onOPConnected(UAVObjectManager objMngr) {
super.onOPConnected(objMngr); super.onOPConnected(objMngr);
Log.d(TAG,"On connected"); Log.d(TAG,"On connected");
UAVObject obj = objMngr.getObject("SystemAlarms"); UAVObject obj = objMngr.getObject("SystemAlarms");
if (obj != null) if (obj != null)
registerObjectUpdates(obj); registerObjectUpdates(obj);
objectUpdated(obj); objectUpdated(obj);
} }
/** /**
* Called whenever any objects subscribed to via registerObjects * Called whenever any objects subscribed to via registerObjects
*/ */
@Override @Override
protected void objectUpdated(UAVObject obj) { protected void objectUpdated(UAVObject obj) {
@ -46,7 +71,7 @@ public class SystemAlarmsFragment extends ObjectManagerFragment {
List<String> names = a.getElementNames(); List<String> names = a.getElementNames();
String contents = new String(); String contents = new String();
List <String> options = a.getOptions(); List <String> options = a.getOptions();
// Rank the alarms by order of severity, skip uninitialized // Rank the alarms by order of severity, skip uninitialized
for (int j = options.size() - 1; j > 0; j--) { for (int j = options.size() - 1; j > 0; j--) {
for (int i = 0; i < names.size(); i++) { for (int i = 0; i < names.size(); i++) {
@ -57,6 +82,6 @@ public class SystemAlarmsFragment extends ObjectManagerFragment {
alarms.setText(contents); alarms.setText(contents);
} }
} }
} }

View File

@ -1,9 +1,33 @@
/**
******************************************************************************
* @file TcpUAVTalk.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief UAVTalk over TCP.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.openpilot.uavtalk.UAVObjectManager; import org.openpilot.uavtalk.UAVObjectManager;
import org.openpilot.uavtalk.UAVTalk; import org.openpilot.uavtalk.UAVTalk;
@ -17,17 +41,17 @@ public class TcpUAVTalk {
public static int LOGLEVEL = 2; public static int LOGLEVEL = 2;
public static boolean WARN = LOGLEVEL > 1; public static boolean WARN = LOGLEVEL > 1;
public static boolean DEBUG = LOGLEVEL > 0; public static boolean DEBUG = LOGLEVEL > 0;
// Temporarily define fixed device name // Temporarily define fixed device name
private String ip_address = "1"; private String ip_address = "1";
private int port = 9001; private int port = 9001;
private UAVTalk uavTalk; private UAVTalk uavTalk;
private boolean connected; private boolean connected;
private Socket socket; private Socket socket;
/** /**
* Construct a TcpUAVTalk object attached to the OPTelemetryService. Gets the * Construct a TcpUAVTalk object attached to the OPTelemetryService. Gets the
* connection settings from the preferences. * connection settings from the preferences.
*/ */
public TcpUAVTalk(Context caller) { public TcpUAVTalk(Context caller) {
@ -41,21 +65,21 @@ public class TcpUAVTalk {
if (DEBUG) Log.d(TAG, "Trying to open UAVTalk with " + ip_address); if (DEBUG) Log.d(TAG, "Trying to open UAVTalk with " + ip_address);
connected = false; connected = false;
} }
/** /**
* Connect a TCP object to an object manager. Returns true if already * Connect a TCP object to an object manager. Returns true if already
* connected, otherwise returns true if managed a successful socket. * connected, otherwise returns true if managed a successful socket.
*/ */
public boolean connect(UAVObjectManager objMngr) { public boolean connect(UAVObjectManager objMngr) {
if( getConnected() ) if( getConnected() )
return true; return true;
if( !openTelemetryTcp(objMngr) ) if( !openTelemetryTcp(objMngr) )
return false; return false;
return true; return true;
} }
public void disconnect() { public void disconnect() {
try { try {
socket.close(); socket.close();
@ -69,18 +93,18 @@ public class TcpUAVTalk {
public boolean getConnected() { public boolean getConnected() {
return connected; return connected;
} }
public UAVTalk getUavtalk() { public UAVTalk getUavtalk() {
return uavTalk; return uavTalk;
} }
/** /**
* Opens a TCP socket to the address determined on construction. If successful * Opens a TCP socket to the address determined on construction. If successful
* creates a UAVTalk stream connection this socket to the passed in object manager * creates a UAVTalk stream connection this socket to the passed in object manager
*/ */
private boolean openTelemetryTcp(UAVObjectManager objMngr) { private boolean openTelemetryTcp(UAVObjectManager objMngr) {
Log.d(TAG, "Opening connection to " + ip_address + " at address " + port); Log.d(TAG, "Opening connection to " + ip_address + " at address " + port);
InetAddress serverAddr = null; InetAddress serverAddr = null;
try { try {
serverAddr = InetAddress.getByName(ip_address); serverAddr = InetAddress.getByName(ip_address);
@ -98,7 +122,7 @@ public class TcpUAVTalk {
} }
connected = true; connected = true;
try { try {
uavTalk = new UAVTalk(socket.getInputStream(), socket.getOutputStream(), objMngr); uavTalk = new UAVTalk(socket.getInputStream(), socket.getOutputStream(), objMngr);
} catch (IOException e) { } catch (IOException e) {
@ -107,7 +131,7 @@ public class TcpUAVTalk {
//e.printStackTrace(); //e.printStackTrace();
return false; return false;
} }
return true; return true;
} }

View File

@ -1,3 +1,25 @@
/**
******************************************************************************
* @file TelemetryWidget.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A widget that shows the status of telemetry.
* @see The GNU Public License (GPL) Version 3
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
@ -8,7 +30,7 @@ import android.content.Intent;
import android.widget.RemoteViews; import android.widget.RemoteViews;
public class TelemetryWidget extends AppWidgetProvider { public class TelemetryWidget extends AppWidgetProvider {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(OPTelemetryService.INTENT_ACTION_CONNECTED)) { if(intent.getAction().equals(OPTelemetryService.INTENT_ACTION_CONNECTED)) {
@ -16,11 +38,11 @@ public class TelemetryWidget extends AppWidgetProvider {
} }
if(intent.getAction().equals(OPTelemetryService.INTENT_ACTION_DISCONNECTED)) { if(intent.getAction().equals(OPTelemetryService.INTENT_ACTION_DISCONNECTED)) {
changeStatus(context, false); changeStatus(context, false);
} }
super.onReceive(context, intent); super.onReceive(context, intent);
} }
public void changeStatus(Context context, boolean status) { public void changeStatus(Context context, boolean status) {
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.telemetry_widget); RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.telemetry_widget);
updateViews.setTextViewText(R.id.telemetryWidgetStatus, "Connection status: " + status); updateViews.setTextViewText(R.id.telemetryWidgetStatus, "Connection status: " + status);
@ -30,6 +52,7 @@ public class TelemetryWidget extends AppWidgetProvider {
} }
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length; final int N = appWidgetIds.length;
@ -44,6 +67,6 @@ public class TelemetryWidget extends AppWidgetProvider {
appWidgetManager.updateAppWidget(appWidgetId, views); appWidgetManager.updateAppWidget(appWidgetId, views);
} }
} }
} }

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file UAVLocation.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Display the UAV location on google maps
* @see The GNU Public License (GPL) Version 3
*****************************************************************************/
/*
* 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; either version 3 of the License, or
* (at your option) any later version.
*
* 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 org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.util.List; import java.util.List;
@ -10,14 +33,6 @@ import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectManager; import org.openpilot.uavtalk.UAVObjectManager;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import com.google.android.maps.MyLocationOverlay;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@ -36,14 +51,22 @@ import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
public class UAVLocation extends MapActivity import com.google.android.maps.GeoPoint;
{ import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
public class UAVLocation extends MapActivity
{
private final String TAG = "UAVLocation"; private final String TAG = "UAVLocation";
private static int LOGLEVEL = 0; private static int LOGLEVEL = 0;
// private static boolean WARN = LOGLEVEL > 1; // private static boolean WARN = LOGLEVEL > 1;
private static boolean DEBUG = LOGLEVEL > 0; private static boolean DEBUG = LOGLEVEL > 0;
private MapView mapView; private MapView mapView;
private MapController mapController; private MapController mapController;
UAVObjectManager objMngr; UAVObjectManager objMngr;
@ -55,28 +78,28 @@ public class UAVLocation extends MapActivity
GeoPoint uavLocation; GeoPoint uavLocation;
@Override public void onCreate(Bundle icicle) { @Override public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
setContentView(R.layout.map_layout); setContentView(R.layout.map_layout);
mapView = (MapView)findViewById(R.id.map_view); mapView = (MapView)findViewById(R.id.map_view);
mapController = mapView.getController(); mapController = mapView.getController();
mapView.displayZoomControls(true); mapView.displayZoomControls(true);
Double lat = 37.422006*1E6; Double lat = 37.422006*1E6;
Double lng = -122.084095*1E6; Double lng = -122.084095*1E6;
homeLocation = new GeoPoint(lat.intValue(), lng.intValue()); homeLocation = new GeoPoint(lat.intValue(), lng.intValue());
uavLocation = homeLocation; uavLocation = homeLocation;
mapController.setCenter(homeLocation); mapController.setCenter(homeLocation);
mapController.setZoom(18); mapController.setZoom(18);
List<Overlay> overlays = mapView.getOverlays(); List<Overlay> overlays = mapView.getOverlays();
UAVOverlay myOverlay = new UAVOverlay(); UAVOverlay myOverlay = new UAVOverlay();
overlays.add(myOverlay); overlays.add(myOverlay);
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView); MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
myLocationOverlay.enableMyLocation(); myLocationOverlay.enableMyLocation();
myLocationOverlay.enableCompass(); myLocationOverlay.enableCompass();
overlays.add(myLocationOverlay); overlays.add(myLocationOverlay);
mapView.postInvalidate(); mapView.postInvalidate();
// ObjectManager related stuff (can't inherit standard class) // ObjectManager related stuff (can't inherit standard class)
@ -86,7 +109,7 @@ public class UAVLocation extends MapActivity
Log.d(TAG, "Received intent"); Log.d(TAG, "Received intent");
TelemTask task; TelemTask task;
if(intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_CONNECTED) == 0) { if(intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_CONNECTED) == 0) {
if(binder == null) if(binder == null)
return; return;
if((task = binder.getTelemTask(0)) == null) if((task = binder.getTelemTask(0)) == null)
@ -101,9 +124,9 @@ public class UAVLocation extends MapActivity
onOPDisconnected(); onOPDisconnected();
Log.d(TAG, "Disonnected()"); Log.d(TAG, "Disonnected()");
} }
} }
}; };
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addCategory(OPTelemetryService.INTENT_CATEGORY_GCS); filter.addCategory(OPTelemetryService.INTENT_CATEGORY_GCS);
filter.addAction(OPTelemetryService.INTENT_ACTION_CONNECTED); filter.addAction(OPTelemetryService.INTENT_ACTION_CONNECTED);
@ -111,103 +134,108 @@ public class UAVLocation extends MapActivity
registerReceiver(connectedReceiver, filter); registerReceiver(connectedReceiver, filter);
} }
//@Override //@Override
@Override
protected boolean isRouteDisplayed() { protected boolean isRouteDisplayed() {
// IMPORTANT: This method must return true if your Activity // is displaying driving directions. Otherwise return false. // IMPORTANT: This method must return true if your Activity // is displaying driving directions. Otherwise return false.
return false; return false;
} }
public class UAVOverlay extends Overlay { public class UAVOverlay extends Overlay {
Bitmap homeSymbol = BitmapFactory.decodeResource(getResources(), R.drawable.ic_home); Bitmap homeSymbol = BitmapFactory.decodeResource(getResources(), R.drawable.ic_home);
Bitmap uavSymbol = BitmapFactory.decodeResource(getResources(), R.drawable.ic_uav); Bitmap uavSymbol = BitmapFactory.decodeResource(getResources(), R.drawable.ic_uav);
@Override @Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) { public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Projection projection = mapView.getProjection(); Projection projection = mapView.getProjection();
if (shadow == false) { if (shadow == false) {
Point myPoint = new Point(); Point myPoint = new Point();
projection.toPixels(uavLocation, myPoint); projection.toPixels(uavLocation, myPoint);
//// Draw UAV //// Draw UAV
// Create and setup your paint brush // Create and setup your paint brush
Paint paint = new Paint(); Paint paint = new Paint();
paint.setARGB(250, 255, 0, 0); paint.setARGB(250, 255, 0, 0);
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setFakeBoldText(true); paint.setFakeBoldText(true);
// Draw on the canvas // Draw on the canvas
canvas.drawBitmap(uavSymbol, myPoint.x - uavSymbol.getWidth() / 2, canvas.drawBitmap(uavSymbol, myPoint.x - uavSymbol.getWidth() / 2,
myPoint.y - uavSymbol.getHeight() / 2, paint); myPoint.y - uavSymbol.getHeight() / 2, paint);
canvas.drawText("UAV", myPoint.x+uavSymbol.getWidth() / 2, myPoint.y, paint); canvas.drawText("UAV", myPoint.x+uavSymbol.getWidth() / 2, myPoint.y, paint);
//// Draw Home //// Draw Home
myPoint = new Point(); myPoint = new Point();
projection.toPixels(homeLocation, myPoint); projection.toPixels(homeLocation, myPoint);
// Create and setup your paint brush // Create and setup your paint brush
paint.setARGB(250, 0, 0, 0); paint.setARGB(250, 0, 0, 0);
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setFakeBoldText(true); paint.setFakeBoldText(true);
canvas.drawBitmap(homeSymbol, myPoint.x - homeSymbol.getWidth() / 2,
myPoint.y - homeSymbol.getHeight() / 2, paint);
canvas.drawText("Home", myPoint.x+homeSymbol.getWidth(), myPoint.y, paint);
} canvas.drawBitmap(homeSymbol, myPoint.x - homeSymbol.getWidth() / 2,
myPoint.y - homeSymbol.getHeight() / 2, paint);
canvas.drawText("Home", myPoint.x+homeSymbol.getWidth(), myPoint.y, paint);
}
} }
@Override @Override
public boolean onTap(GeoPoint point, MapView mapView1) { public boolean onTap(GeoPoint point, MapView mapView1) {
// Return true if screen tap is handled by this overlay // Return true if screen tap is handled by this overlay
return false; return false;
} }
} }
void onOPConnected() { void onOPConnected() {
UAVObject obj = objMngr.getObject("HomeLocation"); UAVObject obj = objMngr.getObject("HomeLocation");
if(obj != null) if(obj != null)
obj.addUpdatedObserver(new Observer() { obj.addUpdatedObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
UAVDataObject obj = (UAVDataObject) data; UAVDataObject obj = (UAVDataObject) data;
Double lat = obj.getField("Latitude").getDouble() / 10; Double lat = obj.getField("Latitude").getDouble() / 10;
Double lon = obj.getField("Longitude").getDouble() / 10; Double lon = obj.getField("Longitude").getDouble() / 10;
homeLocation = new GeoPoint(lat.intValue(), lon.intValue()); homeLocation = new GeoPoint(lat.intValue(), lon.intValue());
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override
public void run() { public void run() {
mapController.setCenter(homeLocation); mapController.setCenter(homeLocation);
} }
}); });
System.out.println("HomeLocation: " + homeLocation.toString()); System.out.println("HomeLocation: " + homeLocation.toString());
} }
}); });
obj.updateRequested(); obj.updateRequested();
obj = objMngr.getObject("PositionActual"); obj = objMngr.getObject("PositionActual");
if(obj != null) if(obj != null)
obj.addUpdatedObserver(new Observer() { obj.addUpdatedObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
uavLocation = getUavLocation(); uavLocation = getUavLocation();
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override
public void run() { public void run() {
mapView.invalidate(); mapView.invalidate();
} }
}); });
} }
}); });
} }
private GeoPoint getUavLocation() { private GeoPoint getUavLocation() {
UAVObject pos = (UAVObject) objMngr.getObject("PositionActual"); UAVObject pos = objMngr.getObject("PositionActual");
if (pos == null) if (pos == null)
return new GeoPoint(0,0); return new GeoPoint(0,0);
UAVObject home = (UAVObject) objMngr.getObject("HomeLocation"); UAVObject home = objMngr.getObject("HomeLocation");
if (home == null) if (home == null)
return new GeoPoint(0,0); return new GeoPoint(0,0);
double lat, lon, alt; double lat, lon, alt;
lat = home.getField("Latitude").getDouble() / 10.0e6; lat = home.getField("Latitude").getDouble() / 10.0e6;
lon = home.getField("Longitude").getDouble() / 10.0e6; lon = home.getField("Longitude").getDouble() / 10.0e6;
@ -217,23 +245,23 @@ public class UAVLocation extends MapActivity
double T0, T1; double T0, T1;
T0 = alt+6.378137E6; T0 = alt+6.378137E6;
T1 = Math.cos(lat * Math.PI / 180.0)*(alt+6.378137E6); T1 = Math.cos(lat * Math.PI / 180.0)*(alt+6.378137E6);
// Get the NED coordinates // Get the NED coordinates
double NED0, NED1; double NED0, NED1;
NED0 = pos.getField("North").getDouble(); NED0 = pos.getField("North").getDouble();
NED1 = pos.getField("East").getDouble(); NED1 = pos.getField("East").getDouble();
// Compute the LLA coordinates // Compute the LLA coordinates
lat = lat + (NED0 / T0) * 180.0 / Math.PI; lat = lat + (NED0 / T0) * 180.0 / Math.PI;
lon = lon + (NED1 / T1) * 180.0 / Math.PI; lon = lon + (NED1 / T1) * 180.0 / Math.PI;
return new GeoPoint((int) (lat * 1e6), (int) (lon * 1e6)); return new GeoPoint((int) (lat * 1e6), (int) (lon * 1e6));
} }
void onOPDisconnected() { void onOPDisconnected() {
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) { switch(item.getItemId()) {
@ -265,15 +293,16 @@ public class UAVLocation extends MapActivity
Intent intent = new Intent(this, OPTelemetryService.class); Intent intent = new Intent(this, OPTelemetryService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE); bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
} }
public void onBind() { public void onBind() {
} }
/** Defines callbacks for service binding, passed to bindService() */ /** Defines callbacks for service binding, passed to bindService() */
private ServiceConnection mConnection = new ServiceConnection() { private final ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName arg0, IBinder service) { public void onServiceConnected(ComponentName arg0, IBinder service) {
// We've bound to LocalService, cast the IBinder and attempt to open a connection // We've bound to LocalService, cast the IBinder and attempt to open a connection
if (DEBUG) Log.d(TAG,"Service bound"); if (DEBUG) Log.d(TAG,"Service bound");
mBound = true; mBound = true;
binder = (LocalBinder) service; binder = (LocalBinder) service;
@ -285,10 +314,11 @@ public class UAVLocation extends MapActivity
mConnected = true; mConnected = true;
onOPConnected(); onOPConnected();
} }
} }
} }
@Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
mBound = false; mBound = false;
binder = null; binder = null;