PCAN-USB(PEAK-System)를 사용한 SocketCAN
10441 단어 RaspberryPican
개요
peak_usb.ko
합니다.컨디션
2016-11-25-raspbian-jessie
(GUI의 Wireshark를 사용하면 이쪽)2016-11-25-raspbian-jessie-lite
PCAN-USB
& PCAN-USB FD
(PEAK-System) 절차.
sudo apt update ; sudo apt upgrade -y
로 변환sudo apt install -y bc build-essential libpopt-dev rpi-update
펌웨어 업데이트
sudo rpi-update
또는 sudo rpi-update af9cb14d5053f89857225bd18d1df59a089c171e
#(4.4.38-v7+#938의 경우)Kernel source 가져오기, 압축 풀기, 모듈 구축 준비
개구쟁이
#
# Retrieve kernel source
FIRMWARE_REV=`cat /boot/.firmware_revision` # rpi-update generates.
KERNEL_REV=`curl -L https://github.com/Hexxeh/rpi-firmware/raw/${FIRMWARE_REV}/git_hash`
echo Firmware Rev: ${FIRMWARE_REV}
echo kernel Rev : ${KERNEL_REV}
curl -L https://github.com/Hexxeh/rpi-firmware/raw/${FIRMWARE_REV}/Module.symvers >Module.symvers
curl -L https://github.com/Hexxeh/rpi-firmware/raw/${FIRMWARE_REV}/Module7.symvers >Module7.symvers
curl -L https://github.com/raspberrypi/linux/archive/${KERNEL_REV}.tar.gz >rpi-linux.tar.gz
#
# Extract
sudo mkdir -p /usr/src/rpi-linux
sudo chown pi.pi -R /usr/src/rpi-linux
cd /usr/src/rpi-linux
tar --strip-components 1 -xf ${HOME}/rpi-linux.tar.gz
#
# Place Module.symvers and .config to the proper folder.
sudo modprobe configs
gunzip -c /proc/config.gz >.config
sudo rmmod configs
[ -e /lib/modules/$(uname -r)/build ] || sudo ln -sv /usr/src/rpi-linux /lib/modules/$(uname -r)/build
# cp $HOME/Module.symvers Module.symvers ## RPi1 ????
cp $HOME/Module7.symvers Module.symvers
#
구축:
peak_usb.ko
개구쟁이cd /usr/src/rpi-linux
sed -i -e 's/# CONFIG_CAN_PEAK_USB is not set/CONFIG_CAN_PEAK_USB=m/g' .config
make oldconfig
make modules_prepare
cd drivers/net/can/usb/peak_usb
make -C /usr/src/rpi-linux M=`pwd` clean
make -C /usr/src/rpi-linux M=`pwd` modules
#
# !! This copies to Not "4.4.xx-v7+" but "/lib/modules/4.4.xx-v7/extra/"
# sudo make -C /usr/src/rpi-linux M=`pwd` modules_install
#
# Manually copied
sudo mkdir -p /lib/modules/`uname -r`/kernel/drivers/net/can/usb/peak_usb
sudo cp -v ./*.ko /lib/modules/`uname -r`/kernel/drivers/net/can/usb/peak_usb
#
# おまじない、して、再起動.
sudo depmod -a
sudo reboot
PCAN-USB 연결
읽기
peak_usb
및 can_dev
.실행 예
pi@raspberrypi:~ $ lsmod
Module Size Used by
peak_usb 27417 0
can_dev 9907 1 peak_usb
bnep 10340 2
bluetooth 326105 5 bnep
cfg80211 428431 0
rfkill 16037 3 cfg80211,bluetooth
snd_bcm2835 20447 1
snd_pcm 75762 1 snd_bcm2835
snd_timer 19288 1 snd_pcm
snd 51908 5 snd_bcm2835,snd_timer,snd_pcm
bcm2835_gpiomem 3040 0
bcm2835_wdt 3225 0
uio_pdrv_genirq 3164 0
uio 8000 1 uio_pdrv_genirq
i2c_dev 5859 0
fuse 84037 3
ipv6 347594 65
pi@raspberrypi:~ $ lsusb
Bus 001 Device 004: ID 0c72:0012 PEAK System
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@raspberrypi:~ $
pi@raspberrypi:~ $ sudo ip link set can0 type can bitrate 500000
pi@raspberrypi:~ $ ifconfig can0
can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
NOARP MTU:16 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
사용 예
사용한 부적(비트레이트가 환경에 적합하도록 지정)
sudo ip link set can0 type can bitrate 500000
sudo ifconfig can0 up
can-utils - SocketCAN userspace utilities and tools
도구 설치
sudo apt install -y can-utils
메시지 덤프
candump -cae -t z can0,0:0,#FFFFFFFF
msgid는 xxxxxxx...pi@raspberrypi:~/can-utils$ ./candump -cae -t z can0,0:0,#FFFFFFFF
(000.000000) can0 xxxxxxxx [8] 01 20 34 F3 34 F3 34 F3 '. 4.4.4.'
(000.000464) can0 xxxxxxxx [6] 01 43 34 F3 34 F3 '.C4.4.'
(000.001028) can0 xxxxxxxx [8] 08 20 34 F3 34 F3 00 00 '. 4.4...'
(000.001603) can0 xxxxxxxx [8] 08 00 00 00 00 00 00 00 '........'
...
wireshark / tshark
도구 설치
sudo apt-get install -y wireshark tshark
#
#>Configuring wireshark-common
# --> YES!
# <Yes> wiresharkグループに所属する、nonsuperuserがパケットキャップできる.
# <No> rootだけ.
#
sudo usermod -aG wireshark pi
# logout and login
실행 예
tshark
pi@raspberrypi:~ $ tshark -D # List interfaces
1. eth0
2. can0
3. any
4. lo (Loopback)
5. nflog
6. nfqueue
7. usbmon1
pi@raspberrypi:~ $ tshark -i 2 # Interface Index
Capturing on 'can0'
1 0.000000 -> CAN 16 STD: 0x00000123 02 7e d0 37 4e bd d0 17
2 0.009879 -> CAN 16 STD: 0x00000223 02 7e d0 37 4e bd d0 17
3 0.019870 -> CAN 16 STD: 0x00000443 02 7e d0 37 4e bd d0 17
4 0.029968 -> CAN 16 STD: 0x00000342 02 7e d0 37 4e bd d0 17
5 0.039877 -> CAN 16 STD: 0x00000123 02 7e d0 37 4e bd d0 17
Reference
이 문제에 관하여(PCAN-USB(PEAK-System)를 사용한 SocketCAN), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/mt08/items/cd853d318b336e2b0fde텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)