mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +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;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.openpilot.uavtalk.UAVObject;
|
||||
import org.openpilot.uavtalk.UAVTalk;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
@ -23,7 +23,8 @@ public class Logger extends ObjectManagerActivity {
|
||||
|
||||
private File file;
|
||||
private boolean logging;
|
||||
private BufferedWriter out;
|
||||
private FileOutputStream fileStream;
|
||||
private UAVTalk uavTalk;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
@ -38,14 +39,14 @@ public class Logger extends ObjectManagerActivity {
|
||||
|
||||
Date d = new Date();
|
||||
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);
|
||||
if (DEBUG) Log.d(TAG, "Trying for file: " + file.getAbsolutePath());
|
||||
try {
|
||||
if (root.canWrite()){
|
||||
FileWriter filewriter = new FileWriter(file);
|
||||
out = new BufferedWriter(filewriter);
|
||||
fileStream = new FileOutputStream(file);
|
||||
uavTalk = new UAVTalk(null, fileStream, objMngr);
|
||||
logging = true;
|
||||
} else {
|
||||
Log.e(TAG, "Unwriteable address");
|
||||
@ -61,7 +62,7 @@ public class Logger extends ObjectManagerActivity {
|
||||
if (DEBUG) Log.d(TAG, "Stop logging");
|
||||
logging = false;
|
||||
try {
|
||||
out.close();
|
||||
fileStream.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -102,7 +103,23 @@ public class Logger extends ObjectManagerActivity {
|
||||
if (logging) {
|
||||
if (VERBOSE) Log.v(TAG,"Updated: " + obj.toString());
|
||||
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) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user