Downloading logs
I'm trying to use the new Route Manager, but am having difficulty figuring out exactly how to download the log. I am trying to just get the data from the X axis on the Accelerometer for now. I looked at the new API and Sample app, but it only seems to have Streaming functionality.
Is there any kind of quick sample code available for properly setting up and downloading offline logging with the new methods?
I've got this so far for starting the process:
Is there any kind of quick sample code available for properly setting up and downloading offline logging with the new methods?
I've got this so far for starting the process:
AsyncOperation<RouteManager> routeManagerResult= accelModule.routeData().fromXAxis().log("accel_log").commit();
routeManagerResult.onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
accelModule.enableAxisSampling();
accelModule.start();
logModule.startLogging(true); // Starts logging data overwrite is true
}
});
This discussion has been closed.
Comments
connectButton.setOnClickListener(new View.OnClickListener() {
@OverrideaccelerometerMe(); //Didn't include all code here but it calls this to start
public void onServiceConnected(ComponentName name, IBinder service) {
///< Get a reference to the MetaWear service from the binder
mwService = (MetaWearBleService.LocalBinder) service;
final BluetoothManager btManager =
(BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
if (deviceAddress != null) {
final BluetoothDevice btDevice = btManager.getAdapter().getRemoteDevice(deviceAddress);
this.mwBoard = mwService.getMetaWearBoard(btDevice);
this.mwBoard.setConnectionStateHandler(new MetaWearBoard.ConnectionStateHandler() {
@Override
public void connected() {
try {
logModule = mwBoard.getModule(Logging.class);
accelModule = mwBoard.getModule(Accelerometer.class);
setupAccelerometer(); //Sets range & data rate
//getReadings();
} catch (UnsupportedModuleException e) {
e.printStackTrace();
}
}
@Override
public void disconnected() {
Log.i(TAG, "Disconnected");
}
});
mwBoard.connect();
}
}
public void accelerometerMe() {
accelModule.routeData().fromAxes().log("accelLogger").commit()
.onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) { //How do you invoke or trigger this??
result.setLogMessageHandler("accelLogger", new RouteManager.MessageHandler() {
@Override
public void process(Message msg) {
axisData = msg.getData(float.class);
Log.i("test", String.format("Log: %.1f", axisData));
}
});
}
@Override
public void failure(Throwable error) {
Log.e("test", "Error committing route", error);
//accelSetup = false;
}
});
if (isFirstRun) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setButtonStateConnected();
}
});
}
logModule.startLogging();
accelModule.enableAxisSampling();
accelModule.start();
downloadHandler.postDelayed(downloadLogs, pauseTime);
}
private final Runnable downloadLogs= new Runnable() {
@Override
public void run() {
Log.i("AccList1 Size", String.valueOf(accList1.size()));
// Stop Logging
logModule.stopLogging();
logModule.downloadLog(0.1f, new Logging.DownloadHandler() {
@Override
public void onProgressUpdate(int nEntriesLeft, int totalEntries) {
if (nEntriesLeft == 0) {
Log.i(TAG, "Log download complete");
}
}
});
accList1.add(axisData); //THIS IS WHERE I WANT TO FILL THE ARRAYLIST
isFirstRun = false;
counter = 0;
accelerometerMe(); //INTENTION IS TO LOOP AROUND AND GET MORE DATA EVERY FEW SECONDS
}
};
I had all this working with the previous API. I am trying to convert my working code over to the new API.
I was going off this for the message type for single axis:
Three axis data can be interpreted as a CartesianFloat (G's) or a CartesianShort (milli G's) whereas single axis data can be interpreted as a float (G) or short/integer/long (milli G).
1.) I did do that and was able to get the streaming to start and stop. I then converted it to logging and I can get the logging to start and stop and download, but I can't get the downloadLog call to invoke public void success(RouteManager result). Stop, Start and Downloading the log all work.
2.) I had all that working with streaming and then logging and then tried to put it in the loop. The loop works to start, stop and download the log but never processes data. I do get a log message that the download is complete.
Again, thank you guys for your patience and helping me with this. My client is looking at 200 units/yr on this project.
private final Runnable downloadLog= new Runnable() {
@Override
public void run() {
logModule.downloadLog(0.1f, new Logging.DownloadHandler() {
@Override
public void onProgressUpdate(int nEntriesLeft, int totalEntries) {
Log.i("test", String.format("Progress: %d/%d/", nEntriesLeft, totalEntries));
if (nEntriesLeft == 0) {
Log.i("test", "Log download completed");
downloadHandler.post(downloadLog);
}
}
@Override
public void receivedUnknownLogEntry(byte logId, Calendar timestamp, byte[] data) {
Log.i("test", String.format("Unknown log entry: {id: %d, data: %s}", logId, Arrays.toString(data)));
}
});
}
};
One question with the new API - do I still need to stop the logger and/or acc modules to download the log? In the previous API we had to stop both, download the logs, then start them back up again.
I add the receivedUnknownLogEntry method and here are the last few entries of the results:
09-04 03:36:42.634 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 3, data: [-28, -1, 0, 0]}
09-04 03:36:42.634 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 4, data: [27, -4, -8, -1]}
09-04 03:36:42.634 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 5, data: [-28, -1, 0, 0]}
09-04 03:36:42.634 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 6, data: [27, -4, -8, -1]}
09-04 03:36:42.644 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 7, data: [-28, -1, 0, 0]}
09-04 03:36:42.644 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 0, data: [27, -4, 0, 0]}
09-04 03:36:42.644 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 1, data: [-36, -1, 0, 0]}
09-04 03:36:42.644 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 2, data: [27, -4, 0, 0]}
09-04 03:36:42.644 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 3, data: [-36, -1, 0, 0]}
09-04 03:36:42.654 31722-31869/com.project.name I/test﹕ Unknown log entry: {id: 4, data: [27, -4, 0, 0]}
09-04 03:36:42.654 31722-31869/com.project.name I/test﹕ Progress: 0/13056/
09-04 03:36:42.654 31722-31869/com.project.name I/test﹕ Log download completed
I only get this on the first run through the loop. Then I only get this:
Skipped 4719 frames! The application may be doing too much work on its main thread.
on subsequent loops.
It still never goes through the route manager to process. I also tried changing the delay time from 3 seconds to 100 ms and I still got 13056 records from receivedUnknownLogEntry.
private void accelerometerMe() {
if (!isStoppedPress){
//accelModule.start(); //Not sure if stopping and start is still needed
logModule.startLogging(); //Not sure if stopping and start is still needed
downloadHandler.postDelayed(downloadLog, pauseTime);
}
else{
logModule.stopLogging();
cleanUp();
setButtonStateDisconnected();
}
}
private final Runnable downloadLog= new Runnable() {
@Override
public void run() {
logModule.stopLogging();
//accelModule.stop();
logModule.downloadLog(0.1f, new Logging.DownloadHandler() {
@Override
public void onProgressUpdate(int nEntriesLeft, int totalEntries) {
Log.i("test", String.format("Progress: %d/%d/", nEntriesLeft, totalEntries));
if (nEntriesLeft == 0) {
Log.i("test", "Log download completed");
downloadHandler.post(downloadLog);
}
}
@Override
public void receivedUnknownLogEntry(byte logId, Calendar timestamp, byte[] data) {
Log.i("test", String.format("Unknown log entry: {id: %d, data: %s}", logId, Arrays.toString(data)));
}
});
accelerometerMe();
}
};
private final Handler downloadHandler= new Handler();
09-08 12:10:19.418 13043-13285/com.project.name I/test﹕ Progress: 751/5103/
09-08 12:10:19.588 13043-13285/com.project.name I/test﹕ Progress: 495/5103/
09-08 12:10:19.748 13043-13285/com.project.name I/test﹕ Progress: 239/5103/ (It just stops here)
private final Runnable dlLog= new Runnable() {
@Override
public void run() {
logModule.downloadLog(0.05f, new Logging.DownloadHandler() {
@Override
public void onProgressUpdate(int nEntriesLeft, int totalEntries) {
Log.i("test", String.format("Progress: %d/%d/", nEntriesLeft, totalEntries));
if (nEntriesLeft == 0) {
Log.i("dlLog", "Log download completed");
downloadHandler.post(dlLog);
}
}
@Override
public void receivedUnknownLogEntry(byte logId, Calendar timestamp, byte[] data) {
Log.i("test", String.format("Unknown log entry: {id: %d, data: %s}", logId, Arrays.toString(data)));
}
});
}
};
...several good downloads then...
09-08 14:28:56.788 6635-6887/com.project.name I/dlLog? Log download completed
09-08 14:28:56.788 6635-6887/com.project.name I/VibrationMeterFragment? accList1 size: 536
09-08 14:28:59.648 6635-6887/com.project.name I/test? Progress: 132/146/
09-08 14:28:59.688 6635-6887/com.project.name I/test? Progress: 118/146/
09-08 14:28:59.748 6635-6887/com.project.name I/test? Progress: 103/146/
09-08 14:28:59.818 6635-6887/com.project.name I/test? Progress: 89/146/
09-08 14:28:59.878 6635-6887/com.project.name I/test? Progress: 75/146/
09-08 14:28:59.908 6635-6887/com.project.name I/test? Progress: 61/146/
09-08 14:28:59.928 6635-6887/com.project.name I/test? Progress: 47/146/
09-08 14:28:59.948 6635-6887/com.project.name I/test? Progress: 33/146/
09-08 14:28:59.968 6635-6887/com.project.name I/test? Progress: 19/146/
09-08 14:28:59.988 6635-6887/com.project.name I/test? Progress: 5/146/
09-08 14:28:59.988 6635-6887/com.project.name I/test? Progress: 0/146/
09-08 14:28:59.988 6635-6887/com.project.name I/dlLog? Log download completed
09-08 14:28:59.998 6635-6887/com.project.name I/VibrationMeterFragment? accList1 size: 608
09-08 14:29:01.708 6635-6887/com.project.name I/test? Progress: 0/4/
09-08 14:29:01.708 6635-6887/com.project.name I/dlLog? Log download completed
09-08 14:29:01.708 6635-6887/com.project.name I/VibrationMeterFragment? accList1 size: 608
09-08 14:29:05.548 6635-6887/com.project.name I/test? Progress: 0/4/
09-08 14:29:05.548 6635-6887/com.project.name I/dlLog? Log download completed
09-08 14:29:05.548 6635-6887/com.project.name I/VibrationMeterFragment? accList1 size: 608
09-08 14:29:11.108 6635-6887/com.project.name I/test? Progress: 0/4/
09-08 14:29:11.108 6635-6887/com.project.name I/dlLog? Log download completed
09-08 14:29:11.108 6635-6887/com.project.name I/VibrationMeterFragment? accList1 size: 608
... it just keeps looping and never downloads more data