Skip to content

Commit 4ea3b9f

Browse files
jmachuca77peterbarker
authored andcommitted
Add Source Component ID parameter to connect function to allow setting a different comp ID than 0. Default to 0 to make it backwards compatible.
1 parent 0eb7715 commit 4ea3b9f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

dronekit/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,7 @@ def connect(ip,
30943094
baud=115200,
30953095
heartbeat_timeout=30,
30963096
source_system=255,
3097+
source_component=0,
30973098
use_native=False):
30983099
"""
30993100
Returns a :py:class:`Vehicle` object connected to the address specified by string parameter ``ip``.
@@ -3130,6 +3131,7 @@ def connect(ip,
31303131
:param int heartbeat_timeout: Connection timeout value in seconds (default is 30s).
31313132
If a heartbeat is not detected within this time an exception will be raised.
31323133
:param int source_system: The MAVLink ID of the :py:class:`Vehicle` object returned by this method (by default 255).
3134+
:param int source_component: The MAVLink Component ID fo the :py:class:`Vehicle` object returned by this method (by default 0).
31333135
:param bool use_native: Use precompiled MAVLink parser.
31343136
31353137
.. note::
@@ -3154,7 +3156,7 @@ def connect(ip,
31543156
if not vehicle_class:
31553157
vehicle_class = Vehicle
31563158

3157-
handler = MAVConnection(ip, baud=baud, source_system=source_system, use_native=use_native)
3159+
handler = MAVConnection(ip, baud=baud, source_system=source_system, source_component=source_component, use_native=use_native)
31583160
vehicle = vehicle_class(handler)
31593161

31603162
if status_printer:

dronekit/mavlink.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def read(self):
3939

4040
class mavudpin_multi(mavutil.mavfile):
4141
'''a UDP mavlink socket'''
42-
def __init__(self, device, baud=None, input=True, broadcast=False, source_system=255, use_native=mavutil.default_native):
42+
def __init__(self, device, baud=None, input=True, broadcast=False, source_system=255, source_component=0, use_native=mavutil.default_native):
4343
self._logger = logging.getLogger(__name__)
4444
a = device.split(':')
4545
if len(a) != 2:
@@ -59,7 +59,7 @@ def __init__(self, device, baud=None, input=True, broadcast=False, source_system
5959
self.broadcast = True
6060
mavutil.set_close_on_exec(self.port.fileno())
6161
self.port.setblocking(False)
62-
mavutil.mavfile.__init__(self, self.port.fileno(), device, source_system=source_system, input=input, use_native=use_native)
62+
mavutil.mavfile.__init__(self, self.port.fileno(), device, source_system=source_system, source_component=source_component, input=input, use_native=use_native)
6363

6464
def close(self):
6565
self.port.close()
@@ -121,20 +121,21 @@ def stop_threads(self):
121121
self.mavlink_thread_out.join()
122122
self.mavlink_thread_out = None
123123

124-
def __init__(self, ip, baud=115200, target_system=0, source_system=255, use_native=False):
124+
def __init__(self, ip, baud=115200, target_system=0, source_system=255, source_component=0, use_native=False):
125125
self._logger = logging.getLogger(__name__)
126126

127127
if ip.startswith("udpin:"):
128-
self.master = mavudpin_multi(ip[6:], input=True, baud=baud, source_system=source_system)
128+
self.master = mavudpin_multi(ip[6:], input=True, baud=baud, source_system=source_system, source_component=source_component)
129129
else:
130-
self.master = mavutil.mavlink_connection(ip, baud=baud, source_system=source_system)
130+
self.master = mavutil.mavlink_connection(ip, baud=baud, source_system=source_system, source_component=source_component)
131131

132132
# TODO get rid of "master" object as exposed,
133133
# keep it private, expose something smaller for dronekit
134134
self.out_queue = Queue()
135135
self.master.mav = mavutil.mavlink.MAVLink(
136136
MAVWriter(self.out_queue),
137137
srcSystem=self.master.source_system,
138+
srcComponent=self.master.source_component,
138139
use_native=use_native)
139140

140141
# Monkey-patch MAVLink object for fix_targets.

0 commit comments

Comments
 (0)