def auto_mavlink_version(self, buf):
        '''auto-switch mavlink protocol version'''
        global mavlink
        if len(buf) == 0:
            return
        try:
            magic = ord(buf[0])
        except:
            magic = buf[0]
        if not magic in [ 85, 254, 253 ]:
            return
        self.first_byte = False
        if self.WIRE_PROTOCOL_VERSION == "0.9" and magic == 254:
            self.WIRE_PROTOCOL_VERSION = "1.0"
            set_dialect(current_dialect)
        elif self.WIRE_PROTOCOL_VERSION == "1.0" and magic == 85:
            self.WIRE_PROTOCOL_VERSION = "0.9"
            os.environ['MAVLINK09'] = '1'
            set_dialect(current_dialect)
        elif self.WIRE_PROTOCOL_VERSION != "2.0" and magic == 253:
            self.WIRE_PROTOCOL_VERSION = "2.0"
            os.environ['MAVLINK20'] = '1'
            set_dialect(current_dialect)
        else:
            return
        # switch protocol 
        (callback, callback_args, callback_kwargs) = (self.mav.callback,
                                                      self.mav.callback_args,
                                                      self.mav.callback_kwargs)
        self.mav = mavlink.MAVLink(self, srcSystem=self.source_system)
        self.mav.robust_parsing = self.robust_parsing
        self.WIRE_PROTOCOL_VERSION = mavlink.WIRE_PROTOCOL_VERSION
        (self.mav.callback, self.mav.callback_args, self.mav.callback_kwargs) = (callback,
                                                                                 callback_args,
                                                                                 callback_kwargs)
def auto_mavlink_version ( self , buf ) : global mavlink if len ( buf ) == 0 : return try : magic = ord ( buf [ 0 ] ) except : magic = buf [ 0 ] if not magic in [ 85 , 254 , 253 ] : return self . first_byte = False if self . WIRE_PROTOCOL_VERSION == "0.9" and magic == 254 : self . WIRE_PROTOCOL_VERSION = "1.0" set_dialect ( current_dialect ) elif self . WIRE_PROTOCOL_VERSION == "1.0" and magic == 85 : self . WIRE_PROTOCOL_VERSION = "0.9" os . environ [ 'MAVLINK09' ] = '1' set_dialect ( current_dialect ) elif self . WIRE_PROTOCOL_VERSION != "2.0" and magic == 253 : self . WIRE_PROTOCOL_VERSION = "2.0" os . environ [ 'MAVLINK20' ] = '1' set_dialect ( current_dialect ) else : return ( callback , callback_args , callback_kwargs ) = ( self . mav . callback , self . mav . callback_args , self . mav . callback_kwargs ) self . mav = mavlink . MAVLink ( self , srcSystem = self . source_system ) self . mav . robust_parsing = self . robust_parsing self . WIRE_PROTOCOL_VERSION = mavlink . WIRE_PROTOCOL_VERSION ( self . mav . callback , self . mav . callback_args , self . mav . callback_kwargs ) = ( callback , callback_args , callback_kwargs )
auto-switch mavlink protocol version