1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Get rid of lots of warnings

This commit is contained in:
James Cotton 2011-03-19 20:01:01 -05:00
parent 515a4c4fd1
commit 6505507230
7 changed files with 194 additions and 129 deletions

View File

@ -2,6 +2,7 @@ package org.openpilot.androidgcs;
import org.openpilot.uavtalk.Telemetry; import org.openpilot.uavtalk.Telemetry;
import org.openpilot.uavtalk.TelemetryMonitor; import org.openpilot.uavtalk.TelemetryMonitor;
import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObjectManager; import org.openpilot.uavtalk.UAVObjectManager;
import org.openpilot.uavtalk.UAVTalk; import org.openpilot.uavtalk.UAVTalk;
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize; import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
@ -13,69 +14,192 @@ import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Binder;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
public class OPTelemetryService extends Service { public class OPTelemetryService extends Service {
// Logging settings
private final String TAG = "OPTElemetryService"; private final String TAG = "OPTElemetryService";
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;
final int DISCONNECT_MESSAGE = 0; // Intent category
final int CONNECT_MESSAGE = 1; public final static String INTENT_CATEGORY_GCS = "org.openpilot.intent.category.GCS";
final int CONNECT_FAILED_MESSAGE = 2;
private UAVObjectManager objMngr;
private UAVTalk uavTalk;
private Telemetry tel;
private TelemetryMonitor mon;
private Handler handler;
@Override // Intent actions
public IBinder onBind(Intent arg0) { public final static String INTENT_ACTION_CONNECTED = "org.openpilot.intent.action.CONNECTED";
return null; public final static String INTENT_ACTION_DISCONNECTED = "org.openpilot.intent.action.DISCONNECTED";
}
// Variables for local message handler thread
private Looper mServiceLooper;
private ServiceHandler mServiceHandler;
// Message ids
final int MSG_START = 0;
final int MSG_CONNECT_BT = 1;
final int MSG_CONNECT_FAKE = 2;
final int MSG_TOAST = 100;
private Thread activeTelem;
private final IBinder mBinder = new LocalBinder();
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
switch(msg.arg1) {
case MSG_START:
Toast.makeText(OPTelemetryService.this, "HERE", Toast.LENGTH_SHORT);
System.out.println("HERE");
stopSelf(msg.arg2);
case MSG_CONNECT_BT:
activeTelem = new BTTelemetryThread();
activeTelem.start();
break;
case MSG_CONNECT_FAKE:
activeTelem = new FakeTelemetryThread();
activeTelem.start();
break;
case MSG_TOAST:
Toast.makeText(OPTelemetryService.this, (String) msg.obj, Toast.LENGTH_SHORT);
break;
default:
System.out.println(msg.toString());
throw new Error("Invalid message");
}
}
};
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); // Low priority thread for message handling with service
HandlerThread thread = new HandlerThread("TelemetryServiceHandler",
if (DEBUG) Log.d(TAG, "Telemetry Service started"); Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
Thread telemetryThread = new Thread(telemetryRunnable); // Get the HandlerThread's Looper and use it for our Handler
telemetryThread.start(); mServiceLooper = thread.getLooper();
} mServiceHandler = new ServiceHandler(mServiceLooper);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Telemetry service starting", Toast.LENGTH_SHORT).show();
System.out.println("Start");
// For each start request, send a message to start a job and deliver the
// start ID so we know which request we're stopping when we finish the job
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = MSG_START;
msg.arg2 = startId;
mServiceHandler.sendMessage(msg);
// If we get killed, after returning from here, restart
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); Toast.makeText(this, "Telemetry service done", Toast.LENGTH_SHORT).show();
} }
public class LocalBinder extends Binder {
public TelemTask getTelemTask(int id) {
return (TelemTask) activeTelem;
}
public void openFakeConnection() {
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = MSG_CONNECT_FAKE;
mServiceHandler.sendMessage(msg);
}
};
private final Runnable telemetryRunnable = new Runnable() { public void toastMessage(String msgText) {
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = MSG_TOAST;
msg.obj = msgText;
mServiceHandler.sendMessage(msg);
}
public interface TelemTask {
public UAVObjectManager getObjectManager();
};
// Fake class for testing, simply emits periodic updates on
private class FakeTelemetryThread extends Thread implements TelemTask {
private UAVObjectManager objMngr;
public UAVObjectManager getObjectManager() { return objMngr; };
FakeTelemetryThread() {
objMngr = new UAVObjectManager();
UAVObjectsInitialize.register(objMngr);
}
public void run() {
System.out.println("Runnin fake thread");
Intent intent = new Intent();
intent.setAction(INTENT_ACTION_CONNECTED);
sendBroadcast(intent,null);
//toastMessage("Started fake telemetry thread");
UAVDataObject systemStats = (UAVDataObject) objMngr.getObject("SystemStats");
while(true) {
systemStats.updated();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
}
}
}
private class BTTelemetryThread extends Thread implements TelemTask {
private UAVObjectManager objMngr;
private UAVTalk uavTalk;
private Telemetry tel;
//private TelemetryMonitor mon;
public UAVObjectManager getObjectManager() { return objMngr; };
BTTelemetryThread() {
objMngr = new UAVObjectManager();
UAVObjectsInitialize.register(objMngr);
}
public void run() { public void run() {
if (DEBUG) Log.d(TAG, "Telemetry Thread started"); if (DEBUG) Log.d(TAG, "Telemetry Thread started");
Looper.prepare(); Looper.prepare();
objMngr = new UAVObjectManager();
UAVObjectsInitialize.register(objMngr);
postNotification(CONNECT_FAILED_MESSAGE, "Connecting");
BluetoothUAVTalk bt = new BluetoothUAVTalk(OPTelemetryService.this, BluetoothUAVTalk.DEVICE_NAME); BluetoothUAVTalk bt = new BluetoothUAVTalk(OPTelemetryService.this, BluetoothUAVTalk.DEVICE_NAME);
for( int i = 0; i < 10; i++ ) { for( int i = 0; i < 10; i++ ) {
if (DEBUG) Log.d(TAG, "Attempting Bluetooth Connection"); if (DEBUG) Log.d(TAG, "Attempting Bluetooth Connection");
bt.connect(objMngr); bt.connect(objMngr);
if (DEBUG) Log.d(TAG, "Done attempting connection"); if (DEBUG) Log.d(TAG, "Done attempting connection");
if( bt.getConnected() ) if( bt.getConnected() )
break; break;
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -85,17 +209,15 @@ public class OPTelemetryService extends Service {
} }
} }
if( ! bt.getConnected() ) { if( ! bt.getConnected() ) {
postNotification(CONNECT_FAILED_MESSAGE, "Could not connect to UAV");
return; return;
} }
postNotification(CONNECT_MESSAGE, "Connected to UAV port");
if (DEBUG) Log.d(TAG, "Connected via bluetooth"); if (DEBUG) Log.d(TAG, "Connected via bluetooth");
uavTalk = bt.getUavtalk(); uavTalk = bt.getUavtalk();
tel = new Telemetry(uavTalk, objMngr); tel = new Telemetry(uavTalk, objMngr);
mon = new TelemetryMonitor(objMngr,tel); new TelemetryMonitor(objMngr,tel);
if (DEBUG) Log.d(TAG, "Entering UAVTalk processing loop"); if (DEBUG) Log.d(TAG, "Entering UAVTalk processing loop");
while(true) { while(true) {
@ -103,30 +225,23 @@ public class OPTelemetryService extends Service {
break; break;
} }
if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected"); if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected");
postNotification(DISCONNECT_MESSAGE,"UAVTalk stream disconnected");
} }
}; };
void postNotification(int id, String message) { void postNotification(int id, String message) {
String ns = Context.NOTIFICATION_SERVICE; String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNManager = (NotificationManager) getSystemService(ns); NotificationManager mNManager = (NotificationManager) getSystemService(ns);
final Notification msg = new Notification(R.drawable.icon, message, System.currentTimeMillis()); final Notification msg = new Notification(R.drawable.icon, message, System.currentTimeMillis());
Context context = getApplicationContext(); Context context = getApplicationContext();
CharSequence contentTitle = "OpenPilot"; CharSequence contentTitle = "OpenPilot";
CharSequence contentText = message; CharSequence contentText = message;
Intent msgIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://forums.openpilot.org")); Intent msgIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://forums.openpilot.org"));
PendingIntent intent = PendingIntent.getActivity(this, 0, msgIntent, Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent intent = PendingIntent.getActivity(this, 0, msgIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
msg.setLatestEventInfo(context, contentTitle, contentText, intent); msg.setLatestEventInfo(context, contentTitle, contentText, intent);
mNManager.notify(id, msg); mNManager.notify(id, msg);
} }
public UAVObjectManager getObjMngr() { return objMngr; };
public UAVTalk getUavTalk() { return uavTalk; };
public Telemetry getTelemetry() { return tel; };
public TelemetryMonitor getTelemetryMonitor() { return mon; };
} }

