mavtest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys, os
00004 
00005 from pymavlink.dialects.v10 import ardupilotmega as mavlink1
00006 from pymavlink.dialects.v20 import ardupilotmega as mavlink2
00007 
00008 class fifo(object):
00009     def __init__(self):
00010         self.buf = []
00011     def write(self, data):
00012         self.buf += data
00013         return len(data)
00014     def read(self):
00015         return self.buf.pop(0)
00016 
00017 def test_protocol(mavlink, signing=False):
00018     # we will use a fifo as an encode/decode buffer
00019     f = fifo()
00020 
00021     # create a mavlink instance, which will do IO on file object 'f'
00022     mav = mavlink.MAVLink(f)
00023 
00024     if signing:
00025         mav.signing.secret_key = chr(42)*32
00026         mav.signing.link_id = 0
00027         mav.signing.timestamp = 0
00028         mav.sign_messages = True
00029 
00030     # set the WP_RADIUS parameter on the MAV at the end of the link
00031     mav.param_set_send(7, 1, "WP_RADIUS", 101, mavlink.MAV_PARAM_TYPE_REAL32)
00032 
00033     # alternatively, produce a MAVLink_param_set object 
00034     # this can be sent via your own transport if you like
00035     m = mav.param_set_encode(7, 1, "WP_RADIUS", 101, mavlink.MAV_PARAM_TYPE_REAL32)
00036 
00037     m.pack(mav)
00038 
00039     # get the encoded message as a buffer
00040     b = m.get_msgbuf()
00041 
00042     bi=[]
00043     for c in b:
00044         bi.append(int(c))
00045     print(bi)
00046 
00047     # decode an incoming message
00048     m2 = mav.decode(b)
00049 
00050     # show what fields it has
00051     print("Got a message with id %u and fields %s" % (m2.get_msgId(), m2.get_fieldnames()))
00052 
00053     # print out the fields
00054     print(m2)
00055 
00056 
00057 print("Testing mavlink1")
00058 test_protocol(mavlink1)
00059 
00060 print("Testing mavlink2")
00061 test_protocol(mavlink2)
00062 
00063 print("Testing mavlink2 with signing")
00064 test_protocol(mavlink2, True)


mavlink
Author(s): Lorenz Meier
autogenerated on Thu Jun 6 2019 19:01:57