Mavlink from a server socket / How to encode a mavlink message without active transport?

514 views
Skip to first unread message

Gerard Toonstra

unread,
Feb 17, 2015, 10:39:41 PM2/17/15
to mav...@googlegroups.com

Hi all,

In my case I use a bound socket / server connection to listen for GCS connections and then stream mavlink messages over that as soon as a client connects.

I'd like to send a couple of extra messages in the message flow, but I'm having some problems figuring out how I can successfully pack them up and send them over
the wire. So, if I receive an AP mavlink message and send the get_msgbuf() content over the wire directly, it works. When I construct my own packets, the
GCS complains about incorrect CRC's and header ID's.

The mavutil mavlink_connection function has no methods to allow a listening socket to be constructed and used for this use case.


What I use now is a fake inactive connection, which gives problems for the GCS based on incorrect CRC's and headers, python code:

        self.master = mavutil.mavlink_connection( "udp:127.0.0.1:12345" )
        msg = self.master.mav.heartbeat_encode( find_uav_type( hb.uavtype ), find_ap_type( hb.autopilot ), hb.base_mode, hb.custom_mode, hb.system_status )
        self.conn.send( msg.get_msgbuf() )

So, what is the procedure to only construct a correct message and hold it in a buffer somewhere, where custom code manages the transport?
( i.e. no code ending in *send, but which uses the *encode type of functions and then grabs the buffer? )

Or would it just be easier to add a tcplisten: kind of transport device to the mavutil code, write a small wrapper class similar to "mavtcp" and use that
instead?

Rgds,

Gerard

Gerard Toonstra

unread,
Feb 18, 2015, 10:53:19 AM2/18/15
to mav...@googlegroups.com

My real problem was that non-mavlink messages were received and could not be decoded.

What I eventually ended up doing is something like this (to simulate a vehicle):

        self.master = mavutil.mavlink_connection( "udp:127.0.0.1:12345", source_system=1 )
        self.master.mav = mavutil.mavlink.MAVLink(self.master, srcSystem=self.master.source_system, srcComponent=1)
        update_seq( self.master.mav.seq )
        msg = self.master.mav.heartbeat_encode( uavtype, autopilot_type, base_mode, custom_mode, system_status )
        conn.send( msg.get_msgbuf() )

Ligia Frangello

unread,
Feb 8, 2018, 1:13:02 PM2/8/18
to MAVLink
Hi Gerald, 

I am trying to simulate a vehicle on GCS over UDP/TCP, and send Mavlink messages, and it sounds like you are working on the same problem. 

Would you mind sharing what you have learned with me?

Thank you.
Reply all
Reply to author
Forward
0 new messages