问题背景:在测试tx2 can通信时,每次开机需要单独运行两条命令
sudo ip link set can0 type can bitrate 500000(意思是设置CAN0通道波特率为500kb/s)
sudo ip link set up can0(意思是将CAN0通道开启)
但是我们用tx2肯定是希望每次开机程序跑起来以后直接将运算得到的CAN信号传输给车辆底层的啊,每次开机再来开启CAN通道、设置波特率啥的岂不是开玩笑!!!
基于上述原因,要设置开机自启脚本,具体参考了这篇博客:https://blog.csdn.net/qq_19004627/article/details/80661468
这篇博客中提到有A、B两种方法,经过多次尝试,本人用的TX2上第二种方法不成功,因此采用了A方法:
/etc/rc.local脚本是一个ubuntu16.04及其以前的系统中自带的开机脚本,在没有修改之前里面内容如下:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0
那么我要加入CAN的开机启动项以后的效果是啥样的呢,看下面这段代码
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0
exit 0
接下来重启就生效了,ok,解决,问题不一样可能具体解决方案不一样啊,此方法仅用于记录个人学习过程中遇到及解决的问题!