← Documents Documentation/networking/device_drivers/can/can327.rst GitHub 원문 ↗

Linux 6.18.37 · Networking

can327: ELM327 driver for Linux SocketCAN

ELM327 serial OBD interface를 SocketCAN device로 사용하는 line discipline 설정, text protocol과 version별 제한을 설명합니다.

Source pathDocumentation/networking/device_drivers/can/can327.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

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에 중요한 제한이 있습니다.

can327 data path
USB·Bluetooth ELM327TTY `/dev/ttyUSB0``ldattach` line discipline 30`can0`SocketCAN`candump`·`cansniffer`

정체를 자동 인식하지 못하는 serial device를 사용자가 SocketCAN interface에 연결합니다.

Mode switching
Command mode`ATSH` target 설정Hex data frame 송신`ATR1` reply 대기Reception modeFrame line 수신
Reply timeout·silent bus·error`ATMA` monitor계속 수신
새 송신 요청Monitor 중단Command mode

ELM327의 두 mode를 오가며 송신과 수신을 번갈아 수행합니다.

Serial·CAN 초기 설정
계층설정
SerialBaud38400
SerialData·parity·stop8 data bits, no parity, 1 stop bit
TTYLine discipline30
CAN일반 OBD-II bitrate500000 bit/s
CANParameter 변경Interface down 상태에서

Factory serial setting과 일반적인 OBD-II CAN bitrate입니다.

Line discipline 연결
ELM327 serial setting 확인`ldattach ... 30 /dev/ttyUSB0``can0 down``type can bitrate 500000``can0 up`SocketCAN tool 사용

Serial 조건을 먼저 맞춘 뒤 CAN bitrate를 설정합니다.

CAN text frame 형식
FrameELM327 line해석
SFF`123 8 DEADBEEF12345678`11-bit ID `0x123`, DLC 8
EFF`12 34 56 78 8 DEADBEEF12345678`29-bit ID, DLC 8
Overflow`... DEADBEEF123 BUFFER FULL`마지막 frame 불완전 가능

공백 배치로 SFF와 EFF address를 구분합니다.

SFF frame 송신
`AT PB`로 SFF mode`ATSH123``OK``DEADBEEF12345678``OK`CAN ID `0x123` frame

Header command와 payload command를 순서대로 보냅니다.

Controller version 제한
대상제한
Clone `v1.5` 등RTR 송신 drop, RTR 수신 왜곡, `AT CSM` 미지원 가능
모든 versionFull-duplex 없음, RTR length 설정 불가, real-time error 없음
< 1.4b`AT MA` 중 ACK 없음, `listen-only` 제한
< 1.4`AT PB` 없음, runtime bitrate·SFF/EFF 변경 불가
< 1.3`AT D1` 없음, can327 사용 불가

최소 권장 version은 1.4b이며 1.3 미만은 사용할 수 없습니다.

Driver 제한
항목현재 동작영향
8/7 timing미구현`500000/n` 이외 일부 속도 사용 불가
Command response`OK`·`?` 미검사지원하지 않는 command를 감지하지 못함
Hardware CAN ID filter미사용Heavy bus에서 UART overflow 위험
CAN error`AT CS` polling 안 함Real-time notification 없음

Controller capability와 SocketCAN interface 사이에 남은 구현 공백입니다.

초기 command 근거
Command설정필요한 이유
`AT E1`Echo onPrompt를 안정적으로 검출
`AT S1`Spaces on11-bit·29-bit address 구분
`AT D1`DLC onRTR length와 frame 완전성 확인

Text stream을 안정적으로 parse하기 위한 필수 설정입니다.

BUFFER FULL 복구
Heavy CAN trafficELM327 UART buffer 포화Monitoring 중단불완전 frame + `BUFFER FULL` 가능Command modeDriver가 `AT MA`로 monitoring 재개

UART overflow는 frame과 error text가 같은 line에 섞일 수 있는 핵심 failure mode입니다.

CAN termination 위치
연결 위치Adapter resistor조치
OBD-II socket endpointTermination이 적절할 수 있음그대로 사용
기존 CAN bus 중간 tap추가 termination이 부적절통신 실패 시 PCB resistor 제거 검토

