요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
can327: ELM327 driver for Linux SocketCAN
==========================================
Authors
--------
Max Staudt <[email protected]>
Motivation
-----------
This driver aims to lower the initial cost for hackers interested in
working with CAN buses.
CAN adapters are expensive, few, and far between.
ELM327 interfaces are cheap and plentiful.
Let's use ELM327s as CAN adapters.
Introduction
-------------
This driver is an effort to turn abundant ELM327 based OBD interfaces
into full fledged (as far as possible) CAN interfaces.
Since the ELM327 was never meant to be a stand alone CAN controller,
the driver has to switch between its modes as quickly as possible in
order to fake full-duplex operation.
As such, can327 is a best effort driver. However, this is more than
enough to implement simple request-response protocols (such as OBD II),
and to monitor broadcast messages on a bus (such as in a vehicle).
Most ELM327s come as nondescript serial devices, attached via USB or
Bluetooth. The driver cannot recognize them by itself, and as such it
is up to the user to attach it in form of a TTY line discipline
(similar to PPP, SLIP, slcan, ...).
This driver is meant for ELM327 versions 1.4b and up, see below for
known limitations in older controllers and clones.
Data sheet
-----------
The official data sheets can be found at ELM electronics' home page:
https://www.elmelectronics.com/
How to attach the line discipline
----------------------------------
Every ELM327 chip is factory programmed to operate at a serial setting
of 38400 baud/s, 8 data bits, no parity, 1 stopbit.
If you have kept this default configuration, the line discipline can
be attached on a command prompt as follows::
sudo ldattach \
--debug \
--speed 38400 \
--eightbits \
--noparity \
--onestopbit \
--iflag -ICRNL,INLCR,-IXOFF \
30 \
/dev/ttyUSB0
To change the ELM327's serial settings, please refer to its data
sheet. This needs to be done before attaching the line discipline.
Once the ldisc is attached, the CAN interface starts out unconfigured.
Set the speed before starting it::
# The interface needs to be down to change parameters
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 500000
sudo ip link set can0 up
500000 bit/s is a common rate for OBD-II diagnostics.
If you're connecting straight to a car's OBD port, this is the speed
that most cars (but not all!) expect.
After this, you can set out as usual with candump, cansniffer, etc.
How to check the controller version
------------------------------------
Use a terminal program to attach to the controller.
After issuing the "``AT WS``" command, the controller will respond with
its version::
>AT WS
ELM327 v1.4b
>
Note that clones may claim to be any version they like.
It is not indicative of their actual feature set.
Communication example
----------------------
This is a short and incomplete introduction on how to talk to an ELM327.
It is here to guide understanding of the controller's and the driver's
limitation (listed below) as well as manual testing.
The ELM327 has two modes:
- Command mode
- Reception mode
In command mode, it expects one command per line, terminated by CR.
By default, the prompt is a "``>``", after which a command can be
entered::
>ATE1
OK
>
The init script in the driver switches off several configuration options
that are only meaningful in the original OBD scenario the chip is meant
for, and are actually a hindrance for can327.
When a command is not recognized, such as by an older version of the
ELM327, a question mark is printed as a response instead of OK::
>ATUNKNOWN
?
>
At present, can327 does not evaluate this response. See the section
below on known limitations for details.
When a CAN frame is to be sent, the target address is configured, after
which the frame is sent as a command that consists of the data's hex
dump::
>ATSH123
OK
>DEADBEEF12345678
OK
>
The above interaction sends the SFF frame "``DE AD BE EF 12 34 56 78``"
with (11 bit) CAN ID ``0x123``.
For this to function, the controller must be configured for SFF sending
mode (using "``AT PB``", see code or datasheet).
Once a frame has been sent and wait-for-reply mode is on (``ATR1``,
configured on ``listen-only=off``), or when the reply timeout expires
and the driver sets the controller into monitoring mode (``ATMA``),
the ELM327 will send one line for each received CAN frame, consisting
of CAN ID, DLC, and data::
123 8 DEADBEEF12345678
For EFF (29 bit) CAN frames, the address format is slightly different,
which can327 uses to tell the two apart::
12 34 56 78 8 DEADBEEF12345678
The ELM327 will receive both SFF and EFF frames - the current CAN
config (``ATPB``) does not matter.
If the ELM327's internal UART sending buffer runs full, it will abort
the monitoring mode, print "BUFFER FULL" and drop back into command
mode. Note that in this case, unlike with other error messages, the
error message may appear on the same line as the last (usually
incomplete) data frame::
12 34 56 78 8 DEADBEEF123 BUFFER FULL
Known limitations of the controller
------------------------------------
- Clone devices ("v1.5" and others)
Sending RTR frames is not supported and will be dropped silently.
Receiving RTR with DLC 8 will appear to be a regular frame with
the last received frame's DLC and payload.
"``AT CSM``" (CAN Silent Monitoring, i.e. don't send CAN ACKs) is
not supported, and is hard coded to ON. Thus, frames are not ACKed
while listening: "``AT MA``" (Monitor All) will always be "silent".
However, immediately after sending a frame, the ELM327 will be in
"receive reply" mode, in which it *does* ACK any received frames.
Once the bus goes silent, or an error occurs (such as BUFFER FULL),
or the receive reply timeout runs out, the ELM327 will end reply
reception mode on its own and can327 will fall back to "``AT MA``"
in order to keep monitoring the bus.
Other limitations may apply, depending on the clone and the quality
of its firmware.
- All versions
No full duplex operation is supported. The driver will switch
between input/output mode as quickly as possible.
The length of outgoing RTR frames cannot be set. In fact, some
clones (tested with one identifying as "``v1.5``") are unable to
send RTR frames at all.
We don't have a way to get real-time notifications on CAN errors.
While there is a command (``AT CS``) to retrieve some basic stats,
we don't poll it as it would force us to interrupt reception mode.
- Versions prior to 1.4b
These versions do not send CAN ACKs when in monitoring mode (AT MA).
However, they do send ACKs while waiting for a reply immediately
after sending a frame. The driver maximizes this time to make the
controller as useful as possible.
Starting with version 1.4b, the ELM327 supports the "``AT CSM``"
command, and the "listen-only" CAN option will take effect.
- Versions prior to 1.4
These chips do not support the "``AT PB``" command, and thus cannot
change bitrate or SFF/EFF mode on-the-fly. This will have to be
programmed by the user before attaching the line discipline. See the
data sheet for details.
- Versions prior to 1.3
These chips cannot be used at all with can327. They do not support
the "``AT D1``" command, which is necessary to avoid parsing conflicts
on incoming data, as well as distinction of RTR frame lengths.
Specifically, this allows for easy distinction of SFF and EFF
frames, and to check whether frames are complete. While it is possible
to deduce the type and length from the length of the line the ELM327
sends us, this method fails when the ELM327's UART output buffer
overruns. It may abort sending in the middle of the line, which will
then be mistaken for something else.
Known limitations of the driver
--------------------------------
- No 8/7 timing.
ELM327 can only set CAN bitrates that are of the form 500000/n, where
n is an integer divisor.
However there is an exception: With a separate flag, it may set the
speed to be 8/7 of the speed indicated by the divisor.
This mode is not currently implemented.
- No evaluation of command responses.
The ELM327 will reply with OK when a command is understood, and with ?
when it is not. The driver does not currently check this, and simply
assumes that the chip understands every command.
The driver is built such that functionality degrades gracefully
nevertheless. See the section on known limitations of the controller.
- No use of hardware CAN ID filtering
An ELM327's UART sending buffer will easily overflow on heavy CAN bus
load, resulting in the "``BUFFER FULL``" message. Using the hardware
filters available through "``AT CF xxx``" and "``AT CM xxx``" would be
helpful here, however SocketCAN does not currently provide a facility
to make use of such hardware features.
Rationale behind the chosen configuration
------------------------------------------
``AT E1``
Echo on
We need this to be able to get a prompt reliably.
``AT S1``
Spaces on
We need this to distinguish 11/29 bit CAN addresses received.
Note:
We can usually do this using the line length (odd/even),
but this fails if the line is not transmitted fully to
the host (BUFFER FULL).
``AT D1``
DLC on
We need this to tell the "length" of RTR frames.
A note on CAN bus termination
------------------------------
Your adapter may have resistors soldered in which are meant to terminate
the bus. This is correct when it is plugged into a OBD-II socket, but
not helpful when trying to tap into the middle of an existing CAN bus.
If communications don't work with the adapter connected, check for the
termination resistors on its PCB and try removing them.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
목적, best-effort 설계와 지원 controller
1-57can327: Linux SocketCAN용 ELM327 driver
저자
Max Staudt `<[email protected]>`
동기
이 driver의 목표는 CAN bus를 다루려는 hacker의 초기 비용을 낮추는 것입니다.
CAN adapter는 비싸고 종류와 공급도 적지만 ELM327 interface는 저렴하고 흔합니다. 따라서 ELM327을 CAN adapter로 사용합니다.
소개
이 driver는 널리 보급된 ELM327 기반 OBD interface를 가능한 범위에서 완전한 CAN interface로 바꾸려는 시도입니다.
ELM327은 독립형 CAN controller로 설계되지 않았으므로 driver는 full-duplex처럼 동작하게 보이기 위해 여러 mode를 가능한 한 빠르게 전환해야 합니다.
따라서 `can327`은 best-effort driver입니다. 그래도 OBD-II 같은 단순 request-response protocol을 구현하거나 차량 bus의 broadcast message를 monitor하기에는 충분합니다.
대부분의 ELM327은 USB 또는 Bluetooth를 통해 연결되는 정체가 뚜렷하지 않은 serial device로 나타납니다. Driver가 device를 스스로 식별할 수 없으므로 사용자가 PPP, SLIP, `slcan` 등과 비슷한 TTY line discipline 형태로 연결해야 합니다.
이 driver는 ELM327 version 1.4b 이상을 대상으로 합니다. 더 오래된 controller와 clone의 알려진 제한은 아래에 설명합니다.
Data sheet
공식 data sheet는 ELM electronics homepage에서 찾을 수 있습니다: https://www.elmelectronics.com/
.. SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
can327: ELM327 driver for Linux SocketCAN
==========================================
Authors
--------
Max Staudt <[email protected]>
Motivation
-----------
This driver aims to lower the initial cost for hackers interested in
working with CAN buses.
CAN adapters are expensive, few, and far between.
ELM327 interfaces are cheap and plentiful.
Let's use ELM327s as CAN adapters.
Introduction
-------------
This driver is an effort to turn abundant ELM327 based OBD interfaces
into full fledged (as far as possible) CAN interfaces.
Since the ELM327 was never meant to be a stand alone CAN controller,
the driver has to switch between its modes as quickly as possible in
order to fake full-duplex operation.
As such, can327 is a best effort driver. However, this is more than
enough to implement simple request-response protocols (such as OBD II),
and to monitor broadcast messages on a bus (such as in a vehicle).
Most ELM327s come as nondescript serial devices, attached via USB or
Bluetooth. The driver cannot recognize them by itself, and as such it
is up to the user to attach it in form of a TTY line discipline
(similar to PPP, SLIP, slcan, ...).
This driver is meant for ELM327 versions 1.4b and up, see below for
known limitations in older controllers and clones.
Data sheet
-----------
The official data sheets can be found at ELM electronics' home page:
https://www.elmelectronics.com/
TTY line discipline 연결과 controller version 확인
58-116Line discipline을 연결하는 방법
모든 ELM327 chip은 출고 시 serial setting이 38400 baud/s, data bit 8개, parity 없음, stop bit 1개로 program되어 있습니다.
기본 configuration을 유지했다면 command prompt에서 다음과 같이 line discipline을 연결할 수 있습니다.
sudo ldattach \
--debug \
--speed 38400 \
--eightbits \
--noparity \
--onestopbit \
--iflag -ICRNL,INLCR,-IXOFF \
30 \
/dev/ttyUSB0
ELM327 serial setting을 변경하려면 data sheet를 참고하십시오. 이 변경은 line discipline을 연결하기 전에 해야 합니다.
Line discipline을 연결하면 CAN interface는 미구성 상태로 시작합니다. Interface를 시작하기 전에 bitrate를 설정하십시오.
# The interface needs to be down to change parameters
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 500000
sudo ip link set can0 up
500000 bit/s는 OBD-II 진단에서 흔한 속도입니다. 차량 OBD port에 직접 연결한다면 대부분의 차량이 이 속도를 기대하지만 모든 차량이 그런 것은 아닙니다.
설정이 끝나면 `candump`, `cansniffer` 같은 일반 SocketCAN tool을 사용할 수 있습니다.
Controller version을 확인하는 방법
Terminal program으로 controller에 연결합니다.
`AT WS` command를 보내면 controller가 version을 응답합니다.
>AT WS
ELM327 v1.4b
>
Clone은 원하는 version을 임의로 표시할 수 있으므로 이 문자열이 실제 feature set을 보장하지는 않습니다.
How to attach the line discipline
----------------------------------
Every ELM327 chip is factory programmed to operate at a serial setting
of 38400 baud/s, 8 data bits, no parity, 1 stopbit.
If you have kept this default configuration, the line discipline can
be attached on a command prompt as follows::
sudo ldattach \
--debug \
--speed 38400 \
--eightbits \
--noparity \
--onestopbit \
--iflag -ICRNL,INLCR,-IXOFF \
30 \
/dev/ttyUSB0
To change the ELM327's serial settings, please refer to its data
sheet. This needs to be done before attaching the line discipline.
Once the ldisc is attached, the CAN interface starts out unconfigured.
Set the speed before starting it::
# The interface needs to be down to change parameters
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 500000
sudo ip link set can0 up
500000 bit/s is a common rate for OBD-II diagnostics.
If you're connecting straight to a car's OBD port, this is the speed
that most cars (but not all!) expect.
After this, you can set out as usual with candump, cansniffer, etc.
How to check the controller version
------------------------------------
Use a terminal program to attach to the controller.
After issuing the "``AT WS``" command, the controller will respond with
its version::
>AT WS
ELM327 v1.4b
>
Note that clones may claim to be any version they like.
It is not indicative of their actual feature set.
Command·reception mode와 CAN frame 송수신
117-196통신 예
다음 내용은 ELM327과 통신하는 방법을 짧고 불완전하게 소개합니다. 아래에 나열한 controller·driver 제한을 이해하고 수동 시험을 하는 데 도움을 주기 위한 설명입니다.
ELM327에는 두 mode가 있습니다.
- Command mode
- Reception mode
Command mode에서는 CR로 끝나는 command를 한 줄에 하나씩 받습니다. 기본 prompt는 `>`이며 그 뒤에 command를 입력할 수 있습니다.
>ATE1
OK
>
Driver의 init script는 chip의 원래 OBD 용도에서만 의미가 있고 `can327`에는 방해가 되는 여러 configuration option을 끕니다.
구형 ELM327 version처럼 command를 인식하지 못하면 `OK` 대신 물음표를 응답합니다.
>ATUNKNOWN
?
>
현재 `can327`은 이 응답을 평가하지 않습니다. 자세한 내용은 아래의 알려진 제한 절을 참고하십시오.
CAN frame을 보내려면 먼저 target address를 configure한 뒤 data hex dump로 이루어진 command를 보냅니다.
>ATSH123
OK
>DEADBEEF12345678
OK
>
위 상호작용은 11-bit CAN ID `0x123`으로 SFF frame `DE AD BE EF 12 34 56 78`을 보냅니다. 이 동작을 하려면 controller를 `AT PB`로 SFF 송신 mode에 configure해야 합니다. 자세한 내용은 code나 data sheet를 참고하십시오.
Frame을 보낸 뒤 wait-for-reply mode가 켜져 있거나(`ATR1`, `listen-only=off`일 때 설정), reply timeout이 만료되어 driver가 controller를 monitoring mode(`ATMA`)로 바꾸면 ELM327은 수신 CAN frame마다 CAN ID, DLC, data로 이루어진 한 줄을 보냅니다.
123 8 DEADBEEF12345678
EFF(29-bit) CAN frame은 address 형식이 조금 다르며 `can327`은 이 차이로 SFF와 EFF를 구분합니다.
12 34 56 78 8 DEADBEEF12345678
ELM327은 SFF와 EFF frame을 모두 수신하며 현재 CAN configuration인 `ATPB` 값은 이에 영향을 주지 않습니다.
ELM327 내부 UART 송신 buffer가 가득 차면 monitoring mode를 중단하고 `BUFFER FULL`을 출력한 뒤 command mode로 돌아갑니다. 다른 error message와 달리 이 message는 마지막 data frame과 같은 줄에 나타날 수 있으며, 그 frame은 보통 불완전합니다.
12 34 56 78 8 DEADBEEF123 BUFFER FULL
Communication example
----------------------
This is a short and incomplete introduction on how to talk to an ELM327.
It is here to guide understanding of the controller's and the driver's
limitation (listed below) as well as manual testing.
The ELM327 has two modes:
- Command mode
- Reception mode
In command mode, it expects one command per line, terminated by CR.
By default, the prompt is a "``>``", after which a command can be
entered::
>ATE1
OK
>
The init script in the driver switches off several configuration options
that are only meaningful in the original OBD scenario the chip is meant
for, and are actually a hindrance for can327.
When a command is not recognized, such as by an older version of the
ELM327, a question mark is printed as a response instead of OK::
>ATUNKNOWN
?
>
At present, can327 does not evaluate this response. See the section
below on known limitations for details.
When a CAN frame is to be sent, the target address is configured, after
which the frame is sent as a command that consists of the data's hex
dump::
>ATSH123
OK
>DEADBEEF12345678
OK
>
The above interaction sends the SFF frame "``DE AD BE EF 12 34 56 78``"
with (11 bit) CAN ID ``0x123``.
For this to function, the controller must be configured for SFF sending
mode (using "``AT PB``", see code or datasheet).
Once a frame has been sent and wait-for-reply mode is on (``ATR1``,
configured on ``listen-only=off``), or when the reply timeout expires
and the driver sets the controller into monitoring mode (``ATMA``),
the ELM327 will send one line for each received CAN frame, consisting
of CAN ID, DLC, and data::
123 8 DEADBEEF12345678
For EFF (29 bit) CAN frames, the address format is slightly different,
which can327 uses to tell the two apart::
12 34 56 78 8 DEADBEEF12345678
The ELM327 will receive both SFF and EFF frames - the current CAN
config (``ATPB``) does not matter.
If the ELM327's internal UART sending buffer runs full, it will abort
the monitoring mode, print "BUFFER FULL" and drop back into command
mode. Note that in this case, unlike with other error messages, the
error message may appear on the same line as the last (usually
incomplete) data frame::
12 34 56 78 8 DEADBEEF123 BUFFER FULL
Clone과 ELM327 version별 controller 제한
197-268Controller의 알려진 제한
Clone device(`v1.5` 등)
RTR frame 송신은 지원하지 않으며 조용히 drop됩니다.
DLC 8인 RTR frame을 수신하면 마지막으로 받은 frame의 DLC와 payload를 가진 일반 frame처럼 나타납니다.
`AT CSM`(CAN Silent Monitoring, 즉 CAN ACK를 보내지 않음)은 지원하지 않으며 ON으로 hard-code되어 있습니다. 따라서 listen 중에는 frame을 ACK하지 않고 `AT MA`(Monitor All)는 항상 silent입니다.
하지만 frame을 보낸 직후 ELM327은 `receive reply` mode에 들어가며 이 mode에서는 수신 frame을 ACK합니다. Bus가 silent해지거나 `BUFFER FULL` 같은 error가 발생하거나 reply timeout이 끝나면 ELM327은 스스로 reply reception mode를 끝냅니다. 그러면 `can327`은 bus monitoring을 계속하기 위해 `AT MA`로 fallback합니다.
Clone과 firmware 품질에 따라 다른 제한도 있을 수 있습니다.
모든 version
Full-duplex 동작을 지원하지 않습니다. Driver는 input과 output mode를 최대한 빠르게 전환합니다.
송신 RTR frame의 길이를 설정할 수 없습니다. 실제로 `v1.5`라고 식별된 일부 clone은 RTR frame 자체를 전혀 보내지 못합니다.
CAN error의 real-time notification을 받을 방법이 없습니다. 기본 statistic을 가져오는 `AT CS` command가 있지만 이를 polling하면 reception mode를 중단해야 하므로 사용하지 않습니다.
Version 1.4b 이전
이 version은 monitoring mode(`AT MA`)에서 CAN ACK를 보내지 않습니다. 다만 frame을 보낸 직후 reply를 기다리는 동안에는 ACK를 보냅니다. Driver는 controller의 활용도를 높이기 위해 이 시간을 최대화합니다.
Version 1.4b부터 ELM327은 `AT CSM` command를 지원하며 CAN의 `listen-only` option이 실제로 적용됩니다.
Version 1.4 이전
이 chip은 `AT PB` command를 지원하지 않아 bitrate나 SFF/EFF mode를 실행 중에 바꿀 수 없습니다. 사용자가 line discipline을 연결하기 전에 직접 program해야 합니다. 자세한 내용은 data sheet를 참고하십시오.
Version 1.3 이전
이 chip은 `can327`과 함께 전혀 사용할 수 없습니다. 수신 data parsing conflict를 피하고 RTR frame 길이를 구분하는 데 필요한 `AT D1` command를 지원하지 않기 때문입니다.
`AT D1`은 SFF와 EFF frame을 쉽게 구분하고 frame이 완전한지 확인하게 합니다. ELM327이 보내는 line 길이로 type과 길이를 추론할 수도 있지만 UART output buffer가 넘치면 이 방법은 실패합니다. Line 중간에서 송신이 중단되어 다른 형식으로 잘못 해석될 수 있기 때문입니다.
Known limitations of the controller
------------------------------------
- Clone devices ("v1.5" and others)
Sending RTR frames is not supported and will be dropped silently.
Receiving RTR with DLC 8 will appear to be a regular frame with
the last received frame's DLC and payload.
"``AT CSM``" (CAN Silent Monitoring, i.e. don't send CAN ACKs) is
not supported, and is hard coded to ON. Thus, frames are not ACKed
while listening: "``AT MA``" (Monitor All) will always be "silent".
However, immediately after sending a frame, the ELM327 will be in
"receive reply" mode, in which it *does* ACK any received frames.
Once the bus goes silent, or an error occurs (such as BUFFER FULL),
or the receive reply timeout runs out, the ELM327 will end reply
reception mode on its own and can327 will fall back to "``AT MA``"
in order to keep monitoring the bus.
Other limitations may apply, depending on the clone and the quality
of its firmware.
- All versions
No full duplex operation is supported. The driver will switch
between input/output mode as quickly as possible.
The length of outgoing RTR frames cannot be set. In fact, some
clones (tested with one identifying as "``v1.5``") are unable to
send RTR frames at all.
We don't have a way to get real-time notifications on CAN errors.
While there is a command (``AT CS``) to retrieve some basic stats,
we don't poll it as it would force us to interrupt reception mode.
- Versions prior to 1.4b
These versions do not send CAN ACKs when in monitoring mode (AT MA).
However, they do send ACKs while waiting for a reply immediately
after sending a frame. The driver maximizes this time to make the
controller as useful as possible.
Starting with version 1.4b, the ELM327 supports the "``AT CSM``"
command, and the "listen-only" CAN option will take effect.
- Versions prior to 1.4
These chips do not support the "``AT PB``" command, and thus cannot
change bitrate or SFF/EFF mode on-the-fly. This will have to be
programmed by the user before attaching the line discipline. See the
data sheet for details.
- Versions prior to 1.3
These chips cannot be used at all with can327. They do not support
the "``AT D1``" command, which is necessary to avoid parsing conflicts
on incoming data, as well as distinction of RTR frame lengths.
Specifically, this allows for easy distinction of SFF and EFF
frames, and to check whether frames are complete. While it is possible
to deduce the type and length from the length of the line the ELM327
sends us, this method fails when the ELM327's UART output buffer
overruns. It may abort sending in the middle of the line, which will
then be mistaken for something else.
can327 driver의 bitrate·응답·filter 제한
269-297Driver의 알려진 제한
8/7 timing 없음
ELM327은 정수 divisor n에 대해 `500000/n` 형태의 CAN bitrate만 설정할 수 있습니다. 별도 flag를 쓰면 divisor가 나타내는 속도의 8/7로 설정하는 예외가 있지만 이 mode는 현재 구현되지 않았습니다.
Command 응답을 평가하지 않음
ELM327은 이해한 command에 `OK`, 이해하지 못한 command에 `?`를 응답합니다. Driver는 이를 검사하지 않고 chip이 모든 command를 이해한다고 가정합니다.
그럼에도 driver는 기능이 점진적으로 저하되도록 구성되어 있습니다. Controller의 알려진 제한 절을 참고하십시오.
Hardware CAN ID filtering을 사용하지 않음
CAN bus load가 높으면 ELM327 UART 송신 buffer가 쉽게 overflow하여 `BUFFER FULL` message가 발생합니다. `AT CF xxx`와 `AT CM xxx`가 제공하는 hardware filter를 쓰면 도움이 되지만 현재 SocketCAN에는 이런 hardware feature를 사용할 facility가 없습니다.
Known limitations of the driver
--------------------------------
- No 8/7 timing.
ELM327 can only set CAN bitrates that are of the form 500000/n, where
n is an integer divisor.
However there is an exception: With a separate flag, it may set the
speed to be 8/7 of the speed indicated by the divisor.
This mode is not currently implemented.
- No evaluation of command responses.
The ELM327 will reply with OK when a command is understood, and with ?
when it is not. The driver does not currently check this, and simply
assumes that the chip understands every command.
The driver is built such that functionality degrades gracefully
nevertheless. See the section on known limitations of the controller.
- No use of hardware CAN ID filtering
An ELM327's UART sending buffer will easily overflow on heavy CAN bus
load, resulting in the "``BUFFER FULL``" message. Using the hardware
filters available through "``AT CF xxx``" and "``AT CM xxx``" would be
helpful here, however SocketCAN does not currently provide a facility
to make use of such hardware features.
초기 command 선택 이유와 CAN bus termination
298-331선택한 configuration의 근거
`AT E1`: Echo on
Prompt를 안정적으로 얻기 위해 echo가 필요합니다.
`AT S1`: Spaces on
수신한 11-bit와 29-bit CAN address를 구분하기 위해 공백이 필요합니다.
참고: 보통은 line 길이의 홀수·짝수로 구분할 수 있지만 `BUFFER FULL`로 line 전체가 host에 전달되지 않으면 이 방법은 실패합니다.
`AT D1`: DLC on
RTR frame의 `length`를 알기 위해 DLC가 필요합니다.
CAN bus termination 참고
Adapter에는 bus termination을 위한 resistor가 납땜되어 있을 수 있습니다. OBD-II socket에 꽂을 때는 올바른 구성이지만 기존 CAN bus 중간을 tap하려는 경우에는 도움이 되지 않습니다.
Adapter를 연결했을 때 통신이 되지 않으면 PCB의 termination resistor를 확인하고 제거해 보십시오.
Rationale behind the chosen configuration
------------------------------------------
``AT E1``
Echo on
We need this to be able to get a prompt reliably.
``AT S1``
Spaces on
We need this to distinguish 11/29 bit CAN addresses received.
Note:
We can usually do this using the line length (odd/even),
but this fails if the line is not transmitted fully to
the host (BUFFER FULL).
``AT D1``
DLC on
We need this to tell the "length" of RTR frames.
A note on CAN bus termination
------------------------------
Your adapter may have resistors soldered in which are meant to terminate
the bus. This is correct when it is plugged into a OBD-II socket, but
not helpful when trying to tap into the middle of an existing CAN bus.
If communications don't work with the adapter connected, check for the
termination resistors on its PCB and try removing them.
요약·해설
can327.rst:1-331`can327`은 저렴한 ELM327 OBD serial interface를 TTY line discipline으로 연결해 SocketCAN에서 쓰게 하는 best-effort driver입니다. ELM327이 독립형 CAN controller가 아니므로 command와 reception mode를 빠르게 오가며 full-duplex를 흉내 냅니다. 간단한 OBD-II request-response와 bus monitoring에는 유용하지만 version·clone·UART buffer·RTR·error reporting에 중요한 제한이 있습니다.
정체를 자동 인식하지 못하는 serial device를 사용자가 SocketCAN interface에 연결합니다.
ELM327의 두 mode를 오가며 송신과 수신을 번갈아 수행합니다.
Factory serial setting과 일반적인 OBD-II CAN bitrate입니다.
Serial 조건을 먼저 맞춘 뒤 CAN bitrate를 설정합니다.
공백 배치로 SFF와 EFF address를 구분합니다.
Header command와 payload command를 순서대로 보냅니다.
최소 권장 version은 1.4b이며 1.3 미만은 사용할 수 없습니다.
Controller capability와 SocketCAN interface 사이에 남은 구현 공백입니다.
Text stream을 안정적으로 parse하기 위한 필수 설정입니다.
UART overflow는 frame과 error text가 같은 line에 섞일 수 있는 핵심 failure mode입니다.
OBD-II endpoint와 기존 bus 중간 tap은 termination 요구가 다릅니다.