Skip to content

Commit

Permalink
core: ardupilot-manager: Allow to plug more than one serial board
Browse files Browse the repository at this point in the history
This commit changes the way serial devices are detected.

Instead of relying on UDEV rules it uses `pyserial` to detect available serial devices.

With UDEV rules, we can only detect one at a given time. With those changes, the limitation no longer exists.

The validation rules (manufacturer and product name) are kept.
  • Loading branch information
rafaellehmkuhl authored and patrickelectric committed Mar 16, 2022
1 parent d554d19 commit f4efb31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List, Optional

from loguru import logger
from serial.tools.list_ports_linux import comports
from serial.tools.list_ports_linux import SysFS, comports
from smbus2 import SMBus

from typedefs import FlightController, Platform
Expand Down Expand Up @@ -53,26 +53,27 @@ def is_navigator_r5_connected() -> bool:
logger.debug("No Navigator board detected.")
return None

@staticmethod
def is_valid_serial_controller(port: SysFS) -> bool:
return port.manufacturer == "ArduPilot" or (port.manufacturer == "3D Robotics" and "PX4" in port.product)

@staticmethod
def detect_serial_flight_controllers() -> List[FlightController]:
"""Check if a Pixhawk1 or any other valid serial flight controller is connected.
Returns:
List[FlightController]: List with connected serial flight controller.
"""
serial_path = "/dev/autopilot"
for port in comports(include_links=True):
if not port.device == serial_path:
continue
return [
FlightController(
name=port.product or port.name,
manufacturer=port.manufacturer,
platform=Platform.Pixhawk1,
path=serial_path,
)
]
return []
return [
FlightController(
name=port.product or port.name,
manufacturer=port.manufacturer,
platform=Platform.Pixhawk1,
path=port.device,
)
for port in comports()
if Detector.is_valid_serial_controller(port)
]

@classmethod
def detect(cls) -> List[FlightController]:
Expand Down
3 changes: 0 additions & 3 deletions install/udev/100.autopilot.rules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
SUBSYSTEM=="tty", ATTRS{manufacturer}=="3D Robotics", ATTRS{product}=="PX4*", SYMLINK+="autopilot", ENV{ID_MM_DEVICE_IGNORE}="1", ENV{ID_MM_PORT_IGNORE}="1"
SUBSYSTEM=="tty", ATTRS{manufacturer}=="ArduPilot", SYMLINK+="autopilot", ENV{ID_MM_DEVICE_IGNORE}="1", ENV{ID_MM_PORT_IGNORE}="1"

# CP210X USB UART
ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE:="0666", ENV{ID_MM_DEVICE_IGNORE}="1", ENV{ID_MM_PORT_IGNORE}="1"

Expand Down

0 comments on commit f4efb31

Please sign in to comment.