OBD-II endpoint와 기존 bus 중간 tap은 termination 요구가 다릅니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2
3 can327: ELM327 driver for Linux SocketCAN
4 ==========================================
5
6 Authors
7 --------
8
9 Max Staudt <max@enpas.org>
10
11
12
13 Motivation
14 -----------
15
16 This driver aims to lower the initial cost for hackers interested in
17 working with CAN buses.
18
19 CAN adapters are expensive, few, and far between.
20 ELM327 interfaces are cheap and plentiful.
21 Let's use ELM327s as CAN adapters.
22
23
24
25 Introduction
26 -------------
27
28 This driver is an effort to turn abundant ELM327 based OBD interfaces
29 into full fledged (as far as possible) CAN interfaces.
30
31 Since the ELM327 was never meant to be a stand alone CAN controller,
32 the driver has to switch between its modes as quickly as possible in
33 order to fake full-duplex operation.
34
35 As such, can327 is a best effort driver. However, this is more than
36 enough to implement simple request-response protocols (such as OBD II),
37 and to monitor broadcast messages on a bus (such as in a vehicle).
38
39 Most ELM327s come as nondescript serial devices, attached via USB or
40 Bluetooth. The driver cannot recognize them by itself, and as such it
41 is up to the user to attach it in form of a TTY line discipline
42 (similar to PPP, SLIP, slcan, ...).
43
44 This driver is meant for ELM327 versions 1.4b and up, see below for
45 known limitations in older controllers and clones.
46
47
48
49 Data sheet
50 -----------
51
52 The official data sheets can be found at ELM electronics' home page:
53
54 https://www.elmelectronics.com/
55
56
57
58 How to attach the line discipline
59 ----------------------------------
60
61 Every ELM327 chip is factory programmed to operate at a serial setting
62 of 38400 baud/s, 8 data bits, no parity, 1 stopbit.
63
64 If you have kept this default configuration, the line discipline can
65 be attached on a command prompt as follows::
66
67 sudo ldattach \
68 --debug \
69 --speed 38400 \
70 --eightbits \
71 --noparity \
72 --onestopbit \
73 --iflag -ICRNL,INLCR,-IXOFF \
74 30 \
75 /dev/ttyUSB0
76
77 To change the ELM327's serial settings, please refer to its data
78 sheet. This needs to be done before attaching the line discipline.
79
80 Once the ldisc is attached, the CAN interface starts out unconfigured.
81 Set the speed before starting it::
82
83 # The interface needs to be down to change parameters
84 sudo ip link set can0 down
85 sudo ip link set can0 type can bitrate 500000
86 sudo ip link set can0 up
87
88 500000 bit/s is a common rate for OBD-II diagnostics.
89 If you're connecting straight to a car's OBD port, this is the speed
90 that most cars (but not all!) expect.
91
92 After this, you can set out as usual with candump, cansniffer, etc.
93
94
95
96 How to check the controller version
97 ------------------------------------
98
99 Use a terminal program to attach to the controller.
100
101 After issuing the "``AT WS``" command, the controller will respond with
102 its version::
103
104 >AT WS
105
106
107 ELM327 v1.4b
108
109 >
110
111 Note that clones may claim to be any version they like.
112 It is not indicative of their actual feature set.
113
114
115
116
117 Communication example
118 ----------------------
119
120 This is a short and incomplete introduction on how to talk to an ELM327.
121 It is here to guide understanding of the controller's and the driver's
122 limitation (listed below) as well as manual testing.
123
124
125 The ELM327 has two modes:
126
127 - Command mode
128 - Reception mode
129
130 In command mode, it expects one command per line, terminated by CR.
131 By default, the prompt is a "``>``", after which a command can be
132 entered::
133
134 >ATE1
135 OK
136 >
137
138 The init script in the driver switches off several configuration options
139 that are only meaningful in the original OBD scenario the chip is meant
140 for, and are actually a hindrance for can327.
141
142
143 When a command is not recognized, such as by an older version of the
144 ELM327, a question mark is printed as a response instead of OK::
145
146 >ATUNKNOWN
147 ?
148 >
149
150 At present, can327 does not evaluate this response. See the section
151 below on known limitations for details.
152
153
154 When a CAN frame is to be sent, the target address is configured, after
155 which the frame is sent as a command that consists of the data's hex
156 dump::
157
158 >ATSH123
159 OK
160 >DEADBEEF12345678
161 OK
162 >
163
164 The above interaction sends the SFF frame "``DE AD BE EF 12 34 56 78``"
165 with (11 bit) CAN ID ``0x123``.
166 For this to function, the controller must be configured for SFF sending
167 mode (using "``AT PB``", see code or datasheet).
168
169
170 Once a frame has been sent and wait-for-reply mode is on (``ATR1``,
171 configured on ``listen-only=off``), or when the reply timeout expires
172 and the driver sets the controller into monitoring mode (``ATMA``),
173 the ELM327 will send one line for each received CAN frame, consisting
174 of CAN ID, DLC, and data::
175
176 123 8 DEADBEEF12345678
177
178 For EFF (29 bit) CAN frames, the address format is slightly different,
179 which can327 uses to tell the two apart::
180
181 12 34 56 78 8 DEADBEEF12345678
182
183 The ELM327 will receive both SFF and EFF frames - the current CAN
184 config (``ATPB``) does not matter.
185
186
187 If the ELM327's internal UART sending buffer runs full, it will abort
188 the monitoring mode, print "BUFFER FULL" and drop back into command
189 mode. Note that in this case, unlike with other error messages, the
190 error message may appear on the same line as the last (usually
191 incomplete) data frame::
192
193 12 34 56 78 8 DEADBEEF123 BUFFER FULL
194
195
196
197 Known limitations of the controller
198 ------------------------------------
199
200 - Clone devices ("v1.5" and others)
201
202 Sending RTR frames is not supported and will be dropped silently.
203
204 Receiving RTR with DLC 8 will appear to be a regular frame with
205 the last received frame's DLC and payload.
206
207 "``AT CSM``" (CAN Silent Monitoring, i.e. don't send CAN ACKs) is
208 not supported, and is hard coded to ON. Thus, frames are not ACKed
209 while listening: "``AT MA``" (Monitor All) will always be "silent".
210 However, immediately after sending a frame, the ELM327 will be in
211 "receive reply" mode, in which it *does* ACK any received frames.
212 Once the bus goes silent, or an error occurs (such as BUFFER FULL),
213 or the receive reply timeout runs out, the ELM327 will end reply
214 reception mode on its own and can327 will fall back to "``AT MA``"
215 in order to keep monitoring the bus.
216
217 Other limitations may apply, depending on the clone and the quality
218 of its firmware.
219
220
221 - All versions
222
223 No full duplex operation is supported. The driver will switch
224 between input/output mode as quickly as possible.
225
226 The length of outgoing RTR frames cannot be set. In fact, some
227 clones (tested with one identifying as "``v1.5``") are unable to
228 send RTR frames at all.
229
230 We don't have a way to get real-time notifications on CAN errors.
231 While there is a command (``AT CS``) to retrieve some basic stats,
232 we don't poll it as it would force us to interrupt reception mode.
233
234
235 - Versions prior to 1.4b
236
237 These versions do not send CAN ACKs when in monitoring mode (AT MA).
238 However, they do send ACKs while waiting for a reply immediately
239 after sending a frame. The driver maximizes this time to make the
240 controller as useful as possible.
241
242 Starting with version 1.4b, the ELM327 supports the "``AT CSM``"
243 command, and the "listen-only" CAN option will take effect.
244
245
246 - Versions prior to 1.4
247
248 These chips do not support the "``AT PB``" command, and thus cannot
249 change bitrate or SFF/EFF mode on-the-fly. This will have to be
250 programmed by the user before attaching the line discipline. See the
251 data sheet for details.
252
253
254 - Versions prior to 1.3
255
256 These chips cannot be used at all with can327. They do not support
257 the "``AT D1``" command, which is necessary to avoid parsing conflicts
258 on incoming data, as well as distinction of RTR frame lengths.
259
260 Specifically, this allows for easy distinction of SFF and EFF
261 frames, and to check whether frames are complete. While it is possible
262 to deduce the type and length from the length of the line the ELM327
263 sends us, this method fails when the ELM327's UART output buffer
264 overruns. It may abort sending in the middle of the line, which will
265 then be mistaken for something else.
266
267
268
269 Known limitations of the driver
270 --------------------------------
271
272 - No 8/7 timing.
273
274 ELM327 can only set CAN bitrates that are of the form 500000/n, where
275 n is an integer divisor.
276 However there is an exception: With a separate flag, it may set the
277 speed to be 8/7 of the speed indicated by the divisor.
278 This mode is not currently implemented.
279
280 - No evaluation of command responses.
281
282 The ELM327 will reply with OK when a command is understood, and with ?
283 when it is not. The driver does not currently check this, and simply
284 assumes that the chip understands every command.
285 The driver is built such that functionality degrades gracefully
286 nevertheless. See the section on known limitations of the controller.
287
288 - No use of hardware CAN ID filtering
289
290 An ELM327's UART sending buffer will easily overflow on heavy CAN bus
291 load, resulting in the "``BUFFER FULL``" message. Using the hardware
292 filters available through "``AT CF xxx``" and "``AT CM xxx``" would be
293 helpful here, however SocketCAN does not currently provide a facility
294 to make use of such hardware features.
295
296
297
298 Rationale behind the chosen configuration
299 ------------------------------------------
300
301 ``AT E1``
302 Echo on
303
304 We need this to be able to get a prompt reliably.
305
306 ``AT S1``
307 Spaces on
308
309 We need this to distinguish 11/29 bit CAN addresses received.
310
311 Note:
312 We can usually do this using the line length (odd/even),
313 but this fails if the line is not transmitted fully to
314 the host (BUFFER FULL).
315
316 ``AT D1``
317 DLC on
318
319 We need this to tell the "length" of RTR frames.
320
321
322
323 A note on CAN bus termination
324 ------------------------------
325
326 Your adapter may have resistors soldered in which are meant to terminate
327 the bus. This is correct when it is plugged into a OBD-II socket, but
328 not helpful when trying to tap into the middle of an existing CAN bus.
329
330 If communications don't work with the adapter connected, check for the
331 termination resistors on its PCB and try removing them.
332

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

목적, best-effort 설계와 지원 controller

1-57

can327: Linux SocketCAN용 ELM327 driver

저자

Max Staudt `<max@enpas.org>`

동기

이 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 <max@enpas.org>



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-116

Line 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-268

Controller의 알려진 제한

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-297

Driver의 알려진 제한

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.