[Unit]
Description=FB-RTK driver (roslaunch fbrtkros fbrtk_driver.launch)
After=network.target

[Service]
Type=simple
PermissionsStartOnly=true
User=cat
Restart=on-failure
RestartSec=5

# Wait shortly for device to appear, then set permissive mode so non-root user can access it
ExecStartPre=/bin/sh -c 'for i in 1 2 3 4 5 6 7 8 9 10; do [ -e /dev/ttyACM2 ] && break || sleep 1; done'
ExecStartPre=/bin/chmod 777 /dev/ttyACM2

WorkingDirectory=/home/cat/catkin_ws

# Run the start script as user 'cat' (PermissionsStartOnly keeps ExecStartPre running as root)
ExecStart=/bin/bash -lc '/home/cat/catkin_ws/src/fb-rtkros/start/start_fbrtk_driver.sh'

Environment=ROS_HOME=/home/cat/.ros

[Install]
WantedBy=multi-user.target