View File

@ -1,42 +1,21 @@
package org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.io.IOException;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import java.util.Set;
import java.util.UUID;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
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.ToggleButton; import android.widget.ToggleButton;
import org.openpilot.androidgcs.*;
import org.openpilot.uavtalk.Telemetry;
import org.openpilot.uavtalk.TelemetryMonitor;
import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectManager;
import org.openpilot.uavtalk.UAVTalk;
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
public class ObjectBrowser extends Activity { public class ObjectBrowser extends ObjectManagerActivity {
private final String TAG = "ObjectBrower"; private final String TAG = "ObjectBrower";
private final String DEVICE_NAME = "RN42-222D";
private final int REQUEST_ENABLE_BT = 0;
private UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
BluetoothAdapter mBluetoothAdapter;
BluetoothSocket socket;
boolean connected; boolean connected;
UAVObjectManager objMngr;
UAVTalk uavTalk;
final Handler uavobjHandler = new Handler(); final Handler uavobjHandler = new Handler();
final Runnable updateText = new Runnable() { final Runnable updateText = new Runnable() {
public void run() { public void run() {
@ -44,9 +23,9 @@ public class ObjectBrowser extends Activity {
button.setChecked(!connected); button.setChecked(!connected);
Log.d(TAG,"HERE" + connected); Log.d(TAG,"HERE" + connected);
TextView text = (TextView) findViewById(R.id.textView1); TextView text = (TextView) findViewById(R.id.textView1);
UAVObject obj1 = objMngr.getObject("SystemStats"); UAVObject obj1 = objMngr.getObject("SystemStats");
UAVObject obj2 = objMngr.getObject("AttitudeRaw"); UAVObject obj2 = objMngr.getObject("AttitudeRaw");
UAVObject obj3 = objMngr.getObject("AttitudeActual"); UAVObject obj3 = objMngr.getObject("AttitudeActual");
@ -57,52 +36,30 @@ public class ObjectBrowser extends Activity {
Log.d(TAG,"And here"); Log.d(TAG,"And here");
text.setText(obj1.toString() + "\n" + obj2.toString() + "\n" + obj3.toString() + "\n" + obj4.toString() ); text.setText(obj1.toString() + "\n" + obj2.toString() + "\n" + obj3.toString() + "\n" + obj4.toString() );
} }
}; };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(TAG, "Launching Object Browser");
Log.d(TAG, "Start OP Telemetry Service"); /** Called when the activity is first created. */
startService( new Intent( this, OPTelemetryService.class ) ); @Override
public void onCreate(Bundle savedInstanceState) {
objMngr = new UAVObjectManager(); super.onCreate(savedInstanceState);
UAVObjectsInitialize.register(objMngr); setContentView(R.layout.main);
}
@Override
void onOPConnected() {
// Toast.makeText(this,"Telemetry estabilished",Toast.LENGTH_SHORT);
Log.d(TAG, "onOPConnected()");
UAVObject obj = objMngr.getObject("SystemStats"); UAVObject obj = objMngr.getObject("SystemStats");
Log.d(TAG, ((Boolean) (obj == null)).toString());
if(obj != null) if(obj != null)
obj.addUpdatedObserver(new Observer() { obj.addUpdatedObserver(new Observer() {
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
uavobjHandler.post(updateText); uavobjHandler.post(updateText);
} }
}); });
obj = objMngr.getObject("AttitudeRaw");
if(obj != null) }
obj.addUpdatedObserver(new Observer() {
public void update(Observable observable, Object data) {
uavobjHandler.post(updateText);
}
});
obj = objMngr.getObject("AttitudeActual");
if(obj != null)
obj.addUpdatedObserver(new Observer() {
public void update(Observable observable, Object data) {
uavobjHandler.post(updateText);
}
});
obj = objMngr.getObject("SystemAlarms");
if(obj != null)
obj.addUpdatedObserver(new Observer() {
public void update(Observable observable, Object data) {
uavobjHandler.post(updateText);
}
});
}
} }

