1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-30 15:52:12 +01:00

AndroidGCS: Add a telemetry monitor to the action bar that shows the TX/RX data

rate.  Right now seem to have a bug when going into the same widget twice it
crashes teh second time.
This commit is contained in:
James Cotton 2012-08-06 08:32:07 -05:00
parent a47cec644f
commit 5cd670ef49
8 changed files with 122 additions and 32 deletions

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/searchProgressWrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/telemetry_stats_rx_rate_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rxrate" />
<TextView
android:id="@+id/telemetry_stats_rx_rate"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/telemetry_stats_tx_rate_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txrate" />
<TextView
android:id="@+id/telemetry_stats_tx_rate"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>

View File

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menuItemProgress"
android:title="Progress"
android:actionLayout="@layout/telemetry_stats"
android:showAsAction="always" />
</menu> </menu>

View File

@ -30,4 +30,6 @@
<string name="number_of_objects">Number of objects</string> <string name="number_of_objects">Number of objects</string>
<string name="number_of_bytes">Number of bytes</string> <string name="number_of_bytes">Number of bytes</string>
<string name="alarms">Alarms</string> <string name="alarms">Alarms</string>
<string name="txrate">TxRate: </string>
<string name="rxrate">RxRate: </string>
</resources> </resources>

View File

@ -66,8 +66,8 @@ public class Controller extends ObjectManagerActivity {
@Override @Override
void onOPConnected() { void onOPConnected() {
Log.d(TAG, "onOPConnected()"); super.onOPConnected();
// Subscribe to updates from ManualControlCommand and show the values for crude feedback // Subscribe to updates from ManualControlCommand and show the values for crude feedback
UAVDataObject manualControl = (UAVDataObject) objMngr.getObject("ManualControlCommand"); UAVDataObject manualControl = (UAVDataObject) objMngr.getObject("ManualControlCommand");
if(manualControl != null) { if(manualControl != null) {

View File

@ -77,6 +77,8 @@ public class Logger extends ObjectManagerActivity {
@Override @Override
void onOPConnected() { void onOPConnected() {
super.onOPConnected();
if (DEBUG) Log.d(TAG, "onOPConnected()"); if (DEBUG) Log.d(TAG, "onOPConnected()");
onStartLogging(); onStartLogging();
registerObjectUpdates(objMngr.getObjects()); registerObjectUpdates(objMngr.getObjects());

View File

@ -53,14 +53,15 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
/** 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);
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);
} }
@Override @Override
void onOPConnected() { void onOPConnected() {
super.onOPConnected();
Log.d(TAG, "onOPConnected()"); Log.d(TAG, "onOPConnected()");
OnCheckedChangeListener checkListener = new OnCheckedChangeListener() { OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {

View File

@ -24,6 +24,7 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.TextView;
public abstract class ObjectManagerActivity extends Activity { public abstract class ObjectManagerActivity extends Activity {
@ -42,7 +43,9 @@ public abstract class ObjectManagerActivity extends Activity {
LocalBinder binder; LocalBinder binder;
//! Store the broadcast receiver to unregister it //! Store the broadcast receiver to unregister it
BroadcastReceiver connectedReceiver; BroadcastReceiver connectedReceiver;
//! Indicate if this activity has already connected it's telemetry callbacks
private boolean telemetryStatsConnected = false;
/** 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) {
@ -118,19 +121,60 @@ public abstract class ObjectManagerActivity extends Activity {
} }
} }
private void updateStats() {
UAVObject stats = objMngr.getObject("GCSTelemetryStats");
TextView rxRate = (TextView) findViewById(R.id.telemetry_stats_rx_rate);
TextView txRate = (TextView) findViewById(R.id.telemetry_stats_tx_rate);
if (rxRate != null)
rxRate.setText(Integer.valueOf((int) stats.getField("RxDataRate").getDouble()).toString());
if (rxRate != null)
txRate.setText(Integer.valueOf((int) stats.getField("TxDataRate").getDouble()).toString());
}
final Observer telemetryObserver = new Observer() {
public void update(Observable observable, Object data) {
uavobjHandler.post(new Runnable() {
@Override
public void run() {
updateStats();
}
});
}
};
/** /**
* Called when either the telemetry establishes a connection or * Called when either the telemetry establishes a connection or
* if it already has on creation of this activity * if it already has on creation of this activity
*
* This should be called by all inherited classes if they want the telemetry bar etc
*/ */
void onOPConnected() { void onOPConnected() {
if ( telemetryStatsConnected )
return;
// We are not using the objectUpdated mechanism in place so that all the children
// don't have to sort through the messages.
UAVObject stats = objMngr.getObject("GCSTelemetryStats");
if (stats == null)
return;
stats.addUpdatedObserver(telemetryObserver);
telemetryStatsConnected = true;
updateStats();
} }
/** /**
* Called when telemetry drops the connection * Called when telemetry drops the connection
*
* This should be called by all inherited classes if they want the telemetry bar etc
*/ */
void onOPDisconnected() { void onOPDisconnected() {
// Indicate no connection
TextView rxRate = (TextView) findViewById(R.id.telemetry_stats_rx_rate);
TextView txRate = (TextView) findViewById(R.id.telemetry_stats_tx_rate);
rxRate.setText("");
txRate.setText("");
} }
@Override @Override
@ -154,6 +198,7 @@ public abstract class ObjectManagerActivity extends Activity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.status_menu, menu);
inflater.inflate(R.menu.options_menu, menu); inflater.inflate(R.menu.options_menu, menu);
return true; return true;
} }

View File

@ -1,31 +1,42 @@
package org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.util.Observable;
import java.util.Observer;
import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVObject;
import android.os.Bundle; import android.os.Bundle;
public class PFD extends ObjectManagerActivity { public class PFD extends ObjectManagerActivity {
final long MIN_UPDATE_PERIOD = 50;
long lastUpdateMs;
double heading; double heading;
double roll; double roll;
double pitch; double pitch;
Runnable update = new Runnable() { /**
public void run() { * Update the UI whenever the attitude is updated
CompassView compass = (CompassView) findViewById(R.id.compass_view); */
compass.setBearing((int) heading); protected void objectUpdated(UAVObject obj) {
compass.invalidate(); // Throttle the UI redraws. Eventually this should maybe come from a periodic task
if ((System.currentTimeMillis() - lastUpdateMs) < MIN_UPDATE_PERIOD)
return;
if (obj.getName().compareTo("AttitudeActual") != 0)
return;
AttitudeView attitude = (AttitudeView) findViewById(R.id.attitude_view); lastUpdateMs = System.currentTimeMillis();
attitude.setRoll(roll / 180 * Math.PI);
attitude.setPitch(pitch / 180 * Math.PI); heading = obj.getField("Yaw").getDouble();
attitude.invalidate(); pitch = obj.getField("Pitch").getDouble();
} roll = obj.getField("Roll").getDouble();
};
CompassView compass = (CompassView) findViewById(R.id.compass_view);
compass.setBearing((int) heading);
compass.invalidate();
AttitudeView attitude = (AttitudeView) findViewById(R.id.attitude_view);
attitude.setRoll(roll / 180 * Math.PI);
attitude.setPitch(pitch / 180 * Math.PI);
attitude.invalidate();
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -35,17 +46,11 @@ public class PFD extends ObjectManagerActivity {
@Override @Override
void onOPConnected() { void onOPConnected() {
super.onOPConnected();
// Connect the update method to AttitudeActual
UAVObject obj = objMngr.getObject("AttitudeActual"); UAVObject obj = objMngr.getObject("AttitudeActual");
if(obj != null) if (obj != null)
obj.addUpdatedObserver(new Observer() { registerObjectUpdates(obj);
public void update(Observable observable, Object data) {
UAVDataObject obj = (UAVDataObject) data;
heading = obj.getField("Yaw").getDouble();
pitch = obj.getField("Pitch").getDouble();
roll = obj.getField("Roll").getDouble();
runOnUiThread(update);
}
});
} }
} }