Logging Acceleration Offline (n00b question)

2»

Comments

  • You can serialize the board's internal state and store it to your device's filesystem.  When you restart your app, you can restore the board's state.

  • edited August 2015
    Hum, so on Disconect I must serialize the board. And it works with your Inner class ? 
    <pre>

    ArrayList<Message> messages  = new ArrayList<Message>();
    ...
    mma8452qModule.routeData().fromOrientation().log("orientation_log").commit().onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
        @Override
        public void success(RouteManager result) {
            result.setLogMessageHandler("orientation_log", new RouteManager.MessageHandler() {
                @Override
                public void process(final Message message) {
                    messages.add(message);
                }
            });
        }
    });
    </pre>
    In this sample the messages ArrayList is wrong. I didn't think serialisation could do that, I'll try
  • edited August 2015
    ///< When you serialize
    mma8452qModule.routeData().fromOrientation().log("orientation_log").commit()
        .onComplete(new CompletionHandler<RouteManager>() {
            @Override
            public void success(RouteManager result) {
                ///< save this somewhere on your device e.g. sharedpreferences or a text file
                byte[] state= mwBoard.serializeState();
                
                ///< save this on the device
                int orientationManagerId= result.id();
            }
        });


    -----------
    ///< When you deserialize
    byte[] state= ...;  ///< Read from text file / shared preferences
    int orientationManagerId= ...; ///< Read from text file / shared preferences

    mwBoard.deserializeState(state);

    RouteManager orientationManager= mwBoard.getRouteManager(orientationManagerId);
    orientationManager.setLogMessageHandler("orientation_log", new RouteManager.MessageHandler() {
            @Override
            public void process(final Message message) {
                messages.add(message);
            }
        });
    });
  • edited August 2015

  • edited August 2015
    Hi,

    I do something like this:

    String mac =  board.getMacAddress();
    SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    String serial = sharedPref.getString(mac, null);
    board.deserializeState(Base64.decode(serial, Base64.DEFAULT));
    switchId      = sharedPref.getInt(mac+"_switch",0);
    RouteManager mgr = board.getRouteManager(switchId);
    if (mgr!= null) mgr.setLogMessageHandler("switch_log", new WHMessageHandler("Switch"));

    The serialisation works because I retrieve all Ids (switch, orientation, ...) but mgr  is null. I serialize with Base64 encoder ? I'm missing something ?
    And so when I download logs I have unknow logs with id corresponding to stored Id
  • Ok so I added a button to explicitly serialize the board and it seems to work.

    My understanding:

    mma8452qModule.routeData().fromOrientation().log("orientation_log").commit().onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    orientationId = result.id();
    result.setLogMessageHandler("orientation_log", new WHMessageHandler("Orientation"));
    }
    });
    The orientationId is set asynchronously so I have to "wait" to serialize the board (because I do not only work orientation but 4 other states)
  • Okkayyyy on method description of serializeState() you should explain the byte[] is a JSON and it's legal to do new String(serial). I understand that watching the exemple code.

    In you exemple you do it onComplete() but if we have multiple sensor I assume it could be done for each onComplete().
  • A little Bug ?

    Here is the latest version of my fragment:

    You can see on click I call setup() that will plug a logger on each "sensor": motion, tap, shake, switch, orientation. I stream and I log.

    The very very weird thing is each time I start not all logger are setup. I do not understand why. Is it because of AsyncOperation ?
    - Each sensor is setup async
    - I call mma8452qModule.start(); very "quickly"

    Can it break something ?

  • edited August 2015
    The point of returning a byte array is so the user doesn't know anything about the internal formatting.  If someday, a more compact serialization format is needed, it does not affect the user as all they see is a byte array rather than expecting a formatted string (JSON, XML, English characters, etc.).  Creating a string from the byte array simply gives you a "nice" way to look at the bytes rather than look at hex values.

    It is possible you are starting the accelerometer before the other components are enabled.  Once the accelerometer is in active mode, all configurations are ignored.  Routes are added in order they are committed so you can have the last async operation start the accelerometer.

    You can combine the log and stream calls in one route.
  • I don't understand the question, when you process logging values you have a Message object and you just have to call message.getTimestamp() 
  • => Previous Message: Wrong thread

    - Update to Android 3.0.0 OK
    - Update firmware to 1.0.4 OK
    - Update my own code OK

    Thanks !
This discussion has been closed.