Skip to content

system: keep sysid/compid when connect() is called again - #840

Open
vishwagw wants to merge 2 commits into
mavlink:mainfrom
vishwagw:fix-reconnect-keeps-sysid-compid
Open

vishwagw wants to merge 2 commits into
mavlink:mainfrom
vishwagw:fix-reconnect-keeps-sysid-compid

Conversation

@vishwagw

Copy link
Copy Markdown
Contributor

Problem

Calling System.connect() a second time (e.g. to reconnect) restarts mavsdk_server.
Before restarting, _stop_mavsdk_server() calls self.__init__(port=self._port).
That resets every constructor argument except port, so the new server is started with the
default MAVLink IDs instead of the ones the user chose:

drone = System(port=50060, sysid=1, compid=191)
await drone.connect("udpin://0.0.0.0:14540")   # mavsdk_server started with sysid=1,   compid=191
await drone.connect("udpin://0.0.0.0:14540")   # mavsdk_server started with sysid=245, compid=190

After a reconnect, a companion computer or multi-vehicle setup that relies on a fixed
sysid/compid quietly gets the defaults.

Fix

_stop_mavsdk_server() now resets only the per-connection state (_server_process,
_plugins, and the "localhost" address that connect() set) and leaves port, sysid
and compid as they were. Behaviour is otherwise unchanged:

  • a reconnect still kills the old server and starts a new one;
  • with a user-supplied mavsdk_server_address, nothing is started or stopped (as before).

Tests

Adds tests/test_system.py (pytest, no running mavsdk_server needed:
_start_mavsdk_server and _init_plugins are mocked):

  • reconnect keeps port/sysid/compid. This fails on main and passes with this change;
  • reconnect kills the previous server process and starts a new one;
  • an external mavsdk_server_address is never started or stopped.

Run with python3 -m pytest tests from the repo root. CI doesn't run pytest yet. I'm happy
to add a step to main.yml here or in a follow-up, whichever you prefer.

Reset connection state and clean up plugins when stopping the mavsdk_server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant