gpsinit 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. #
  3. # gpsinit - initialize kernel-CAN interfaces
  4. #
  5. # This file is Copyright (c) 2012 by the GPSD project.
  6. # SPDX-License-Identifier: BSD-2-clause
  7. #
  8. speed=38400
  9. net=0
  10. version()
  11. {
  12. echo `basename $0`" : Version v0.20";
  13. }
  14. usage()
  15. {
  16. version; echo;
  17. echo "usage :" `basename $0` "[-n <netnumber>] [-s <serial speed>] <can_module_name> [<interface_name>]";
  18. echo " :" `basename $0` "-v";
  19. echo " :" `basename $0` "-h";
  20. echo " Options include:";
  21. echo " -n = CAN network number, 0 if not given.";
  22. echo " -s = Speed of the slcan hardware port, 38400 if not given.";
  23. echo " = Needed for some slcan modules only.";
  24. echo " -v = Print version of this script and exit.";
  25. echo " -h = Print this help message and exit.";
  26. echo " can_module_name = One out of plx_pci, esd_usb2, usb_8dev, vcan, slcan, beaglebone.";
  27. echo " interface_name = The interface, the SLCAN module is connected to, i.e. /dev/ttyS0 or /dev/ttyUSB0.";
  28. echo " = Needed for the slcan module only. The default is /dev/ttyUSB0.";
  29. echo "Root permissions are needed for the first calling option (Enforced by socketCAN subsystem).";
  30. }
  31. while getopts :n:s:vh opt
  32. do
  33. case ${opt} in
  34. n) net=${OPTARG};;
  35. s) speed=${OPTARG};;
  36. v) version; exit 0;;
  37. h) usage; exit 0;;
  38. \?) usage; exit 1;;
  39. esac
  40. done
  41. shift $((${OPTIND} - 1))
  42. candevice=$1
  43. case ${candevice} in
  44. plx_pci)
  45. # For the SJA1000 based PCI or PCI-Express CAN interface
  46. modprobe plx_pci;
  47. ip link set can${net} type can tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1;
  48. ip link set can${net} up;;
  49. esd_usb2)
  50. # For an esd usb/2 CAN interface
  51. modprobe esd_usb2;
  52. ip link set can${net} type can tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1;
  53. ip link set can${net} up;;
  54. usb_8dev)
  55. # For an 8devices usb2can CAN interface
  56. modprobe usb_8dev;
  57. ip link set can${net} type can tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1;
  58. ip link set can${net} up;;
  59. vcan)
  60. # With this setup, CAN frames can be injected into vcan0 by a test
  61. modprobe vcan;
  62. ip link add type vcan;
  63. ip link set vcan${net} up;;
  64. slcan)
  65. # For a serial line CAN device
  66. # No support for devices, that need a setup of the baudrate yet
  67. device=${2:-/dev/ttyUSB0};
  68. modprobe slcan;
  69. slcan_attach -f -s5 -o ${device};
  70. slcand `basename ${device}`;
  71. ip link set slcan${net} up;;
  72. beaglebone)
  73. # For CAN interface on a BeagleBone
  74. # The d_can driver is part of the kernel
  75. ip link set can${net} type can bitrate 250000 sjw 1;
  76. ip link set can${net} up;;
  77. *)
  78. echo `basename ${0}` ": invalid CAN interface ${1} net${net} device ${2:-(none)}"
  79. echo;
  80. usage;
  81. exit 1
  82. esac