# Setup hardware support on the main AI machine on kitt
# This includes:
#  - configuring gpsd to use data from /dev/ttyS0
#  - disabling hotplug on gpsd so that it doesn't conflict with SBG
#     ( see SYSINT-65 )
#  - building and installing the SBG detect program
#  - installing the udev rules for SBG
---
- block:
  - name: Install gpsd
    apt:
      name:
        - "gpsd"
        - "gpsd-clients"
      cache_valid_time: "{{ apt_cache_valid_time }}"

  - name: Configure gpsd
    copy:
      src: gpsd
      dest: /etc/default/
    notify: Restart gpsd

  # install sbg_detect binary
  - name: Install sbg_detect
    get_url:
      # This was built using `bazel build //vehicle/sbg_gateway:sbg_detect`
      url: "{{ sbg_detect.url }}"
      dest: "/usr/local/bin/sbg_detect"
      checksum: "sha256:{{ sbg_detect.sha256 }}"
      mode: '755'


  # install the udev rule that uses sbg_detect
  - name: Install SBG udev rules
    copy:
      src: 50-usb-gps-sbg.rules
      dest: /etc/udev/rules.d/


  # TODO(TOOL-2475): need serial number in udev rules? Can we just use the device/vendor ID?
  - name: Install AP-40 udev rules
    copy:
      src: 50-usb-gps-ap40.rules
      dest: /etc/udev/rules.d/
      force: no

  become: yes
