idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
41,700
def on_load ( self , event ) : dlg = wx . FileDialog ( None , self . settings . get_title ( ) , '' , "" , '*.*' , wx . FD_OPEN ) if dlg . ShowModal ( ) == wx . ID_OK : self . settings . load ( dlg . GetPath ( ) ) for label in self . setting_map . keys ( ) : setting = self . setting_map [ label ] ctrl = self . controls [ label ] value = ctrl . GetValue ( ) if isinstance ( value , str ) or isinstance ( value , unicode ) : ctrl . SetValue ( str ( setting . value ) ) else : ctrl . SetValue ( setting . value )
called on load button
41,701
def add_text ( self , setting , width = 300 , height = 100 , multiline = False ) : tab = self . panel ( setting . tab ) if multiline : ctrl = wx . TextCtrl ( tab , - 1 , "" , size = ( width , height ) , style = wx . TE_MULTILINE | wx . TE_PROCESS_ENTER ) else : ctrl = wx . TextCtrl ( tab , - 1 , "" , size = ( width , - 1 ) ) self . _add_input ( setting , ctrl )
add a text input line
41,702
def add_choice ( self , setting , choices ) : tab = self . panel ( setting . tab ) default = setting . value if default is None : default = choices [ 0 ] ctrl = wx . ComboBox ( tab , - 1 , choices = choices , value = str ( default ) , style = wx . CB_DROPDOWN | wx . CB_READONLY | wx . CB_SORT ) self . _add_input ( setting , ctrl )
add a choice input line
41,703
def add_intspin ( self , setting ) : tab = self . panel ( setting . tab ) default = setting . value ( minv , maxv ) = setting . range ctrl = wx . SpinCtrl ( tab , - 1 , initial = default , min = minv , max = maxv ) self . _add_input ( setting , ctrl , value = default )
add a spin control
41,704
def add_floatspin ( self , setting ) : from wx . lib . agw . floatspin import FloatSpin tab = self . panel ( setting . tab ) default = setting . value ( minv , maxv ) = setting . range ctrl = FloatSpin ( tab , - 1 , value = default , min_val = minv , max_val = maxv , increment = setting . increment ) if setting . format is not None : ctrl . SetFormat ( setting . format ) if setting . digits is not None : ctrl . SetDigits ( setting . digits ) self . _add_input ( setting , ctrl , value = default )
add a floating point spin control
41,705
def draw_path ( self , gc , path , transform , rgbFace = None ) : nmax = rcParams [ 'agg.path.chunksize' ] npts = path . vertices . shape [ 0 ] if ( nmax > 100 and npts > nmax and path . should_simplify and rgbFace is None and gc . get_hatch ( ) is None ) : nch = np . ceil ( npts / float ( nmax ) ) chsize = int ( np . ceil ( npts / nch ) ) i0 = np . arange ( 0 , npts , chsize ) i1 = np . zeros_like ( i0 ) i1 [ : - 1 ] = i0 [ 1 : ] - 1 i1 [ - 1 ] = npts for ii0 , ii1 in zip ( i0 , i1 ) : v = path . vertices [ ii0 : ii1 , : ] c = path . codes if c is not None : c = c [ ii0 : ii1 ] c [ 0 ] = Path . MOVETO p = Path ( v , c ) self . _renderer . draw_path ( gc , p , transform , rgbFace ) else : self . _renderer . draw_path ( gc , path , transform , rgbFace )
Draw the path
41,706
def draw_mathtext ( self , gc , x , y , s , prop , angle ) : if __debug__ : verbose . report ( 'RendererAgg.draw_mathtext' , 'debug-annoying' ) ox , oy , width , height , descent , font_image , used_characters = self . mathtext_parser . parse ( s , self . dpi , prop ) xd = descent * np . sin ( np . deg2rad ( angle ) ) yd = descent * np . cos ( np . deg2rad ( angle ) ) x = np . round ( x + ox + xd ) y = np . round ( y - oy + yd ) self . _renderer . draw_text_image ( font_image , x , y + 1 , angle , gc )
Draw the math text using matplotlib . mathtext
41,707
def draw_text ( self , gc , x , y , s , prop , angle , ismath = False , mtext = None ) : if __debug__ : verbose . report ( 'RendererAgg.draw_text' , 'debug-annoying' ) if ismath : return self . draw_mathtext ( gc , x , y , s , prop , angle ) flags = get_hinting_flag ( ) font = self . _get_agg_font ( prop ) if font is None : return None if len ( s ) == 1 and ord ( s ) > 127 : font . load_char ( ord ( s ) , flags = flags ) else : font . set_text ( s , 0 , flags = flags ) font . draw_glyphs_to_bitmap ( antialiased = rcParams [ 'text.antialiased' ] ) d = font . get_descent ( ) / 64.0 xd = - d * np . sin ( np . deg2rad ( angle ) ) yd = d * np . cos ( np . deg2rad ( angle ) ) self . _renderer . draw_text_image ( font . get_image ( ) , np . round ( x - xd ) , np . round ( y + yd ) + 1 , angle , gc )
Render the text
41,708
def _get_agg_font ( self , prop ) : if __debug__ : verbose . report ( 'RendererAgg._get_agg_font' , 'debug-annoying' ) key = hash ( prop ) font = RendererAgg . _fontd . get ( key ) if font is None : fname = findfont ( prop ) font = RendererAgg . _fontd . get ( fname ) if font is None : font = FT2Font ( str ( fname ) , hinting_factor = rcParams [ 'text.hinting_factor' ] ) RendererAgg . _fontd [ fname ] = font RendererAgg . _fontd [ key ] = font font . clear ( ) size = prop . get_size_in_points ( ) font . set_size ( size , self . dpi ) return font
Get the font for text instance t cacheing for efficiency
41,709
def draw ( self ) : if __debug__ : verbose . report ( 'FigureCanvasAgg.draw' , 'debug-annoying' ) self . renderer = self . get_renderer ( cleared = True ) RendererAgg . lock . acquire ( ) try : self . figure . draw ( self . renderer ) finally : RendererAgg . lock . release ( )
Draw the figure using the renderer
41,710
def vehicle_type_string ( self , hb ) : if hb . type == mavutil . mavlink . MAV_TYPE_FIXED_WING : return 'Plane' if hb . type == mavutil . mavlink . MAV_TYPE_GROUND_ROVER : return 'Rover' if hb . type == mavutil . mavlink . MAV_TYPE_SURFACE_BOAT : return 'Boat' if hb . type == mavutil . mavlink . MAV_TYPE_SUBMARINE : return 'Sub' if hb . type in [ mavutil . mavlink . MAV_TYPE_QUADROTOR , mavutil . mavlink . MAV_TYPE_COAXIAL , mavutil . mavlink . MAV_TYPE_HEXAROTOR , mavutil . mavlink . MAV_TYPE_OCTOROTOR , mavutil . mavlink . MAV_TYPE_TRICOPTER , mavutil . mavlink . MAV_TYPE_DODECAROTOR ] : return "Copter" if hb . type == mavutil . mavlink . MAV_TYPE_HELICOPTER : return "Heli" if hb . type == mavutil . mavlink . MAV_TYPE_ANTENNA_TRACKER : return "Tracker" return "UNKNOWN(%u)" % hb . type
return vehicle type string from a heartbeat
41,711
def update_vehicle_menu ( self ) : self . vehicle_menu . items = [ ] for s in sorted ( self . vehicle_list ) : clist = self . module ( 'param' ) . get_component_id_list ( s ) if len ( clist ) == 1 : name = 'SysID %u: %s' % ( s , self . vehicle_name_by_sysid [ s ] ) self . vehicle_menu . items . append ( MPMenuItem ( name , name , '# vehicle %u' % s ) ) else : for c in sorted ( clist ) : try : name = 'SysID %u[%u]: %s' % ( s , c , self . component_name [ s ] [ c ] ) except KeyError as e : name = 'SysID %u[%u]: ?' % ( s , c ) self . vehicle_menu . items . append ( MPMenuItem ( name , name , '# vehicle %u:%u' % ( s , c ) ) ) self . mpstate . console . set_menu ( self . menu , self . menu_callback )
update menu for new vehicles
41,712
def add_new_vehicle ( self , hb ) : if hb . type == mavutil . mavlink . MAV_TYPE_GCS : return sysid = hb . get_srcSystem ( ) self . vehicle_list . append ( sysid ) self . vehicle_name_by_sysid [ sysid ] = self . vehicle_type_string ( hb ) self . update_vehicle_menu ( )
add a new vehicle
41,713
def say_espeak ( self , text , priority = 'important' ) : from espeak import espeak if self . settings . speech_voice : espeak . set_voice ( self . settings . speech_voice ) espeak . synth ( text )
speak some text using espeak
41,714
def cmd_long ( self , args ) : if len ( args ) < 1 : print ( "Usage: long <command> [arg1] [arg2]..." ) return command = None if args [ 0 ] . isdigit ( ) : command = int ( args [ 0 ] ) else : try : command = eval ( "mavutil.mavlink." + args [ 0 ] ) except AttributeError as e : try : command = eval ( "mavutil.mavlink.MAV_CMD_" + args [ 0 ] ) except AttributeError as e : pass if command is None : print ( "Unknown command long ({0})" . format ( args [ 0 ] ) ) return floating_args = [ float ( x ) for x in args [ 1 : ] ] while len ( floating_args ) < 7 : floating_args . append ( float ( 0 ) ) self . master . mav . command_long_send ( self . settings . target_system , self . settings . target_component , command , 0 , * floating_args )
execute supplied command long
41,715
def cmd_command_int ( self , args ) : if len ( args ) != 11 : print ( "num args{0}" . format ( len ( args ) ) ) print ( "Usage: command_int frame command current autocontinue param1 param2 param3 param4 x y z" ) print ( "e.g. command_int GLOBAL_RELATIVE_ALT DO_SET_HOME 0 0 0 0 0 0 -353632120 1491659330 0" ) print ( "e.g. command_int GLOBAL MAV_CMD_DO_SET_ROI 0 0 0 0 0 0 5000000 5000000 500" ) return if args [ 0 ] . isdigit ( ) : frame = int ( args [ 0 ] ) else : try : frame = eval ( "mavutil.mavlink." + args [ 0 ] ) except AttributeError as e : try : frame = eval ( "mavutil.mavlink.MAV_FRAME_" + args [ 0 ] ) except AttributeError as e : pass if frame is None : print ( "Unknown frame ({0})" . format ( args [ 0 ] ) ) return command = None if args [ 1 ] . isdigit ( ) : command = int ( args [ 1 ] ) else : try : command = eval ( "mavutil.mavlink." + args [ 1 ] ) except AttributeError as e : try : command = eval ( "mavutil.mavlink.MAV_CMD_" + args [ 1 ] ) except AttributeError as e : pass current = int ( args [ 2 ] ) autocontinue = int ( args [ 3 ] ) param1 = float ( args [ 4 ] ) param2 = float ( args [ 5 ] ) param3 = float ( args [ 6 ] ) param4 = float ( args [ 7 ] ) x = int ( args [ 8 ] ) y = int ( args [ 9 ] ) z = float ( args [ 10 ] ) self . master . mav . command_int_send ( self . settings . target_system , self . settings . target_component , frame , command , 0 , 0 , param1 , param2 , param3 , param4 , x , y , z )
execute supplied command_int
41,716
def cmd_sensors ( self , args ) : gps_heading = self . status . msgs [ 'GPS_RAW_INT' ] . cog * 0.01 self . console . writeln ( "heading: %u/%u alt: %u/%u r/p: %u/%u speed: %u/%u thr: %u" % ( self . status . msgs [ 'VFR_HUD' ] . heading , gps_heading , self . status . altitude , self . gps_alt , math . degrees ( self . status . msgs [ 'ATTITUDE' ] . roll ) , math . degrees ( self . status . msgs [ 'ATTITUDE' ] . pitch ) , self . status . msgs [ 'VFR_HUD' ] . airspeed , self . status . msgs [ 'VFR_HUD' ] . groundspeed , self . status . msgs [ 'VFR_HUD' ] . throttle ) )
show key sensors
41,717
def cmd_reverse_lookup ( command_name ) : for key , value in miss_cmds . items ( ) : if ( value . upper ( ) == command_name . upper ( ) ) : return key return 0
returns 0 if key not found
41,718
def make_column_label ( command_name , description , default ) : for ( pattern , label ) in description_map : if fnmatch . fnmatch ( description , pattern ) : return label return default
try to work out a reasonable column name from parameter description
41,719
def get_column_labels ( command_name ) : cmd = cmd_reverse_lookup ( command_name ) if cmd == 0 : return { } labels = { } enum = mavutil . mavlink . enums [ 'MAV_CMD' ] [ cmd ] for col in enum . param . keys ( ) : labels [ col ] = make_column_label ( command_name , enum . param [ col ] , "P%u" % col ) return labels
return dictionary of column labels if available
41,720
def find_connection ( self ) : if self . connection is not None : return self . connection for m in self . mpstate . mav_master : if 'HEARTBEAT' in m . messages : if m . messages [ 'HEARTBEAT' ] . type == mavutil . mavlink . MAV_TYPE_ANTENNA_TRACKER : return m return None
find an antenna tracker connection if possible
41,721
def cmd_tracker ( self , args ) : usage = "usage: tracker <start|set|arm|disarm|level|param|mode|position> [options]" if len ( args ) == 0 : print ( usage ) return if args [ 0 ] == "start" : self . cmd_tracker_start ( ) elif args [ 0 ] == "set" : self . tracker_settings . command ( args [ 1 : ] ) elif args [ 0 ] == 'arm' : self . cmd_tracker_arm ( ) elif args [ 0 ] == 'disarm' : self . cmd_tracker_disarm ( ) elif args [ 0 ] == 'level' : self . cmd_tracker_level ( ) elif args [ 0 ] == 'param' : self . cmd_tracker_param ( args [ 1 : ] ) elif args [ 0 ] == 'mode' : self . cmd_tracker_mode ( args [ 1 : ] ) elif args [ 0 ] == 'position' : self . cmd_tracker_position ( args [ 1 : ] ) elif args [ 0 ] == 'calpress' : self . cmd_tracker_calpress ( args [ 1 : ] ) else : print ( usage )
tracker command parser
41,722
def cmd_tracker_position ( self , args ) : connection = self . find_connection ( ) if not connection : print ( "No antenna tracker found" ) return positions = [ 0 , 0 , 0 , 0 , 0 ] for i in range ( 0 , 4 ) : if len ( args ) > i : positions [ i ] = int ( args [ i ] ) connection . mav . manual_control_send ( connection . target_system , positions [ 0 ] , positions [ 1 ] , positions [ 2 ] , positions [ 3 ] , positions [ 4 ] )
tracker manual positioning commands
41,723
def cmd_tracker_calpress ( self , args ) : connection = self . find_connection ( ) if not connection : print ( "No antenna tracker found" ) return connection . calibrate_pressure ( )
calibrate barometer on tracker
41,724
def mavlink_packet ( self , m ) : if m . get_type ( ) in [ 'GLOBAL_POSITION_INT' , 'SCALED_PRESSURE' ] : connection = self . find_connection ( ) if not connection : return if m . get_srcSystem ( ) != connection . target_system : connection . mav . send ( m )
handle an incoming mavlink packet from the master vehicle . Relay it to the tracker if it is a GLOBAL_POSITION_INT
41,725
def cmd_legend ( self , args ) : if len ( args ) == 0 : for leg in self . legend . keys ( ) : print ( "%s -> %s" % ( leg , self . legend [ leg ] ) ) elif len ( args ) == 1 : leg = args [ 0 ] if leg in self . legend : print ( "Removing legend %s" % leg ) self . legend . pop ( leg ) elif len ( args ) >= 2 : leg = args [ 0 ] leg2 = args [ 1 ] print ( "Adding legend %s -> %s" % ( leg , leg2 ) ) self . legend [ leg ] = leg2
setup legend for graphs
41,726
def cmd_gimbal_mode ( self , args ) : if len ( args ) != 1 : print ( "usage: gimbal mode <GPS|MAVLink>" ) return if args [ 0 ] . upper ( ) == 'GPS' : mode = mavutil . mavlink . MAV_MOUNT_MODE_GPS_POINT elif args [ 0 ] . upper ( ) == 'MAVLINK' : mode = mavutil . mavlink . MAV_MOUNT_MODE_MAVLINK_TARGETING elif args [ 0 ] . upper ( ) == 'RC' : mode = mavutil . mavlink . MAV_MOUNT_MODE_RC_TARGETING else : print ( "Unsupported mode %s" % args [ 0 ] ) self . master . mav . mount_configure_send ( self . target_system , self . target_component , mode , 1 , 1 , 1 )
control gimbal mode
41,727
def cmd_gimbal_roi ( self , args ) : latlon = None try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ) return if latlon is None : print ( "No map click position available" ) return self . master . mav . mount_control_send ( self . target_system , self . target_component , latlon [ 0 ] * 1e7 , latlon [ 1 ] * 1e7 , 0 , 0 )
control roi position
41,728
def cmd_gimbal_roi_vel ( self , args ) : if len ( args ) != 0 and len ( args ) != 3 and len ( args ) != 6 : print ( "usage: gimbal roivel [VEL_NORTH VEL_EAST VEL_DOWN] [ACC_NORTH ACC_EASY ACC_DOWN]" ) return latlon = None vel = [ 0 , 0 , 0 ] acc = [ 0 , 0 , 0 ] if ( len ( args ) >= 3 ) : vel [ 0 : 3 ] = args [ 0 : 3 ] if ( len ( args ) == 6 ) : acc [ 0 : 3 ] = args [ 3 : 6 ] try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ) return if latlon is None : print ( "No map click position available" ) latlon = ( 0 , 0 , 0 ) self . master . mav . set_roi_global_int_send ( 0 , 1 , 1 , mavutil . mavlink . MAV_FRAME_GLOBAL_RELATIVE_ALT_INT , 0 , 0 , 0 , int ( latlon [ 0 ] * 1e7 ) , int ( latlon [ 1 ] * 1e7 ) , float ( 0 ) , float ( vel [ 0 ] ) , float ( vel [ 1 ] ) , float ( vel [ 2 ] ) , float ( acc [ 0 ] ) , float ( acc [ 1 ] ) , float ( acc [ 2 ] ) )
control roi position and velocity
41,729
def cmd_gimbal_rate ( self , args ) : if len ( args ) != 3 : print ( "usage: gimbal rate ROLL PITCH YAW" ) return ( roll , pitch , yaw ) = ( float ( args [ 0 ] ) , float ( args [ 1 ] ) , float ( args [ 2 ] ) ) self . master . mav . gimbal_control_send ( self . target_system , mavutil . mavlink . MAV_COMP_ID_GIMBAL , radians ( roll ) , radians ( pitch ) , radians ( yaw ) )
control gimbal rate
41,730
def cmd_gimbal_point ( self , args ) : if len ( args ) != 3 : print ( "usage: gimbal point ROLL PITCH YAW" ) return ( roll , pitch , yaw ) = ( float ( args [ 0 ] ) , float ( args [ 1 ] ) , float ( args [ 2 ] ) ) self . master . mav . mount_control_send ( self . target_system , self . target_component , pitch * 100 , roll * 100 , yaw * 100 , 0 )
control gimbal pointing
41,731
def cmd_gimbal_status ( self , args ) : master = self . master if 'GIMBAL_REPORT' in master . messages : print ( master . messages [ 'GIMBAL_REPORT' ] ) else : print ( "No GIMBAL_REPORT messages" )
show gimbal status
41,732
def draw ( self , img , pixmapper , bounds ) : if self . _img is None : self . _img = self . draw_legend ( ) w = self . _img . shape [ 1 ] h = self . _img . shape [ 0 ] px = 5 py = 5 img [ py : py + h , px : px + w ] = self . _img
draw legend on the image
41,733
def draw ( self , img , pixmapper , bounds ) : if self . hidden : return thumb = self . img ( ) ( px , py ) = pixmapper ( self . latlon ) ( w , h ) = image_shape ( thumb ) px -= w // 2 py -= h // 2 ( px , py , sx , sy , w , h ) = self . clip ( px , py , w , h , img ) thumb_roi = thumb [ sy : sy + h , sx : sx + w ] img [ py : py + h , px : px + w ] = thumb_roi self . posx = px + w // 2 self . posy = py + h // 2
draw the thumbnail on the image
41,734
def cmd_terrain ( self , args ) : usage = "usage: terrain <set|status|check>" if len ( args ) == 0 : print ( usage ) return if args [ 0 ] == "status" : print ( "blocks_sent: %u requests_received: %u" % ( self . blocks_sent , self . requests_received ) ) elif args [ 0 ] == "set" : self . terrain_settings . command ( args [ 1 : ] ) elif args [ 0 ] == "check" : self . cmd_terrain_check ( args [ 1 : ] ) else : print ( usage )
terrain command parser
41,735
def cmd_terrain_check ( self , args ) : if len ( args ) >= 2 : latlon = ( float ( args [ 0 ] ) , float ( args [ 1 ] ) ) else : try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ) return if latlon is None : print ( "No map click position available" ) return self . check_lat = int ( latlon [ 0 ] * 1e7 ) self . check_lon = int ( latlon [ 1 ] * 1e7 ) self . master . mav . terrain_check_send ( self . check_lat , self . check_lon )
check a piece of terrain data
41,736
def idle_task ( self ) : if self . current_request is None : return if time . time ( ) - self . last_send_time < 0.2 : return self . send_terrain_data ( )
called when idle
41,737
def unknown_command ( self , args ) : mode_mapping = self . master . mode_mapping ( ) mode = args [ 0 ] . upper ( ) if mode in mode_mapping : self . master . set_mode ( mode_mapping [ mode ] ) return True return False
handle mode switch by mode name as command
41,738
def cmd_guided ( self , args ) : if len ( args ) != 1 and len ( args ) != 3 : print ( "Usage: guided ALTITUDE | guided LAT LON ALTITUDE" ) return if len ( args ) == 3 : latitude = float ( args [ 0 ] ) longitude = float ( args [ 1 ] ) altitude = float ( args [ 2 ] ) latlon = ( latitude , longitude ) else : try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ) return if latlon is None : print ( "No map click position available" ) return altitude = float ( args [ 0 ] ) print ( "Guided %s %s" % ( str ( latlon ) , str ( altitude ) ) ) self . master . mav . mission_item_send ( self . settings . target_system , self . settings . target_component , 0 , self . module ( 'wp' ) . get_default_frame ( ) , mavutil . mavlink . MAV_CMD_NAV_WAYPOINT , 2 , 0 , 0 , 0 , 0 , 0 , latlon [ 0 ] , latlon [ 1 ] , altitude )
set GUIDED target
41,739
def check_sim_in ( self ) : try : pkt = self . sim_in . recv ( 17 * 8 + 4 ) except socket . error as e : if not e . errno in [ errno . EAGAIN , errno . EWOULDBLOCK ] : raise return if len ( pkt ) != 17 * 8 + 4 : print ( "wrong size %u" % len ( pkt ) ) return ( latitude , longitude , altitude , heading , v_north , v_east , v_down , ax , ay , az , phidot , thetadot , psidot , roll , pitch , yaw , vcas , check ) = struct . unpack ( '<17dI' , pkt ) ( p , q , r ) = self . convert_body_frame ( radians ( roll ) , radians ( pitch ) , radians ( phidot ) , radians ( thetadot ) , radians ( psidot ) ) try : self . hil_state_msg = self . master . mav . hil_state_encode ( int ( time . time ( ) * 1e6 ) , radians ( roll ) , radians ( pitch ) , radians ( yaw ) , p , q , r , int ( latitude * 1.0e7 ) , int ( longitude * 1.0e7 ) , int ( altitude * 1.0e3 ) , int ( v_north * 100 ) , int ( v_east * 100 ) , 0 , int ( ax * 1000 / 9.81 ) , int ( ay * 1000 / 9.81 ) , int ( az * 1000 / 9.81 ) ) except Exception : return
check for FDM packets from runsim
41,740
def check_sim_out ( self ) : now = time . time ( ) if now - self . last_sim_send_time < 0.02 or self . rc_channels_scaled is None : return self . last_sim_send_time = now servos = [ ] for ch in range ( 1 , 9 ) : servos . append ( self . scale_channel ( ch , getattr ( self . rc_channels_scaled , 'chan%u_scaled' % ch ) ) ) servos . extend ( [ 0 , 0 , 0 , 0 , 0 , 0 ] ) buf = struct . pack ( '<14H' , * servos ) try : self . sim_out . send ( buf ) except socket . error as e : if not e . errno in [ errno . ECONNREFUSED ] : raise return
check if we should send new servos to flightgear
41,741
def check_apm_out ( self ) : now = time . time ( ) if now - self . last_apm_send_time < 0.02 : return self . last_apm_send_time = now if self . hil_state_msg is not None : self . master . mav . send ( self . hil_state_msg )
check if we should send new data to the APM
41,742
def convert_body_frame ( self , phi , theta , phiDot , thetaDot , psiDot ) : p = phiDot - psiDot * math . sin ( theta ) q = math . cos ( phi ) * thetaDot + math . sin ( phi ) * psiDot * math . cos ( theta ) r = math . cos ( phi ) * psiDot * math . cos ( theta ) - math . sin ( phi ) * thetaDot return ( p , q , r )
convert a set of roll rates from earth frame to body frame
41,743
def append ( self , v ) : if isinstance ( v , MPSetting ) : setting = v else : ( name , type , default ) = v label = name tab = None if len ( v ) > 3 : label = v [ 3 ] if len ( v ) > 4 : tab = v [ 4 ] setting = MPSetting ( name , type , default , label = label , tab = tab ) if setting . tab is None : setting . tab = self . _default_tab else : self . _default_tab = setting . tab self . _vars [ setting . name ] = setting self . _keys . append ( setting . name ) self . _last_change = time . time ( )
add a new setting
41,744
def get ( self , name ) : if not name in self . _vars : raise AttributeError setting = self . _vars [ name ] return setting . value
get a setting
41,745
def command ( self , args ) : if len ( args ) == 0 : self . show_all ( ) return if getattr ( self , args [ 0 ] , [ None ] ) == [ None ] : print ( "Unknown setting '%s'" % args [ 0 ] ) return if len ( args ) == 1 : self . show ( args [ 0 ] ) else : self . set ( args [ 0 ] , args [ 1 ] )
control options from cmdline
41,746
def all_checks_enabled ( self ) : arming_mask = int ( self . get_mav_param ( "ARMING_CHECK" , 0 ) ) if arming_mask == 1 : return True for bit in arming_masks . values ( ) : if not arming_mask & bit and bit != 1 : return False return True
returns true if the UAV is skipping any arming checks
41,747
def handle_px4_param_value ( self , m ) : if m . param_type == mavutil . mavlink . MAV_PARAM_TYPE_REAL32 : return m . param_value is_px4_params = False if m . get_srcComponent ( ) in [ mavutil . mavlink . MAV_COMP_ID_UDP_BRIDGE ] : is_px4_params = True sysid = m . get_srcSystem ( ) if self . autopilot_type_by_sysid . get ( sysid , - 1 ) in [ mavutil . mavlink . MAV_AUTOPILOT_PX4 ] : is_px4_params = True if not is_px4_params : return m . param_value value = m . param_value try : v = struct . pack ( ">f" , value ) except Exception : return value if m . param_type == mavutil . mavlink . MAV_PARAM_TYPE_UINT8 : value , = struct . unpack ( ">B" , v [ 3 : ] ) elif m . param_type == mavutil . mavlink . MAV_PARAM_TYPE_INT8 : value , = struct . unpack ( ">b" , v [ 3 : ] ) elif m . param_type == mavutil . mavlink . MAV_PARAM_TYPE_UINT16 : value , = struct . unpack ( ">H" , v [ 2 : ] ) elif m . param_type == mavutil . mavlink . MAV_PARAM_TYPE_INT16 : value , = struct . unpack ( ">h" , v [ 2 : ] ) elif m . param_type == mavutil . mavlink . MAV_PARAM_TYPE_UINT32 : value , = struct . unpack ( ">I" , v [ 0 : ] ) elif m . param_type == mavutil . mavlink . MAV_PARAM_TYPE_INT32 : value , = struct . unpack ( ">i" , v [ 0 : ] ) self . param_types [ m . param_id . upper ( ) ] = m . param_type return value
special handling for the px4 style of PARAM_VALUE
41,748
def param_help_download ( self ) : files = [ ] for vehicle in [ 'APMrover2' , 'ArduCopter' , 'ArduPlane' , 'ArduSub' , 'AntennaTracker' ] : url = 'http://autotest.ardupilot.org/Parameters/%s/apm.pdef.xml' % vehicle path = mp_util . dot_mavproxy ( "%s.xml" % vehicle ) files . append ( ( url , path ) ) url = 'http://autotest.ardupilot.org/%s-defaults.parm' % vehicle if vehicle != 'AntennaTracker' : path = mp_util . dot_mavproxy ( "%s-defaults.parm" % vehicle ) files . append ( ( url , path ) ) try : child = multiproc . Process ( target = mp_util . download_files , args = ( files , ) ) child . start ( ) except Exception as e : print ( e )
download XML files for parameters
41,749
def param_help_tree ( self ) : if self . xml_filepath is not None : print ( "param: using xml_filepath=%s" % self . xml_filepath ) path = self . xml_filepath else : if self . vehicle_name is None : print ( "Unknown vehicle type" ) return None path = mp_util . dot_mavproxy ( "%s.xml" % self . vehicle_name ) if not os . path . exists ( path ) : print ( "Please run 'param download' first (vehicle_name=%s)" % self . vehicle_name ) return None if not os . path . exists ( path ) : print ( "Param XML (%s) does not exist" % path ) return None xml = open ( path , 'rb' ) . read ( ) from lxml import objectify objectify . enable_recursive_str ( ) tree = objectify . fromstring ( xml ) htree = { } for p in tree . vehicles . parameters . param : n = p . get ( 'name' ) . split ( ':' ) [ 1 ] htree [ n ] = p for lib in tree . libraries . parameters : for p in lib . param : n = p . get ( 'name' ) htree [ n ] = p return htree
return a help tree a map between a parameter and its metadata . May return None if help is not available
41,750
def param_apropos ( self , args ) : if len ( args ) == 0 : print ( "Usage: param apropos keyword" ) return htree = self . param_help_tree ( ) if htree is None : return contains = { } for keyword in args : for param in htree . keys ( ) : if str ( htree [ param ] ) . find ( keyword ) != - 1 : contains [ param ] = True for param in contains . keys ( ) : print ( "%s" % ( param , ) )
search parameter help for a keyword list those parameters
41,751
def get_component_id_list ( self , system_id ) : ret = [ ] for ( s , c ) in self . mpstate . mav_param_by_sysid . keys ( ) : if s == system_id : ret . append ( c ) return ret
get list of component IDs with parameters for a given system ID
41,752
def get_sysid ( self ) : component = self . target_component if component == 0 : component = 1 return ( self . target_system , component )
get sysid tuple to use for parameters
41,753
def parse_args ( self , args = None , values = None ) : q = multiproc . Queue ( ) p = multiproc . Process ( target = self . _parse_args , args = ( q , args , values ) ) p . start ( ) ret = q . get ( ) p . join ( ) return ret
multiprocessing wrapper around _parse_args
41,754
def _parse_args ( self , q , args , values ) : if wx . GetApp ( ) is None : self . app = wx . App ( False ) option_values , args = self . SUPER . parse_args ( self , args , values ) for option in self . option_list : if option . dest and hasattr ( option_values , option . dest ) : default = getattr ( option_values , option . dest ) if default is not None : option . default = default dlg = OptparseDialog ( option_parser = self , title = self . get_description ( ) ) if args : dlg . args_ctrl . Value = ' ' . join ( args ) dlg_result = dlg . ShowModal ( ) if wx . ID_OK != dlg_result : raise UserCancelledError ( 'User has canceled' ) if values is None : values = self . get_default_values ( ) option_values , args = dlg . getOptionsAndArgs ( ) for option , value in option_values . iteritems ( ) : if ( 'store_true' == option . action ) and ( value is False ) : setattr ( values , option . dest , False ) continue if ( 'store_false' == option . action ) and ( value is True ) : setattr ( values , option . dest , False ) continue if option . takes_value ( ) is False : value = None option . process ( option , value , values , self ) q . put ( ( values , args ) )
This is the heart of it all - overrides optparse . OptionParser . parse_args
41,755
def distance_from ( self , lat , lon ) : lat1 = self . pkt [ 'I105' ] [ 'Lat' ] [ 'val' ] lon1 = self . pkt [ 'I105' ] [ 'Lon' ] [ 'val' ] return mp_util . gps_distance ( lat1 , lon1 , lat , lon )
get distance from a point
41,756
def randpos ( self ) : self . setpos ( gen_settings . home_lat , gen_settings . home_lon ) self . move ( random . uniform ( 0 , 360 ) , random . uniform ( 0 , gen_settings . region_width ) )
random initial position
41,757
def ground_height ( self ) : lat = self . pkt [ 'I105' ] [ 'Lat' ] [ 'val' ] lon = self . pkt [ 'I105' ] [ 'Lon' ] [ 'val' ] global ElevationMap ret = ElevationMap . GetElevation ( lat , lon ) ret -= gen_settings . wgs84_to_AMSL return ret * 3.2807
return height above ground in feet
41,758
def move ( self , bearing , distance ) : lat = self . pkt [ 'I105' ] [ 'Lat' ] [ 'val' ] lon = self . pkt [ 'I105' ] [ 'Lon' ] [ 'val' ] ( lat , lon ) = mp_util . gps_newpos ( lat , lon , bearing , distance ) self . setpos ( lat , lon )
move position by bearing and distance
41,759
def update ( self , deltat = 1.0 ) : DNFZ . update ( self , deltat ) self . dist_flown += self . speed * deltat if self . dist_flown > self . circuit_width : self . desired_heading = self . heading + 90 self . dist_flown = 0 if self . getalt ( ) < self . ground_height ( ) or self . getalt ( ) > self . ground_height ( ) + 2000 : self . randpos ( ) self . randalt ( )
fly a square circuit
41,760
def update ( self , deltat = 1.0 ) : DNFZ . update ( self , deltat ) self . time_circling += deltat self . setheading ( self . heading + self . turn_rate * deltat ) self . move ( self . drift_heading , self . drift_speed ) if self . getalt ( ) > self . max_alt or self . getalt ( ) < self . ground_height ( ) : if self . getalt ( ) > self . ground_height ( ) : self . setclimbrate ( self . dive_rate ) else : self . setclimbrate ( self . climb_rate ) if self . getalt ( ) < self . ground_height ( ) : self . setalt ( self . ground_height ( ) ) if self . distance_from_home ( ) > gen_settings . region_width : self . randpos ( ) self . randalt ( )
fly circles then dive
41,761
def update ( self , deltat = 1.0 ) : DNFZ . update ( self , deltat ) if ( self . distance_from_home ( ) > gen_settings . region_width or self . getalt ( ) < self . ground_height ( ) or self . getalt ( ) > self . ground_height ( ) + 1000 ) : self . randpos ( ) self . randalt ( )
fly in long curves
41,762
def update ( self , deltat = 1.0 ) : DNFZ . update ( self , deltat ) self . lifetime -= deltat if self . lifetime <= 0 : self . randpos ( ) self . lifetime = random . uniform ( 300 , 600 )
straight lines with short life
41,763
def cmd_dropobject ( self , obj ) : latlon = self . module ( 'map' ) . click_position if self . last_click is not None and self . last_click == latlon : return self . last_click = latlon if latlon is not None : obj . setpos ( latlon [ 0 ] , latlon [ 1 ] ) self . aircraft . append ( obj )
drop an object on the map
41,764
def cmd_genobstacles ( self , args ) : usage = "usage: genobstacles <start|stop|restart|clearall|status|set>" if len ( args ) == 0 : print ( usage ) return if args [ 0 ] == "set" : gen_settings . command ( args [ 1 : ] ) elif args [ 0 ] == "start" : if self . have_home : self . start ( ) else : self . pending_start = True elif args [ 0 ] == "stop" : self . stop ( ) self . pending_start = False elif args [ 0 ] == "restart" : self . stop ( ) self . start ( ) elif args [ 0 ] == "status" : print ( self . status ( ) ) elif args [ 0 ] == "remove" : latlon = self . module ( 'map' ) . click_position if self . last_click is not None and self . last_click == latlon : return self . last_click = latlon if latlon is not None : closest = None closest_distance = 1000 for a in self . aircraft : dist = a . distance_from ( latlon [ 0 ] , latlon [ 1 ] ) if dist < closest_distance : closest_distance = dist closest = a if closest is not None : self . aircraft . remove ( closest ) else : print ( "No obstacle found at click point" ) elif args [ 0 ] == "dropcloud" : self . cmd_dropobject ( Weather ( ) ) elif args [ 0 ] == "dropeagle" : self . cmd_dropobject ( BirdOfPrey ( ) ) elif args [ 0 ] == "dropbird" : self . cmd_dropobject ( BirdMigrating ( ) ) elif args [ 0 ] == "dropplane" : self . cmd_dropobject ( Aircraft ( ) ) elif args [ 0 ] == "clearall" : self . clearall ( ) else : print ( usage )
genobstacles command parser
41,765
def start ( self ) : if self . sock is not None : self . sock . close ( ) self . sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM , socket . IPPROTO_UDP ) self . sock . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) self . sock . connect ( ( '' , gen_settings . port ) ) global track_count self . aircraft = [ ] track_count = 0 self . last_t = 0 for i in range ( gen_settings . num_aircraft ) : self . aircraft . append ( Aircraft ( random . uniform ( 10 , 100 ) , 2000.0 ) ) for i in range ( gen_settings . num_bird_prey ) : self . aircraft . append ( BirdOfPrey ( ) ) for i in range ( gen_settings . num_bird_migratory ) : self . aircraft . append ( BirdMigrating ( ) ) for i in range ( gen_settings . num_weather ) : self . aircraft . append ( Weather ( ) ) print ( "Started on port %u" % gen_settings . port )
start sending packets
41,766
def mavlink_packet ( self , m ) : if not self . have_home and m . get_type ( ) == 'GPS_RAW_INT' and m . fix_type >= 3 : gen_settings . home_lat = m . lat * 1.0e-7 gen_settings . home_lon = m . lon * 1.0e-7 self . have_home = True if self . pending_start : self . start ( ) if m . get_type ( ) != 'ATTITUDE' : return t = self . get_time ( ) dt = t - self . last_t if dt < 0 or dt > 10 : self . last_t = t return if dt > 10 or dt < 0.9 : return self . last_t = t for a in self . aircraft : if not gen_settings . stop : a . update ( 1.0 ) self . pkt_queue . append ( a . pickled ( ) ) while len ( self . pkt_queue ) > len ( self . aircraft ) * 2 : self . pkt_queue . pop ( 0 ) if self . module ( 'map' ) is not None and not self . menu_added_map : self . menu_added_map = True self . module ( 'map' ) . add_menu ( self . menu )
trigger sends from ATTITUDE packets
41,767
def update ( self , state , tnow ) : self . state = state self . update_time = tnow
update the threat state
41,768
def cmd_ADSB ( self , args ) : usage = "usage: adsb <set>" if len ( args ) == 0 : print ( usage ) return if args [ 0 ] == "status" : print ( "total threat count: %u active threat count: %u" % ( len ( self . threat_vehicles ) , len ( self . active_threat_ids ) ) ) for id in self . threat_vehicles . keys ( ) : print ( "id: %s distance: %.2f m callsign: %s alt: %.2f" % ( id , self . threat_vehicles [ id ] . distance , self . threat_vehicles [ id ] . state [ 'callsign' ] , self . threat_vehicles [ id ] . state [ 'altitude' ] ) ) elif args [ 0 ] == "set" : self . ADSB_settings . command ( args [ 1 : ] ) else : print ( usage )
adsb command parser
41,769
def update_threat_distances ( self , latlonalt ) : for id in self . threat_vehicles . keys ( ) : threat_latlonalt = ( self . threat_vehicles [ id ] . state [ 'lat' ] * 1e-7 , self . threat_vehicles [ id ] . state [ 'lon' ] * 1e-7 , self . threat_vehicles [ id ] . state [ 'altitude' ] ) self . threat_vehicles [ id ] . h_distance = self . get_h_distance ( latlonalt , threat_latlonalt ) self . threat_vehicles [ id ] . v_distance = self . get_v_distance ( latlonalt , threat_latlonalt ) self . threat_vehicles [ id ] . distance = sqrt ( self . threat_vehicles [ id ] . h_distance ** 2 + ( self . threat_vehicles [ id ] . v_distance ) ** 2 )
update the distance between threats and vehicle
41,770
def check_threat_timeout ( self ) : for id in self . threat_vehicles . keys ( ) : if self . threat_vehicles [ id ] . update_time == 0 : self . threat_vehicles [ id ] . update_time = self . get_time ( ) dt = self . get_time ( ) - self . threat_vehicles [ id ] . update_time if dt > self . ADSB_settings . timeout : del self . threat_vehicles [ id ] for mp in self . module_matching ( 'map*' ) : mp . map . remove_object ( id ) mp . map . remove_object ( id + ":circle" ) return
check and handle threat time out
41,771
def cmd_gopro_status ( self , args ) : master = self . master if 'GOPRO_HEARTBEAT' in master . messages : print ( master . messages [ 'GOPRO_HEARTBEAT' ] ) else : print ( "No GOPRO_HEARTBEAT messages" )
show gopro status
41,772
def on_text_url ( self , event ) : try : import webbrowser except ImportError : return mouse_event = event . GetMouseEvent ( ) if mouse_event . LeftDClick ( ) : url_start = event . GetURLStart ( ) url_end = event . GetURLEnd ( ) url = self . control . GetRange ( url_start , url_end ) try : browser_controller = webbrowser . get ( 'google-chrome' ) browser_controller . open_new_tab ( url ) except webbrowser . Error : webbrowser . open_new_tab ( url )
handle double clicks on URL text
41,773
def update_channels ( self ) : self . interlock_channel = - 1 self . override_channel = - 1 self . zero_I_channel = - 1 self . no_vtol_channel = - 1 self . rsc_out_channel = 9 self . fwd_thr_channel = 10 for ch in range ( 1 , 16 ) : option = self . get_mav_param ( "RC%u_OPTION" % ch , 0 ) if option == 32 : self . interlock_channel = ch elif option == 63 : self . override_channel = ch elif option == 64 : self . zero_I_channel = ch elif option == 65 : self . override_channel = ch elif option == 66 : self . no_vtol_channel = ch function = self . get_mav_param ( "SERVO%u_FUNCTION" % ch , 0 ) if function == 32 : self . rsc_out_channel = ch if function == 70 : self . fwd_thr_channel = ch
update which channels provide input
41,774
def rallyloader ( self ) : if not self . target_system in self . rallyloader_by_sysid : self . rallyloader_by_sysid [ self . target_system ] = mavwp . MAVRallyLoader ( self . settings . target_system , self . settings . target_component ) return self . rallyloader_by_sysid [ self . target_system ]
rally loader by system ID
41,775
def packet_is_for_me ( self , m ) : if m . target_system != self . master . mav . srcSystem : return False if m . target_component != self . master . mav . srcComponent : return False if self . sender is not None : if ( m . get_srcSystem ( ) , m . get_srcComponent ( ) ) != self . sender : return False return True
returns true if this packet is appropriately addressed
41,776
def _convert_agg_to_wx_image ( agg , bbox ) : if bbox is None : image = wx . EmptyImage ( int ( agg . width ) , int ( agg . height ) ) image . SetData ( agg . tostring_rgb ( ) ) return image else : return wx . ImageFromBitmap ( _WX28_clipped_agg_as_bitmap ( agg , bbox ) )
Convert the region of the agg buffer bounded by bbox to a wx . Image . If bbox is None the entire buffer is converted .
41,777
def _convert_agg_to_wx_bitmap ( agg , bbox ) : if bbox is None : return wx . BitmapFromBufferRGBA ( int ( agg . width ) , int ( agg . height ) , agg . buffer_rgba ( ) ) else : return _WX28_clipped_agg_as_bitmap ( agg , bbox )
Convert the region of the agg buffer bounded by bbox to a wx . Bitmap . If bbox is None the entire buffer is converted .
41,778
def _WX28_clipped_agg_as_bitmap ( agg , bbox ) : l , b , width , height = bbox . bounds r = l + width t = b + height srcBmp = wx . BitmapFromBufferRGBA ( int ( agg . width ) , int ( agg . height ) , agg . buffer_rgba ( ) ) srcDC = wx . MemoryDC ( ) srcDC . SelectObject ( srcBmp ) destBmp = wx . EmptyBitmap ( int ( width ) , int ( height ) ) destDC = wx . MemoryDC ( ) destDC . SelectObject ( destBmp ) destDC . BeginDrawing ( ) x = int ( l ) y = int ( int ( agg . height ) - t ) destDC . Blit ( 0 , 0 , int ( width ) , int ( height ) , srcDC , x , y ) destDC . EndDrawing ( ) srcDC . SelectObject ( wx . NullBitmap ) destDC . SelectObject ( wx . NullBitmap ) return destBmp
Convert the region of a the agg buffer bounded by bbox to a wx . Bitmap .
41,779
def draw ( self , drawDC = None ) : DEBUG_MSG ( "draw()" , 1 , self ) FigureCanvasAgg . draw ( self ) self . bitmap = _convert_agg_to_wx_bitmap ( self . get_renderer ( ) , None ) self . _isDrawn = True self . gui_repaint ( drawDC = drawDC )
Render the figure using agg .
41,780
def blit ( self , bbox = None ) : if bbox is None : self . bitmap = _convert_agg_to_wx_bitmap ( self . get_renderer ( ) , None ) self . gui_repaint ( ) return l , b , w , h = bbox . bounds r = l + w t = b + h x = int ( l ) y = int ( self . bitmap . GetHeight ( ) - t ) srcBmp = _convert_agg_to_wx_bitmap ( self . get_renderer ( ) , None ) srcDC = wx . MemoryDC ( ) srcDC . SelectObject ( srcBmp ) destDC = wx . MemoryDC ( ) destDC . SelectObject ( self . bitmap ) destDC . BeginDrawing ( ) destDC . Blit ( x , y , int ( w ) , int ( h ) , srcDC , x , y ) destDC . EndDrawing ( ) destDC . SelectObject ( wx . NullBitmap ) srcDC . SelectObject ( wx . NullBitmap ) self . gui_repaint ( )
Transfer the region of the agg buffer defined by bbox to the display . If bbox is None the entire buffer is transferred .
41,781
def cmd_antenna ( self , args ) : if len ( args ) != 2 : if self . gcs_location is None : print ( "GCS location not set" ) else : print ( "GCS location %s" % str ( self . gcs_location ) ) return self . gcs_location = ( float ( args [ 0 ] ) , float ( args [ 1 ] ) )
set gcs location
41,782
def passphrase_to_key ( self , passphrase ) : import hashlib h = hashlib . new ( 'sha256' ) h . update ( passphrase ) return h . digest ( )
convert a passphrase to a 32 byte key
41,783
def cmd_signing_setup ( self , args ) : if len ( args ) == 0 : print ( "usage: signing setup passphrase" ) return if not self . master . mavlink20 ( ) : print ( "You must be using MAVLink2 for signing" ) return passphrase = args [ 0 ] key = self . passphrase_to_key ( passphrase ) secret_key = [ ] for b in key : secret_key . append ( ord ( b ) ) epoch_offset = 1420070400 now = max ( time . time ( ) , epoch_offset ) initial_timestamp = int ( ( now - epoch_offset ) * 1e5 ) self . master . mav . setup_signing_send ( self . target_system , self . target_component , secret_key , initial_timestamp ) print ( "Sent secret_key" ) self . cmd_signing_key ( [ passphrase ] )
setup signing key on board
41,784
def allow_unsigned ( self , mav , msgId ) : if self . allow is None : self . allow = { mavutil . mavlink . MAVLINK_MSG_ID_RADIO : True , mavutil . mavlink . MAVLINK_MSG_ID_RADIO_STATUS : True } if msgId in self . allow : return True if self . settings . allow_unsigned : return True return False
see if an unsigned packet should be allowed
41,785
def cmd_signing_key ( self , args ) : if len ( args ) == 0 : print ( "usage: signing setup passphrase" ) return if not self . master . mavlink20 ( ) : print ( "You must be using MAVLink2 for signing" ) return passphrase = args [ 0 ] key = self . passphrase_to_key ( passphrase ) self . master . setup_signing ( key , sign_outgoing = True , allow_unsigned_callback = self . allow_unsigned ) print ( "Setup signing key" )
set signing key on connection
41,786
def cmd_signing_remove ( self , args ) : if not self . master . mavlink20 ( ) : print ( "You must be using MAVLink2 for signing" ) return self . master . mav . setup_signing_send ( self . target_system , self . target_component , [ 0 ] * 32 , 0 ) self . master . disable_signing ( ) print ( "Removed signing" )
remove signing from server
41,787
def cmd_output ( self , args ) : if len ( args ) < 1 or args [ 0 ] == "list" : self . cmd_output_list ( ) elif args [ 0 ] == "add" : if len ( args ) != 2 : print ( "Usage: output add OUTPUT" ) return self . cmd_output_add ( args [ 1 : ] ) elif args [ 0 ] == "remove" : if len ( args ) != 2 : print ( "Usage: output remove OUTPUT" ) return self . cmd_output_remove ( args [ 1 : ] ) elif args [ 0 ] == "sysid" : if len ( args ) != 3 : print ( "Usage: output sysid SYSID OUTPUT" ) return self . cmd_output_sysid ( args [ 1 : ] ) else : print ( "usage: output <list|add|remove|sysid>" )
handle output commands
41,788
def cmd_output_add ( self , args ) : device = args [ 0 ] print ( "Adding output %s" % device ) try : conn = mavutil . mavlink_connection ( device , input = False , source_system = self . settings . source_system ) conn . mav . srcComponent = self . settings . source_component except Exception : print ( "Failed to connect to %s" % device ) return self . mpstate . mav_outputs . append ( conn ) try : mp_util . child_fd_list_add ( conn . port . fileno ( ) ) except Exception : pass
add new output
41,789
def cmd_output_sysid ( self , args ) : sysid = int ( args [ 0 ] ) device = args [ 1 ] print ( "Adding output %s for sysid %u" % ( device , sysid ) ) try : conn = mavutil . mavlink_connection ( device , input = False , source_system = self . settings . source_system ) conn . mav . srcComponent = self . settings . source_component except Exception : print ( "Failed to connect to %s" % device ) return try : mp_util . child_fd_list_add ( conn . port . fileno ( ) ) except Exception : pass if sysid in self . mpstate . sysid_outputs : self . mpstate . sysid_outputs [ sysid ] . close ( ) self . mpstate . sysid_outputs [ sysid ] = conn
add new output for a specific MAVLink sysID
41,790
def cmd_output_remove ( self , args ) : device = args [ 0 ] for i in range ( len ( self . mpstate . mav_outputs ) ) : conn = self . mpstate . mav_outputs [ i ] if str ( i ) == device or conn . address == device : print ( "Removing output %s" % conn . address ) try : mp_util . child_fd_list_add ( conn . port . fileno ( ) ) except Exception : pass conn . close ( ) self . mpstate . mav_outputs . pop ( i ) return
remove an output
41,791
def set_center ( self , lat , lon ) : self . object_queue . put ( SlipCenter ( ( lat , lon ) ) )
set center of view
41,792
def get_event ( self ) : if self . event_queue . qsize ( ) == 0 : return None evt = self . event_queue . get ( ) while isinstance ( evt , win_layout . WinLayout ) : win_layout . set_layout ( evt , self . set_layout ) if self . event_queue . qsize ( ) == 0 : return None evt = self . event_queue . get ( ) return evt
return next event or None
41,793
def cmd_layout ( self , args ) : from MAVProxy . modules . lib import win_layout if len ( args ) < 1 : print ( "usage: layout <save|load>" ) return if args [ 0 ] == "load" : win_layout . load_layout ( self . mpstate . settings . vehicle_name ) elif args [ 0 ] == "save" : win_layout . save_layout ( self . mpstate . settings . vehicle_name )
handle layout command
41,794
def download_files ( files ) : for ( url , file ) in files : print ( "Downloading %s as %s" % ( url , file ) ) data = download_url ( url ) if data is None : continue try : open ( file , mode = 'wb' ) . write ( data ) except Exception as e : print ( "Failed to save to %s : %s" % ( file , e ) )
download an array of files
41,795
def null_term ( str ) : if sys . version_info . major < 3 : return str if isinstance ( str , bytes ) : str = str . decode ( "utf-8" ) idx = str . find ( "\0" ) if idx != - 1 : str = str [ : idx ] return str
null terminate a string for py3
41,796
def decode_devid ( devid , pname ) : devid = int ( devid ) if devid == 0 : return bus_type = devid & 0x07 bus = ( devid >> 3 ) & 0x1F address = ( devid >> 8 ) & 0xFF devtype = ( devid >> 16 ) bustypes = { 1 : "I2C" , 2 : "SPI" , 3 : "UAVCAN" , 4 : "SITL" } compass_types = { 0x01 : "DEVTYPE_HMC5883_OLD" , 0x07 : "DEVTYPE_HMC5883" , 0x02 : "DEVTYPE_LSM303D" , 0x04 : "DEVTYPE_AK8963 " , 0x05 : "DEVTYPE_BMM150 " , 0x06 : "DEVTYPE_LSM9DS1" , 0x08 : "DEVTYPE_LIS3MDL" , 0x09 : "DEVTYPE_AK09916" , 0x0A : "DEVTYPE_IST8310" , 0x0B : "DEVTYPE_ICM20948" , 0x0C : "DEVTYPE_MMC3416" , 0x0D : "DEVTYPE_QMC5883L" , 0x0E : "DEVTYPE_MAG3110" , 0x0F : "DEVTYPE_SITL" , 0x10 : "DEVTYPE_IST8308" , 0x11 : "DEVTYPE_RM3100" , } imu_types = { 0x09 : "DEVTYPE_BMI160" , 0x10 : "DEVTYPE_L3G4200D" , 0x11 : "DEVTYPE_ACC_LSM303D" , 0x12 : "DEVTYPE_ACC_BMA180" , 0x13 : "DEVTYPE_ACC_MPU6000" , 0x16 : "DEVTYPE_ACC_MPU9250" , 0x17 : "DEVTYPE_ACC_IIS328DQ" , 0x21 : "DEVTYPE_GYR_MPU6000" , 0x22 : "DEVTYPE_GYR_L3GD20" , 0x24 : "DEVTYPE_GYR_MPU9250" , 0x25 : "DEVTYPE_GYR_I3G4250D" , 0x26 : "DEVTYPE_GYR_LSM9DS1" , 0x27 : "DEVTYPE_INS_ICM20789" , 0x28 : "DEVTYPE_INS_ICM20689" , 0x29 : "DEVTYPE_INS_BMI055" , 0x2A : "DEVTYPE_SITL" , 0x2B : "DEVTYPE_INS_BMI088" , 0x2C : "DEVTYPE_INS_ICM20948" , 0x2D : "DEVTYPE_INS_ICM20648" , 0x2E : "DEVTYPE_INS_ICM20649" , 0x2F : "DEVTYPE_INS_ICM20602" , } decoded_devname = "" if pname . startswith ( "COMPASS" ) : decoded_devname = compass_types . get ( devtype , "UNKNOWN" ) if pname . startswith ( "INS" ) : decoded_devname = imu_types . get ( devtype , "UNKNOWN" ) print ( "%s: bus_type:%s(%u) bus:%u address:%u(0x%x) devtype:%u(0x%x) %s" % ( pname , bustypes . get ( bus_type , "UNKNOWN" ) , bus_type , bus , address , address , devtype , devtype , decoded_devname ) )
decode one device ID . Used for devid command in mavproxy and MAVExplorer
41,797
def _authenticate_user_dn ( self , password ) : if self . dn is None : raise self . AuthenticationFailed ( "failed to map the username to a DN." ) try : sticky = self . settings . BIND_AS_AUTHENTICATING_USER self . _bind_as ( self . dn , password , sticky = sticky ) except ldap . INVALID_CREDENTIALS : raise self . AuthenticationFailed ( "user DN/password rejected by LDAP server." )
Binds to the LDAP server with the user s DN and password . Raises AuthenticationFailed on failure .
41,798
def _load_user_dn ( self ) : if self . _using_simple_bind_mode ( ) : self . _user_dn = self . _construct_simple_user_dn ( ) else : if self . settings . CACHE_TIMEOUT > 0 : cache_key = valid_cache_key ( "django_auth_ldap.user_dn.{}" . format ( self . _username ) ) self . _user_dn = cache . get_or_set ( cache_key , self . _search_for_user_dn , self . settings . CACHE_TIMEOUT ) else : self . _user_dn = self . _search_for_user_dn ( )
Populates self . _user_dn with the distinguished name of our user .
41,799
def _search_for_user_dn ( self ) : search = self . settings . USER_SEARCH if search is None : raise ImproperlyConfigured ( "AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance." ) results = search . execute ( self . connection , { "user" : self . _username } ) if results is not None and len ( results ) == 1 : ( user_dn , self . _user_attrs ) = next ( iter ( results ) ) else : user_dn = None return user_dn
Searches the directory for a user matching AUTH_LDAP_USER_SEARCH . Populates self . _user_dn and self . _user_attrs .