idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
230,100
def slew ( self , value ) : if float ( value ) != self . filepos : pos = float ( value ) * self . filesize self . mlog . f . seek ( int ( pos ) ) self . find_message ( )
move to a given position in the file
230,101
def draw_plot ( self ) : import numpy , pylab state = self . state if len ( self . data [ 0 ] ) == 0 : print ( "no data to plot" ) return vhigh = max ( self . data [ 0 ] ) vlow = min ( self . data [ 0 ] ) for i in range ( 1 , len ( self . plot_data ) ) : vhigh = max ( vhigh , max ( self . data [ i ] ) ) vlow = min ( vl...
Redraws the plot
230,102
def set_close_on_exec ( fd ) : try : import fcntl flags = fcntl . fcntl ( fd , fcntl . F_GETFD ) flags |= fcntl . FD_CLOEXEC fcntl . fcntl ( fd , fcntl . F_SETFD , flags ) except Exception : pass
set the clone on exec flag on a file descriptor . Ignore exceptions
230,103
def mavlink_connection ( device , baud = 115200 , source_system = 255 , planner_format = None , write = False , append = False , robust_parsing = True , notimestamps = False , input = True , dialect = None , autoreconnect = False , zero_time_base = False , retries = 3 , use_native = default_native ) : global mavfile_gl...
open a serial UDP TCP or file mavlink connection
230,104
def is_printable ( c ) : global have_ascii if have_ascii : return ascii . isprint ( c ) if isinstance ( c , int ) : ic = c else : ic = ord ( c ) return ic >= 32 and ic <= 126
see if a character is printable
230,105
def auto_detect_serial_win32 ( preferred_list = [ '*' ] ) : try : from serial . tools . list_ports_windows import comports list = sorted ( comports ( ) ) except : return [ ] ret = [ ] others = [ ] for port , description , hwid in list : matches = False p = SerialPort ( port , description = description , hwid = hwid ) f...
try to auto - detect serial ports on win32
230,106
def auto_detect_serial_unix ( preferred_list = [ '*' ] ) : import glob glist = glob . glob ( '/dev/ttyS*' ) + glob . glob ( '/dev/ttyUSB*' ) + glob . glob ( '/dev/ttyACM*' ) + glob . glob ( '/dev/serial/by-id/*' ) ret = [ ] others = [ ] for d in glist : matches = False for preferred in preferred_list : if fnmatch . fnm...
try to auto - detect serial ports on unix
230,107
def auto_detect_serial ( preferred_list = [ '*' ] ) : if os . name == 'nt' : return auto_detect_serial_win32 ( preferred_list = preferred_list ) return auto_detect_serial_unix ( preferred_list = preferred_list )
try to auto - detect serial port
230,108
def mode_string_v09 ( msg ) : mode = msg . mode nav_mode = msg . nav_mode MAV_MODE_UNINIT = 0 MAV_MODE_MANUAL = 2 MAV_MODE_GUIDED = 3 MAV_MODE_AUTO = 4 MAV_MODE_TEST1 = 5 MAV_MODE_TEST2 = 6 MAV_MODE_TEST3 = 7 MAV_NAV_GROUNDED = 0 MAV_NAV_LIFTOFF = 1 MAV_NAV_HOLD = 2 MAV_NAV_WAYPOINT = 3 MAV_NAV_VECTOR = 4 MAV_NAV_RETUR...
mode string for 0 . 9 protocol
230,109
def mode_mapping_bynumber ( mav_type ) : map = None if mav_type in [ mavlink . MAV_TYPE_QUADROTOR , mavlink . MAV_TYPE_HELICOPTER , mavlink . MAV_TYPE_HEXAROTOR , mavlink . MAV_TYPE_OCTOROTOR , mavlink . MAV_TYPE_COAXIAL , mavlink . MAV_TYPE_TRICOPTER ] : map = mode_mapping_acm if mav_type == mavlink . MAV_TYPE_FIXED_W...
return dictionary mapping mode numbers to name or None if unknown
230,110
def mode_string_v10 ( msg ) : if msg . autopilot == mavlink . MAV_AUTOPILOT_PX4 : return interpret_px4_mode ( msg . base_mode , msg . custom_mode ) if not msg . base_mode & mavlink . MAV_MODE_FLAG_CUSTOM_MODE_ENABLED : return "Mode(0x%08x)" % msg . base_mode if msg . type in [ mavlink . MAV_TYPE_QUADROTOR , mavlink . M...
mode string for 1 . 0 protocol from heartbeat
230,111
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_dial...
auto - switch mavlink protocol version
230,112
def select ( self , timeout ) : if self . fd is None : time . sleep ( min ( timeout , 0.5 ) ) return True try : ( rin , win , xin ) = select . select ( [ self . fd ] , [ ] , [ ] , timeout ) except select . error : return False return len ( rin ) == 1
wait for up to timeout seconds for more data
230,113
def packet_loss ( self ) : if self . mav_count == 0 : return 0 return ( 100.0 * self . mav_loss ) / ( self . mav_count + self . mav_loss )
packet loss as a percentage
230,114
def recv_match ( self , condition = None , type = None , blocking = False , timeout = None ) : if type is not None and not isinstance ( type , list ) : type = [ type ] start_time = time . time ( ) while True : if timeout is not None : now = time . time ( ) if now < start_time : start_time = now if start_time + timeout ...
recv the next MAVLink message that matches the given condition type can be a string or a list of strings
230,115
def setup_logfile ( self , logfile , mode = 'w' ) : self . logfile = open ( logfile , mode = mode )
start logging to the given logfile with timestamps
230,116
def setup_logfile_raw ( self , logfile , mode = 'w' ) : self . logfile_raw = open ( logfile , mode = mode )
start logging raw bytes to the given logfile without timestamps
230,117
def param_fetch_all ( self ) : if time . time ( ) - getattr ( self , 'param_fetch_start' , 0 ) < 2.0 : return self . param_fetch_start = time . time ( ) self . param_fetch_in_progress = True self . mav . param_request_list_send ( self . target_system , self . target_component )
initiate fetch of all parameters
230,118
def param_fetch_one ( self , name ) : try : idx = int ( name ) self . mav . param_request_read_send ( self . target_system , self . target_component , "" , idx ) except Exception : self . mav . param_request_read_send ( self . target_system , self . target_component , name , - 1 )
initiate fetch of one parameter
230,119
def time_since ( self , mtype ) : if not mtype in self . messages : return time . time ( ) - self . start_time return time . time ( ) - self . messages [ mtype ] . _timestamp
return the time since the last message of type mtype was received
230,120
def param_set_send ( self , parm_name , parm_value , parm_type = None ) : if self . mavlink10 ( ) : if parm_type == None : parm_type = mavlink . MAVLINK_TYPE_FLOAT self . mav . param_set_send ( self . target_system , self . target_component , parm_name , parm_value , parm_type ) else : self . mav . param_set_send ( sel...
wrapper for parameter set
230,121
def waypoint_request_list_send ( self ) : if self . mavlink10 ( ) : self . mav . mission_request_list_send ( self . target_system , self . target_component ) else : self . mav . waypoint_request_list_send ( self . target_system , self . target_component )
wrapper for waypoint_request_list_send
230,122
def waypoint_clear_all_send ( self ) : if self . mavlink10 ( ) : self . mav . mission_clear_all_send ( self . target_system , self . target_component ) else : self . mav . waypoint_clear_all_send ( self . target_system , self . target_component )
wrapper for waypoint_clear_all_send
230,123
def waypoint_request_send ( self , seq ) : if self . mavlink10 ( ) : self . mav . mission_request_send ( self . target_system , self . target_component , seq ) else : self . mav . waypoint_request_send ( self . target_system , self . target_component , seq )
wrapper for waypoint_request_send
230,124
def waypoint_set_current_send ( self , seq ) : if self . mavlink10 ( ) : self . mav . mission_set_current_send ( self . target_system , self . target_component , seq ) else : self . mav . waypoint_set_current_send ( self . target_system , self . target_component , seq )
wrapper for waypoint_set_current_send
230,125
def waypoint_current ( self ) : if self . mavlink10 ( ) : m = self . recv_match ( type = 'MISSION_CURRENT' , blocking = True ) else : m = self . recv_match ( type = 'WAYPOINT_CURRENT' , blocking = True ) return m . seq
return current waypoint
230,126
def waypoint_count_send ( self , seq ) : if self . mavlink10 ( ) : self . mav . mission_count_send ( self . target_system , self . target_component , seq ) else : self . mav . waypoint_count_send ( self . target_system , self . target_component , seq )
wrapper for waypoint_count_send
230,127
def set_mode_auto ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_MISSION_START , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) else : MAV_ACTION_SET_AUTO = 13 self . mav . action_send ( self . target_system , self . target_component , MAV_ACTIO...
enter auto mode
230,128
def set_mode ( self , mode , custom_mode = 0 , custom_sub_mode = 0 ) : mav_autopilot = self . field ( 'HEARTBEAT' , 'autopilot' , None ) if mav_autopilot == mavlink . MAV_AUTOPILOT_PX4 : self . set_mode_px4 ( mode , custom_mode , custom_sub_mode ) else : self . set_mode_apm ( mode )
set arbitrary flight mode
230,129
def set_mode_rtl ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_NAV_RETURN_TO_LAUNCH , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) else : MAV_ACTION_RETURN = 3 self . mav . action_send ( self . target_system , self . target_component , MAV_AC...
enter RTL mode
230,130
def set_mode_manual ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_DO_SET_MODE , 0 , mavlink . MAV_MODE_MANUAL_ARMED , 0 , 0 , 0 , 0 , 0 , 0 ) else : MAV_ACTION_SET_MANUAL = 12 self . mav . action_send ( self . target_system , sel...
enter MANUAL mode
230,131
def set_mode_fbwa ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_DO_SET_MODE , 0 , mavlink . MAV_MODE_STABILIZE_ARMED , 0 , 0 , 0 , 0 , 0 , 0 ) else : print ( "Forcing FBWA not supported" )
enter FBWA mode
230,132
def set_mode_loiter ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_NAV_LOITER_UNLIM , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) else : MAV_ACTION_LOITER = 27 self . mav . action_send ( self . target_system , self . target_component , MAV_AC...
enter LOITER mode
230,133
def set_servo ( self , channel , pwm ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_DO_SET_SERVO , 0 , channel , pwm , 0 , 0 , 0 , 0 , 0 )
set a servo value
230,134
def set_relay ( self , relay_pin = 0 , state = True ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_DO_SET_RELAY , 0 , relay_pin , int ( state ) , 0 , 0 , 0 , 0 , 0 ) else : print ( "Setting relays not supported." )
Set relay_pin to value of state
230,135
def reboot_autopilot ( self , hold_in_bootloader = False ) : if self . mavlink10 ( ) : if hold_in_bootloader : param1 = 3 else : param1 = 1 self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN , 0 , param1 , 0 , 0 , 0 , 0 , 0 , 0 ) self . mav . co...
reboot the autopilot
230,136
def location ( self , relative_alt = False ) : self . wait_gps_fix ( ) self . recv_match ( type = 'VFR_HUD' , blocking = True ) self . recv_match ( type = 'GLOBAL_POSITION_INT' , blocking = True ) if relative_alt : alt = self . messages [ 'GLOBAL_POSITION_INT' ] . relative_alt * 0.001 else : alt = self . messages [ 'VF...
return current location
230,137
def motors_armed ( self ) : if not 'HEARTBEAT' in self . messages : return False m = self . messages [ 'HEARTBEAT' ] return ( m . base_mode & mavlink . MAV_MODE_FLAG_SAFETY_ARMED ) != 0
return true if motors armed
230,138
def field ( self , type , field , default = None ) : if not type in self . messages : return default return getattr ( self . messages [ type ] , field , default )
convenient function for returning an arbitrary MAVLink field with a default
230,139
def setup_signing ( self , secret_key , sign_outgoing = True , allow_unsigned_callback = None , initial_timestamp = None , link_id = None ) : self . mav . signing . secret_key = secret_key self . mav . signing . sign_outgoing = sign_outgoing self . mav . signing . allow_unsigned_callback = allow_unsigned_callback if li...
setup for MAVLink2 signing
230,140
def disable_signing ( self ) : self . mav . signing . secret_key = None self . mav . signing . sign_outgoing = False self . mav . signing . allow_unsigned_callback = None self . mav . signing . link_id = 0 self . mav . signing . timestamp = 0
disable MAVLink2 signing
230,141
def scan_timestamp ( self , tbuf ) : while True : ( tusec , ) = struct . unpack ( '>Q' , tbuf ) t = tusec * 1.0e-6 if abs ( t - self . _last_timestamp ) <= 3 * 24 * 60 * 60 : break c = self . f . read ( 1 ) if len ( c ) != 1 : break tbuf = tbuf [ 1 : ] + c return t
scan forward looking in a tlog for a timestamp in a reasonable range
230,142
def pre_message ( self ) : if self . filesize != 0 : self . percent = ( 100.0 * self . f . tell ( ) ) / self . filesize if self . notimestamps : return if self . planner_format : tbuf = self . f . read ( 21 ) if len ( tbuf ) != 21 or tbuf [ 0 ] != '-' or tbuf [ 20 ] != ':' : raise RuntimeError ( 'bad planner timestamp ...
read timestamp if needed
230,143
def post_message ( self , msg ) : super ( mavlogfile , self ) . post_message ( msg ) if self . planner_format : self . f . read ( 1 ) self . timestamp = msg . _timestamp self . _last_message = msg if msg . get_type ( ) != "BAD_DATA" : self . _last_timestamp = msg . _timestamp msg . _link = self . _link
add timestamp to message
230,144
def trigger ( self ) : tnow = time . time ( ) if tnow < self . last_time : print ( "Warning, time moved backwards. Restarting timer." ) self . last_time = tnow if self . last_time + ( 1.0 / self . frequency ) <= tnow : self . last_time = tnow return True return False
return True if we should trigger now
230,145
def write ( self , b ) : from . import mavutil self . debug ( "sending '%s' (0x%02x) of len %u\n" % ( b , ord ( b [ 0 ] ) , len ( b ) ) , 2 ) while len ( b ) > 0 : n = len ( b ) if n > 70 : n = 70 buf = [ ord ( x ) for x in b [ : n ] ] buf . extend ( [ 0 ] * ( 70 - len ( buf ) ) ) self . mav . mav . serial_control_send...
write some bytes
230,146
def _recv ( self ) : from . import mavutil start_time = time . time ( ) while time . time ( ) < start_time + self . timeout : m = self . mav . recv_match ( condition = 'SERIAL_CONTROL.count!=0' , type = 'SERIAL_CONTROL' , blocking = False , timeout = 0 ) if m is not None and m . count != 0 : break self . mav . mav . se...
read some bytes into self . buf
230,147
def read ( self , n ) : if len ( self . buf ) == 0 : self . _recv ( ) if len ( self . buf ) > 0 : if n > len ( self . buf ) : n = len ( self . buf ) ret = self . buf [ : n ] self . buf = self . buf [ n : ] if self . _debug >= 2 : for b in ret : self . debug ( "read 0x%x" % ord ( b ) , 2 ) return ret return ''
read some bytes
230,148
def flushInput ( self ) : self . buf = '' saved_timeout = self . timeout self . timeout = 0.5 self . _recv ( ) self . timeout = saved_timeout self . buf = '' self . debug ( "flushInput" )
flush any pending input
230,149
def stop ( self ) : self . mpstate . rl . set_prompt ( self . status . flightmode + "> " ) self . mpstate . functions . input_handler = None self . started = False mav = self . master . mav mav . serial_control_send ( self . serial_settings . port , 0 , 0 , self . serial_settings . baudrate , 0 , [ 0 ] * 70 )
stop nsh input
230,150
def cmd_nsh ( self , args ) : usage = "Usage: nsh <start|stop|set>" if len ( args ) < 1 : print ( usage ) return if args [ 0 ] == "start" : self . mpstate . functions . input_handler = self . send self . started = True self . mpstate . rl . set_prompt ( "" ) elif args [ 0 ] == "stop" : self . stop ( ) elif args [ 0 ] =...
nsh shell commands
230,151
def process_waypoint_request ( self , m , master ) : if ( not self . loading_waypoints or time . time ( ) > self . loading_waypoint_lasttime + 10.0 ) : self . loading_waypoints = False self . console . error ( "not loading waypoints" ) return if m . seq >= self . wploader . count ( ) : self . console . error ( "Request...
process a waypoint request from the master
230,152
def send_all_waypoints ( self ) : self . master . waypoint_clear_all_send ( ) if self . wploader . count ( ) == 0 : return self . loading_waypoints = True self . loading_waypoint_lasttime = time . time ( ) self . master . waypoint_count_send ( self . wploader . count ( ) )
send all waypoints to vehicle
230,153
def load_waypoints ( self , filename ) : self . wploader . target_system = self . target_system self . wploader . target_component = self . target_component try : self . wploader . load ( filename ) except Exception as msg : print ( "Unable to load %s - %s" % ( filename , msg ) ) return print ( "Loaded %u waypoints fro...
load waypoints from a file
230,154
def update_waypoints ( self , filename , wpnum ) : self . wploader . target_system = self . target_system self . wploader . target_component = self . target_component try : self . wploader . load ( filename ) except Exception as msg : print ( "Unable to load %s - %s" % ( filename , msg ) ) return if self . wploader . c...
update waypoints from a file
230,155
def get_default_frame ( self ) : if self . settings . terrainalt == 'Auto' : if self . get_mav_param ( 'TERRAIN_FOLLOW' , 0 ) == 1 : return mavutil . mavlink . MAV_FRAME_GLOBAL_TERRAIN_ALT return mavutil . mavlink . MAV_FRAME_GLOBAL_RELATIVE_ALT if self . settings . terrainalt == 'True' : return mavutil . mavlink . MAV...
default frame for waypoints
230,156
def wp_draw_callback ( self , points ) : if len ( points ) < 3 : return from MAVProxy . modules . lib import mp_util home = self . wploader . wp ( 0 ) self . wploader . clear ( ) self . wploader . target_system = self . target_system self . wploader . target_component = self . target_component self . wploader . add ( h...
callback from drawing waypoints
230,157
def wp_loop ( self ) : loader = self . wploader if loader . count ( ) < 2 : print ( "Not enough waypoints (%u)" % loader . count ( ) ) return wp = loader . wp ( loader . count ( ) - 2 ) if wp . command == mavutil . mavlink . MAV_CMD_DO_JUMP : print ( "Mission is already looped" ) return wp = mavutil . mavlink . MAVLink...
close the loop on a mission
230,158
def set_home_location ( self ) : try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ) return lat = float ( latlon [ 0 ] ) lon = float ( latlon [ 1 ] ) if self . wploader . count ( ) == 0 : self . wploader . add_latlonalt ( lat , lon , 0 ) w = self . wploader . wp ( 0 )...
set home location from last map click
230,159
def cmd_wp_move ( self , args ) : if len ( args ) != 1 : print ( "usage: wp move WPNUM" ) return idx = int ( args [ 0 ] ) if idx < 1 or idx > self . wploader . count ( ) : print ( "Invalid wp number %u" % idx ) return try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ...
handle wp move
230,160
def cmd_wp_param ( self , args ) : if len ( args ) < 2 : print ( "usage: wp param WPNUM PNUM <VALUE>" ) return idx = int ( args [ 0 ] ) if idx < 1 or idx > self . wploader . count ( ) : print ( "Invalid wp number %u" % idx ) return wp = self . wploader . wp ( idx ) param = [ wp . param1 , wp . param2 , wp . param3 , wp...
handle wp parameter change
230,161
def depthToRGB8 ( float_img_buff , encoding ) : gray_image = None if ( encoding [ - 3 : - 2 ] == "U" ) : gray_image = float_img_buff else : float_img = np . zeros ( ( float_img_buff . shape [ 0 ] , float_img_buff . shape [ 1 ] , 1 ) , dtype = "float32" ) float_img . data = float_img_buff . data gray_image = cv2 . conve...
Translates from Distance Image format to RGB . Inf values are represented by NaN when converting to RGB NaN passed to 0
230,162
def __callback ( self , img ) : image = imageMsg2Image ( img , self . bridge ) self . lock . acquire ( ) self . data = image self . lock . release ( )
Callback function to receive and save Images .
230,163
def noise ( ) : from random import gauss v = Vector3 ( gauss ( 0 , 1 ) , gauss ( 0 , 1 ) , gauss ( 0 , 1 ) ) v . normalize ( ) return v * args . noise
a noise vector
230,164
def find_offsets ( data , ofs ) : max_change = args . max_change gain = args . gain data2 = [ ] for d in data : d = d . copy ( ) + noise ( ) d . x = float ( int ( d . x + 0.5 ) ) d . y = float ( int ( d . y + 0.5 ) ) d . z = float ( int ( d . z + 0.5 ) ) data2 . append ( d ) data = data2 history_idx = 0 mag_history = d...
find mag offsets by applying Bills offsets revisited algorithm on the data
230,165
def set_menu ( self , menu ) : self . menu = menu self . in_queue . put ( MPImageMenu ( menu ) )
set a MPTopMenu on the frame
230,166
def set_popup_menu ( self , menu ) : self . popup_menu = menu self . in_queue . put ( MPImagePopupMenu ( menu ) )
set a popup menu on the frame
230,167
def image_coordinates ( self , point ) : ret = wx . Point ( int ( self . dragpos . x + point . x / self . zoom ) , int ( self . dragpos . y + point . y / self . zoom ) ) return ret
given a point in window coordinates calculate image coordinates
230,168
def redraw ( self ) : state = self . state if self . img is None : self . mainSizer . Fit ( self ) self . Refresh ( ) state . frame . Refresh ( ) self . SetFocus ( ) return size = self . frame . GetSize ( ) ( width , height ) = ( self . img . GetWidth ( ) , self . img . GetHeight ( ) ) rect = wx . Rect ( self . dragpos...
redraw the image with current settings
230,169
def limit_dragpos ( self ) : if self . dragpos . x < 0 : self . dragpos . x = 0 if self . dragpos . y < 0 : self . dragpos . y = 0 if self . img is None : return if self . dragpos . x >= self . img . GetWidth ( ) : self . dragpos . x = self . img . GetWidth ( ) - 1 if self . dragpos . y >= self . img . GetHeight ( ) : ...
limit dragpos to sane values
230,170
def on_drag_event ( self , event ) : state = self . state if not state . can_drag : return newpos = self . image_coordinates ( event . GetPosition ( ) ) dx = - ( newpos . x - self . mouse_down . x ) dy = - ( newpos . y - self . mouse_down . y ) self . dragpos = wx . Point ( self . dragpos . x + dx , self . dragpos . y ...
handle mouse drags
230,171
def show_popup_menu ( self , pos ) : self . popup_pos = self . image_coordinates ( pos ) self . frame . PopupMenu ( self . wx_popup_menu , pos )
show a popup menu
230,172
def on_key_event ( self , event ) : keycode = event . GetKeyCode ( ) if keycode == wx . WXK_HOME : self . zoom = 1.0 self . dragpos = wx . Point ( 0 , 0 ) self . need_redraw = True
handle key events
230,173
def on_event ( self , event ) : state = self . state if isinstance ( event , wx . MouseEvent ) : self . on_mouse_event ( event ) if isinstance ( event , wx . KeyEvent ) : self . on_key_event ( event ) if ( isinstance ( event , wx . MouseEvent ) and not event . ButtonIsDown ( wx . MOUSE_BTN_ANY ) and event . GetWheelRot...
pass events to the parent
230,174
def on_menu ( self , event ) : state = self . state if self . popup_menu is not None : ret = self . popup_menu . find_selected ( event ) if ret is not None : ret . popup_pos = self . popup_pos if ret . returnkey == 'fitWindow' : self . fit_to_window ( ) elif ret . returnkey == 'fullSize' : self . full_size ( ) else : s...
called on menu event
230,175
def set_menu ( self , menu ) : self . menu = menu wx_menu = menu . wx_menu ( ) self . frame . SetMenuBar ( wx_menu ) self . frame . Bind ( wx . EVT_MENU , self . on_menu )
add a menu from the parent
230,176
def set_popup_menu ( self , menu ) : self . popup_menu = menu if menu is None : self . wx_popup_menu = None else : self . wx_popup_menu = menu . wx_menu ( ) self . frame . Bind ( wx . EVT_MENU , self . on_menu )
add a popup menu from the parent
230,177
def fit_to_window ( self ) : state = self . state self . dragpos = wx . Point ( 0 , 0 ) client_area = state . frame . GetClientSize ( ) self . zoom = min ( float ( client_area . x ) / self . img . GetWidth ( ) , float ( client_area . y ) / self . img . GetHeight ( ) ) self . need_redraw = True
fit image to window
230,178
def full_size ( self ) : self . dragpos = wx . Point ( 0 , 0 ) self . zoom = 1.0 self . need_redraw = True
show image at full size
230,179
def mavmission ( logfile ) : mlog = mavutil . mavlink_connection ( filename ) wp = mavwp . MAVWPLoader ( ) while True : m = mlog . recv_match ( type = [ 'MISSION_ITEM' , 'CMD' , 'WAYPOINT' ] ) if m is None : break if m . get_type ( ) == 'CMD' : m = mavutil . mavlink . MAVLink_mission_item_message ( 0 , 0 , m . CNum , m...
extract mavlink mission
230,180
def message_checksum ( msg ) : from . mavcrc import x25crc crc = x25crc ( ) crc . accumulate_str ( msg . name + ' ' ) crc_end = msg . base_fields ( ) for i in range ( crc_end ) : f = msg . ordered_fields [ i ] crc . accumulate_str ( f . type + ' ' ) crc . accumulate_str ( f . name + ' ' ) if f . array_length : crc . ac...
calculate a 8 - bit checksum of the key fields of a message so we can detect incompatible XML changes
230,181
def merge_enums ( xml ) : emap = { } for x in xml : newenums = [ ] for enum in x . enum : if enum . name in emap : emapitem = emap [ enum . name ] if ( emapitem . start_value <= enum . highest_value and emapitem . highest_value >= enum . start_value ) : for entry in emapitem . entry : if entry . value <= enum . highest...
merge enums between XML files
230,182
def check_duplicates ( xml ) : merge_enums ( xml ) msgmap = { } enummap = { } for x in xml : for m in x . message : key = m . id if key in msgmap : print ( "ERROR: Duplicate message id %u for %s (%s:%u) also used by %s" % ( m . id , m . name , x . filename , m . linenumber , msgmap [ key ] ) ) return True fieldset = se...
check for duplicate message IDs
230,183
def total_msgs ( xml ) : count = 0 for x in xml : count += len ( x . message ) return count
count total number of msgs
230,184
def base_fields ( self ) : if self . extensions_start is None : return len ( self . fields ) return len ( self . fields [ : self . extensions_start ] )
return number of non - extended fields
230,185
def _dataflash_dir ( self , mpstate ) : if mpstate . settings . state_basedir is None : ret = 'dataflash' else : ret = os . path . join ( mpstate . settings . state_basedir , 'dataflash' ) try : os . makedirs ( ret ) except OSError as e : if e . errno != errno . EEXIST : print ( "DFLogger: OSError making (%s): %s" % ( ...
returns directory path to store DF logs in . May be relative
230,186
def new_log_filepath ( self ) : lastlog_filename = os . path . join ( self . dataflash_dir , 'LASTLOG.TXT' ) if os . path . exists ( lastlog_filename ) and os . stat ( lastlog_filename ) . st_size != 0 : fh = open ( lastlog_filename , 'rb' ) log_cnt = int ( fh . read ( ) ) + 1 fh . close ( ) else : log_cnt = 1 self . l...
returns a filepath to a log which does not currently exist and is suitable for DF logging
230,187
def start_new_log ( self ) : filename = self . new_log_filepath ( ) self . block_cnt = 0 self . logfile = open ( filename , 'w+b' ) print ( "DFLogger: logging started (%s)" % ( filename ) ) self . prev_cnt = 0 self . download = 0 self . prev_download = 0 self . last_idle_status_printed_time = time . time ( ) self . las...
open a new dataflash log reset state
230,188
def mavlink_packet ( self , m ) : now = time . time ( ) if m . get_type ( ) == 'REMOTE_LOG_DATA_BLOCK' : if self . stopped : if now - self . time_last_stop_packet_sent > 1 : if self . log_settings . verbose : print ( "DFLogger: Sending stop packet" ) self . master . mav . remote_log_block_status_send ( mavutil . mavlin...
handle REMOTE_LOG_DATA_BLOCK packets
230,189
def meminfo_send ( self , brkval , freemem , force_mavlink1 = False ) : return self . send ( self . meminfo_encode ( brkval , freemem ) , force_mavlink1 = force_mavlink1 )
state of APM memory
230,190
def older_message ( m , lastm ) : atts = { 'time_boot_ms' : 1.0e-3 , 'time_unix_usec' : 1.0e-6 , 'time_usec' : 1.0e-6 } for a in atts . keys ( ) : if hasattr ( m , a ) : mul = atts [ a ] t1 = m . getattr ( a ) * mul t2 = lastm . getattr ( a ) * mul if t2 >= t1 and t2 - t1 < 60 : return True return False
return true if m is older than lastm by timestamp
230,191
def process ( filename ) : print ( "Processing %s" % filename ) mlog = mavutil . mavlink_connection ( filename , notimestamps = args . notimestamps , robust_parsing = args . robust ) ext = os . path . splitext ( filename ) [ 1 ] isbin = ext in [ '.bin' , '.BIN' ] islog = ext in [ '.log' , '.LOG' ] output = None count =...
process one logfile
230,192
def handle_log_entry ( self , m ) : if m . time_utc == 0 : tstring = '' else : tstring = time . ctime ( m . time_utc ) self . entries [ m . id ] = m print ( "Log %u numLogs %u lastLog %u size %u %s" % ( m . id , m . num_logs , m . last_log_num , m . size , tstring ) )
handling incoming log entry
230,193
def handle_log_data_missing ( self ) : if len ( self . download_set ) == 0 : return highest = max ( self . download_set ) diff = set ( range ( highest ) ) . difference ( self . download_set ) if len ( diff ) == 0 : self . master . mav . log_request_data_send ( self . target_system , self . target_component , self . dow...
handling missing incoming log data
230,194
def log_status ( self ) : if self . download_filename is None : print ( "No download" ) return dt = time . time ( ) - self . download_start speed = os . path . getsize ( self . download_filename ) / ( 1000.0 * dt ) m = self . entries . get ( self . download_lognum , None ) if m is None : size = 0 else : size = m . size...
show download status
230,195
def log_download ( self , log_num , filename ) : print ( "Downloading log %u as %s" % ( log_num , filename ) ) self . download_lognum = log_num self . download_file = open ( filename , "wb" ) self . master . mav . log_request_data_send ( self . target_system , self . target_component , log_num , 0 , 0xFFFFFFFF ) self ....
download a log file
230,196
def idle_task ( self ) : if self . download_last_timestamp is not None and time . time ( ) - self . download_last_timestamp > 0.7 : self . download_last_timestamp = time . time ( ) self . handle_log_data_missing ( )
handle missing log data
230,197
def complete_modules ( text ) : import MAVProxy . modules , pkgutil modlist = [ x [ 1 ] for x in pkgutil . iter_modules ( MAVProxy . modules . __path__ ) ] ret = [ ] loaded = set ( complete_loadedmodules ( '' ) ) for m in modlist : if not m . startswith ( "mavproxy_" ) : continue name = m [ 9 : ] if not name in loaded ...
complete mavproxy module names
230,198
def complete_filename ( text ) : list = glob . glob ( text + '*' ) for idx , val in enumerate ( list ) : if os . path . isdir ( val ) : list [ idx ] = ( val + os . path . sep ) return list
complete a filename
230,199
def complete_variable ( text ) : if text . find ( '.' ) != - 1 : var = text . split ( '.' ) [ 0 ] if var in rline_mpstate . status . msgs : ret = [ ] for f in rline_mpstate . status . msgs [ var ] . get_fieldnames ( ) : ret . append ( var + '.' + f ) return ret return [ ] return rline_mpstate . status . msgs . keys ( )
complete a MAVLink variable