View File

@ -3,14 +3,10 @@ package org.openpilot.androidgcs;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider; import android.appwidget.AppWidgetProvider;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RemoteViews; import android.widget.RemoteViews;
public class TelemetryWidget extends AppWidgetProvider { public class TelemetryWidget extends AppWidgetProvider {
private static boolean connected = false;
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;

View File

@ -630,7 +630,6 @@ public class Telemetry {
/** /**
* Private variables * Private variables
*/ */
private TelemetryStats stats;
private UAVObjectManager objMngr; private UAVObjectManager objMngr;
private UAVTalk utalk; private UAVTalk utalk;
private UAVObject gcsStatsObj; private UAVObject gcsStatsObj;

View File

@ -8,9 +8,6 @@ import java.util.Observer;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import org.openpilot.uavtalk.uavobjects.FlightTelemetryStats;
import org.openpilot.uavtalk.uavobjects.GCSTelemetryStats;
import android.util.Log; import android.util.Log;
public class TelemetryMonitor { public class TelemetryMonitor {
@ -26,7 +23,7 @@ public class TelemetryMonitor {
private UAVObjectManager objMngr; private UAVObjectManager objMngr;
private Telemetry tel; private Telemetry tel;
private UAVObject objPending; // private UAVObject objPending;
private UAVObject gcsStatsObj; private UAVObject gcsStatsObj;
private UAVObject flightStatsObj; private UAVObject flightStatsObj;
private Timer periodicTask; private Timer periodicTask;
@ -38,7 +35,7 @@ public class TelemetryMonitor {
{ {
this.objMngr = objMngr; this.objMngr = objMngr;
this.tel = tel; this.tel = tel;
this.objPending = null; // this.objPending = null;
queue = new ArrayList<UAVObject>(); queue = new ArrayList<UAVObject>();
// Get stats objects // Get stats objects
@ -142,7 +139,7 @@ public class TelemetryMonitor {
// Request update // Request update
tel.updateRequested(obj); tel.updateRequested(obj);
objPending = obj; // objPending = obj;
} }
/** /**
@ -155,7 +152,7 @@ public class TelemetryMonitor {
if (DEBUG) Log.d(TAG,"transactionCompleted. Status: " + success); if (DEBUG) Log.d(TAG,"transactionCompleted. Status: " + success);
// TODO: Need to be able to disconnect signals // TODO: Need to be able to disconnect signals
//obj->disconnect(this); //obj->disconnect(this);
objPending = null; // objPending = null;
if(!success) { if(!success) {
Log.e(TAG, "Transaction failed: " + obj.getName() + " sending again."); Log.e(TAG, "Transaction failed: " + obj.getName() + " sending again.");

View File

@ -64,7 +64,7 @@ public abstract class UAVObject {
if(manually) if(manually)
updatedManual(); updatedManual();
} }
void updated() { updated(true); }; public void updated() { updated(true); };
private CallbackListener unpackedListeners = new CallbackListener(this); private CallbackListener unpackedListeners = new CallbackListener(this);
public void addUnpackedObserver(Observer o) { public void addUnpackedObserver(Observer o) {

View File

@ -1,6 +1,5 @@
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
import java.io.Serializable;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
@ -91,7 +90,8 @@ public class UAVObjectField {
* @param dataOut * @param dataOut
* @return the number of bytes added * @return the number of bytes added
**/ **/
public synchronized int pack(ByteBuffer dataOut) { @SuppressWarnings("unchecked")
public synchronized int pack(ByteBuffer dataOut) {
// Pack each element in output buffer // Pack each element in output buffer
dataOut.order(ByteOrder.LITTLE_ENDIAN); dataOut.order(ByteOrder.LITTLE_ENDIAN);
switch (type) switch (type)
@ -152,7 +152,8 @@ public class UAVObjectField {
return getNumBytes(); return getNumBytes();
} }
public synchronized int unpack(ByteBuffer dataIn) { @SuppressWarnings("unchecked")
public synchronized int unpack(ByteBuffer dataIn) {
// Unpack each element from input buffer // Unpack each element from input buffer
dataIn.order(ByteOrder.LITTLE_ENDIAN); dataIn.order(ByteOrder.LITTLE_ENDIAN);
switch (type) switch (type)
@ -436,9 +437,9 @@ public class UAVObjectField {
} }
} }
public String toString() { public String toString() {
String sout = new String(); String sout = new String();
sout += name + ": " + ((List) data).toString() + " (" + units + ")\n"; sout += name + ": " + data.toString() + " (" + units + ")\n";
return sout; return sout;
} }