So been fiddling around with the command BaseStream with mission planner script cabability with a simulated copter inside mission planner. What I want to succed with is to write a python script that is able to read all messages seperatelly and trigger phyton code based on the data that comes in.
Not been able to test BaseStream.write but I’m guessing it sends whatever data you specify to or from the drone.
What I’m having issues with is that sometimes I will use BaseStream.read and get some data that is not following the correct format. I was guessing that I might need to wait for a heartbeat or some kind of timing to know when to read and that I will just read garbage if I read when the drone might not send any data.
This is the script that I made based on some of the example scripts that came with Mission planner. I’m very new in python so qritique would be nice <3 . This code will with no hesitation create a big array with 1001 bytes (as I cannot find any data on how big these blocks(?) that .read will read) and populate it with whatever BaseStream.read will give out. I then print out the messages inside this data dump as I belive the format should look like. Start with 253 for MAVLink V.2 and then the lenght of the payload +11 bytes for non payload data. It seems to be able to isolate most messages, but sometimes I get messages that do not start with 253 or 254 (MAVLink V.1/V.2). Would also be nice to know if I’m getting all messages through this method or if this might miss a ton of them. This code should work on a new copy of Mission Planner.
import clr import MissionPlanner clr.AddReference("MAVLink") import time from System import Byte from System import Array import MAVLink fail = 0 while 1 == 1: index = 0 amount = 0 a=Array[Byte]([0x00]*(1000+1)) time.sleep(.5) MAV.BaseStream.Read(a,0,1000) print '\n' while a[index] != 0: print a[index:index+a+12] index = index+a[index+1]+12