Go to the documentation of this file.00001
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
00019 f = fifo()
00020
00021
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
00031 mav.param_set_send(7, 1, "WP_RADIUS", 101, mavlink.MAV_PARAM_TYPE_REAL32)
00032
00033
00034
00035 m = mav.param_set_encode(7, 1, "WP_RADIUS", 101, mavlink.MAV_PARAM_TYPE_REAL32)
00036
00037 m.pack(mav)
00038
00039
00040 b = m.get_msgbuf()
00041
00042 bi=[]
00043 for c in b:
00044 bi.append(int(c))
00045 print(bi)
00046
00047
00048 m2 = mav.decode(b)
00049
00050
00051 print("Got a message with id %u and fields %s" % (m2.get_msgId(), m2.get_fieldnames()))
00052
00053
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)