From 9d2830b75f5b34039e8f472696aa4af240fc3834 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Mon, 6 Aug 2012 04:47:29 -0500 Subject: [PATCH] AndroidGCS: Write logging in the format consistent with how we record on the ground station and can parse from matlab. --- .../src/org/openpilot/androidgcs/Logger.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/androidgcs/src/org/openpilot/androidgcs/Logger.java b/androidgcs/src/org/openpilot/androidgcs/Logger.java index 9f9a17dd0..323e28323 100644 --- a/androidgcs/src/org/openpilot/androidgcs/Logger.java +++ b/androidgcs/src/org/openpilot/androidgcs/Logger.java @@ -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();