mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-19 09:54:15 +01:00
AndroidGCS: Get the logger writing a list of updated objects
This commit is contained in:
parent
f986a83ef6
commit
eb13db4126
@ -8,7 +8,8 @@
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application android:icon="@drawable/ic_logo" android:label="@string/app_name" android:theme="@android:style/Theme.Holo">
|
||||
<!-- for map overlay -->
|
||||
|
@ -1,10 +1,16 @@
|
||||
package org.openpilot.androidgcs;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.openpilot.uavtalk.UAVObject;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
@ -12,6 +18,13 @@ public class Logger extends ObjectManagerActivity {
|
||||
|
||||
final String TAG = "Logger";
|
||||
|
||||
final boolean VERBOSE = false;
|
||||
final boolean DEBUG = true;
|
||||
|
||||
private File file;
|
||||
private boolean logging;
|
||||
private BufferedWriter out;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@ -19,19 +32,81 @@ public class Logger extends ObjectManagerActivity {
|
||||
setContentView(R.layout.logger);
|
||||
}
|
||||
|
||||
private void onStartLogging() {
|
||||
|
||||
File root = Environment.getExternalStorageDirectory();
|
||||
|
||||
Date d = new Date();
|
||||
String date = (new SimpleDateFormat("yyyyMMdd_hhmmss")).format(d);
|
||||
String fileName = "/logs/logs_" + date + ".uav";
|
||||
|
||||
file = new File(root, fileName);
|
||||
if (DEBUG) Log.d(TAG, "Trying for file: " + file.getAbsolutePath());
|
||||
try {
|
||||
if (root.canWrite()){
|
||||
FileWriter filewriter = new FileWriter(file);
|
||||
out = new BufferedWriter(filewriter);
|
||||
logging = true;
|
||||
} else {
|
||||
Log.e(TAG, "Unwriteable address");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Could not write file " + e.getMessage());
|
||||
}
|
||||
|
||||
// TODO: if logging succeeded then retrieve all settings
|
||||
}
|
||||
|
||||
private void onStopLogging() {
|
||||
if (DEBUG) Log.d(TAG, "Stop logging");
|
||||
logging = false;
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void onOPConnected() {
|
||||
Log.d(TAG, "onOPConnected()");
|
||||
|
||||
List<List<UAVObject>> allObjects = objMngr.getObjects();
|
||||
registerObjectUpdates(allObjects);
|
||||
}
|
||||
|
||||
if (DEBUG) Log.d(TAG, "onOPConnected()");
|
||||
onStartLogging();
|
||||
registerObjectUpdates(objMngr.getObjects());
|
||||
}
|
||||
|
||||
@Override
|
||||
void onOPDisconnected() {
|
||||
if (DEBUG) Log.d(TAG, "onOPDisconnected()");
|
||||
onStopLogging();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
onStopLogging();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
onStartLogging();
|
||||
}
|
||||
/**
|
||||
* Called whenever any objects subscribed to via registerObjects
|
||||
*/
|
||||
@Override
|
||||
protected void objectUpdated(UAVObject obj) {
|
||||
Log.d(TAG,"Updated: " + obj.toString());
|
||||
if (logging) {
|
||||
if (VERBOSE) Log.v(TAG,"Updated: " + obj.toString());
|
||||
try {
|
||||
out.write(obj + "\n");
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,12 +165,16 @@ public abstract class ObjectManagerActivity extends Activity {
|
||||
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* When stopping disconnect form the service and the broadcast receiver
|
||||
*/
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
unbindService(mConnection);
|
||||
unregisterReceiver(connectedReceiver);
|
||||
}
|
||||
|
||||
public void onBind() {
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user