"""
espnow_relay.launch.py — Launch ESP-NOW to ROS2 serial relay.

Usage:
    ros2 launch saltybot_uwb_espnow_relay espnow_relay.launch.py
    ros2 launch saltybot_uwb_espnow_relay espnow_relay.launch.py \\
        serial_port:=/dev/ttyUSB3
"""

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
import os


def generate_launch_description() -> LaunchDescription:
    pkg_dir = get_package_share_directory("saltybot_uwb_espnow_relay")
    params_file = os.path.join(pkg_dir, "config", "espnow_relay_params.yaml")

    serial_port_arg = DeclareLaunchArgument(
        "serial_port",
        default_value="/dev/espnow-relay",
        description="USB serial port for ESP-NOW receiver ESP32",
    )

    relay_node = Node(
        package="saltybot_uwb_espnow_relay",
        executable="espnow_relay",
        name="espnow_relay",
        parameters=[
            params_file,
            {"serial_port": LaunchConfiguration("serial_port")},
        ],
        output="screen",
        emulate_tty=True,
    )

    return LaunchDescription([
        serial_port_arg,
        relay_node,
    ])
