Skip to content

mavlinkDirect: subscribe to several mavlink messages simultaneously #228

@Podrosboy

Description

@Podrosboy

How do I subscribe to several mavlink messages simultaneously if these messages are from custom xml?

I subscribe to the "OBSTACLE_DISTANCE" command and one custom command. If I subscribe to only one command, both work fine, but if I subscribe to both at the same time, only the first one works, and the subsequent one starts arriving simultaneously and doesn't transmit data.

drone.mavlinkDirect.getMessage("AGRO_TANK_STATUS")
    .subscribe({ mavlinkMessageAgroTankStatus ->
        val deserialized: AgroTankStatus =
            jsonAgroTankStatus.decodeFromString<AgroTankStatus>(
                mavlinkMessageAgroTankStatus.fieldsJson
            )
        println("AgroTankStatus: weight - ${deserialized.weight}")
    }, { error ->
        Log.e("MAVLink", "AgroTankStatus error", error)
    })


drone.mavlinkDirect.getMessage("OBSTACLE_DISTANCE")
    .subscribe { mavlinkMessage ->
        val deserialized: ObstacleDistance =
            jsonObstacleDistance.decodeFromString<ObstacleDistance>(
                mavlinkMessage.fieldsJson
            )
        println(
            "ObstacleDistance: distances - ${
                deserialized.distances.joinToString(
                    separator = ", "
                )
            }"
        )
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions