MMRL, Issue to retrieve data after LOGGING SensorFusion data

Hey Mbientlab-Team,

i tried to log SensorFusion data to the sensor memory and later download it. I strongly oriented myself based on the source code of the MetaBase App but I am stuck since a while and i cant see whats different, especially since the MetaBase source code was not easy to understand. Below is my Kotlin code splitted into two segments, the logging part and the download part.

The main issue is that I am not able to get data using this r.subscribe { data, env -> ... } callback, but I am able to see the progress with nEntriesLeft, and totalEntries on downloadAsync

Here is the logging functionality:

fun logging(){
        var task = Task.forResult(null)

        task = task.onSuccessTask { _ ->
            Log.e(tag, "Start connect")
            return@onSuccessTask mwBoard.connectAsync()
        }.onSuccessTask { _ ->
            val editor: Settings.BleConnectionParametersEditor? = mwBoard.getModule(Settings::class.java).editBleConnParams()
            if(editor != null){
                Log.e(tag, "Editor")
                editor.maxConnectionInterval(11.25f)
                    .commit()
                return@onSuccessTask Task.delay(1000L)
            }
            return@onSuccessTask Task.forResult(null)
        }.onSuccessTask { _ ->
            Log.e(tag, "Connected")
            mwBoard.getModule(SensorFusionBosch::class.java).configure()
                .accRange(SensorFusionBosch.AccRange.AR_16G)
                .gyroRange(SensorFusionBosch.GyroRange.GR_2000DPS)
                .mode(SensorFusionBosch.Mode.IMU_PLUS)
                .commit()
            mwBoard.getModule(SensorFusionBosch::class.java).quaternion()
                .addRouteAsync { source ->
                    source.log(null)
                }
            return@onSuccessTask Task.forResult(null)
        }

        task.continueWithTask { task2 ->
            if (task2.isFaulted){
                Log.e(tag, "Faulted")
                return@continueWithTask null
            }else {
                Log.e(tag, "Start logging")
                mwBoard.getModule(Logging::class.java).start(false)
                mwBoard.getModule(SensorFusionBosch::class.java).start()
                return@continueWithTask mwBoard.getModule(Debug::class.java).disconnectAsync()
            }
        }.onSuccess {
            Log.e(tag, "Done")
        }
    }

Here is the code for retrieving the logging data:

fun download(){
        var task = Task.forResult(null)
        var route: AnonymousRoute? = null

        task = task.onSuccessTask { ignored ->
            Log.e(tag, "Start connect")
            mwBoard.connectAsync()
        }.onSuccessTask { ignored ->
            if (ignored.isCompleted){
                Log.e(tag, "Connected")
            }
            mwBoard.getModule(Logging::class.java).stop()
            mwBoard.getModule(Logging::class.java).flushPage()
            return@onSuccessTask mwBoard.createAnonymousRoutesAsync()
        }.onSuccessTask { anonymousTask ->
            for(r in anonymousTask.result){
                route = r
                break
            }
            return@onSuccessTask mwBoard.getModule(Debug::class.java).disconnectAsync()
        }.continueWithTask { initTask ->
            return@continueWithTask Task.forResult(null)
        }

        task.onSuccessTask { ignored ->
            Log.e(tag, "Start connect")
            route?.let { r ->
                Log.e(tag, "Create route subscriber")
                r.subscribe { data, env ->
                    Log.e(tag, "Here is the data")
            // This subscribe call back is not working.                     
                }
            }
            return@onSuccessTask mwBoard.connectAsync()
        }.onSuccessTask { ignored2 ->
            if(ignored2.isCompleted){
                Log.e(tag, "Connected")
            }
            return@onSuccessTask mwBoard.getModule(Logging::class.java).downloadAsync(100){ nEntriesLeft, totalEntries ->
                Log.e(tag, "$nEntriesLeft, $totalEntries")
            }
        }.onSuccessTask { dlTask ->
            if(dlTask.isCompleted){
                Log.e(tag, "Download completed")
            }
            return@onSuccessTask mwBoard.getModule(Debug::class.java).disconnectAsync()
        }.onSuccess {
            Log.e(tag, "Disconnect success")
        }
    }

Sorry for this long code post. I hope someone has the time to look at it, would really appreciate your help :)

Thanks so much!
Toffy

Comments

  • @toffy_dee I haven't worked with kotlin but it looks very close compared to the MetaBase log download code. I would use the interactive debugger and poke around near the r.subscribe and the route = r lines to make sure the right objects are getting stored and registered. If you are getting notifications then the readout process is working, but the handler just has not seemed to register.

Sign In or Register to comment.