gpsinit 2.9 KB

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