mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-03 11:24:10 +01:00
AndroidGCS: Write logging in the format consistent with how we record on the
ground station and can parse from matlab.
This commit is contained in:
parent
11a27cd593
commit
9d2830b75f
@ -1,13 +1,13 @@
|
|||||||
package org.openpilot.androidgcs;
|
package org.openpilot.androidgcs;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.openpilot.uavtalk.UAVObject;
|
import org.openpilot.uavtalk.UAVObject;
|
||||||
|
import org.openpilot.uavtalk.UAVTalk;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@ -23,7 +23,8 @@ public class Logger extends ObjectManagerActivity {
|
|||||||
|
|
||||||
private File file;
|
private File file;
|
||||||
private boolean logging;
|
private boolean logging;
|
||||||
private BufferedWriter out;
|
private FileOutputStream fileStream;
|
||||||
|
private UAVTalk uavTalk;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
@ -38,14 +39,14 @@ public class Logger extends ObjectManagerActivity {
|
|||||||
|
|
||||||
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 + ".uav";
|
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 {
|
||||||
if (root.canWrite()){
|
if (root.canWrite()){
|
||||||
FileWriter filewriter = new FileWriter(file);
|
fileStream = new FileOutputStream(file);
|
||||||
out = new BufferedWriter(filewriter);
|
uavTalk = new UAVTalk(null, fileStream, objMngr);
|
||||||
logging = true;
|
logging = true;
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Unwriteable address");
|
Log.e(TAG, "Unwriteable address");
|
||||||
@ -61,7 +62,7 @@ public class Logger extends ObjectManagerActivity {
|
|||||||
if (DEBUG) Log.d(TAG, "Stop logging");
|
if (DEBUG) Log.d(TAG, "Stop logging");
|
||||||
logging = false;
|
logging = false;
|
||||||
try {
|
try {
|
||||||
out.close();
|
fileStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -102,7 +103,23 @@ public class Logger extends ObjectManagerActivity {
|
|||||||
if (logging) {
|
if (logging) {
|
||||||
if (VERBOSE) Log.v(TAG,"Updated: " + obj.toString());
|
if (VERBOSE) Log.v(TAG,"Updated: " + obj.toString());
|
||||||
try {
|
try {
|
||||||
out.write(obj + "\n");
|
long time = System.currentTimeMillis();
|
||||||
|
fileStream.write((byte)(time & 0xff));
|
||||||
|
fileStream.write((byte)((time & 0x0000ff00) >> 8));
|
||||||
|
fileStream.write((byte)((time & 0x00ff0000) >> 16));
|
||||||
|
fileStream.write((byte)((time & 0xff000000) >> 24));
|
||||||
|
|
||||||
|
long size = obj.getNumBytes();
|
||||||
|
fileStream.write((byte)(size & 0x00000000000000ffl) >> 0);
|
||||||
|
fileStream.write((byte)(size & 0x000000000000ff00l) >> 8);
|
||||||
|
fileStream.write((byte)(size & 0x0000000000ff0000l) >> 16);
|
||||||
|
fileStream.write((byte)(size & 0x00000000ff000000l) >> 24);
|
||||||
|
fileStream.write((byte)(size & 0x000000ff00000000l) >> 32);
|
||||||
|
fileStream.write((byte)(size & 0x0000ff0000000000l) >> 40);
|
||||||
|
fileStream.write((byte)(size & 0x00ff000000000000l) >> 48);
|
||||||
|
fileStream.write((byte)(size & 0xff00000000000000l) >> 56);
|
||||||
|
|
||||||
|
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();
|
||||||
|
Loading…
Reference in New Issue
Block a user