← Documents Documentation/userspace-api/media/rc/lirc-write.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API / Media / Remote Controller

LIRC write()

PULSE sequence 또는 하나의 lirc_scancode를 LIRC 장치로 송신합니다.

Source pathDocumentation/userspace-api/media/rc/lirc-write.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

lirc-write.rst:1-72

PULSE mode는 홀수 개 pulse/space sample, SCANCODE mode는 나머지 member가 0인 structure 하나를 요구합니다. 두 mode 모두 hardware 송신 완료까지 block하며 반환 byte 수를 확인해야 합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: RC
3
4 .. _lirc-write:
5
6 ************
7 LIRC write()
8 ************
9
10 Name
11 ====
12
13 lirc-write - Write to a LIRC device
14
15 Synopsis
16 ========
17
18 .. code-block:: c
19
20 #include <unistd.h>
21
22 .. c:function:: ssize_t write( int fd, void *buf, size_t count )
23
24 Arguments
25 =========
26
27 ``fd``
28 File descriptor returned by ``open()``.
29
30 ``buf``
31 Buffer with data to be written
32
33 ``count``
34 Number of bytes at the buffer
35
36 Description
37 ===========
38
39 :c:func:`write()` writes up to ``count`` bytes to the device
40 referenced by the file descriptor ``fd`` from the buffer starting at
41 ``buf``.
42
43 The exact format of the data depends on what mode a driver is in, use
44 :ref:`lirc_get_features` to get the supported modes and use
45 :ref:`lirc_set_send_mode` set the mode.
46
47 When in :ref:`LIRC_MODE_PULSE <lirc-mode-PULSE>` mode, the data written to
48 the chardev is a pulse/space sequence of integer values. Pulses and spaces
49 are only marked implicitly by their position. The data must start and end
50 with a pulse, therefore, the data must always include an uneven number of
51 samples. The write function blocks until the data has been transmitted
52 by the hardware. If more data is provided than the hardware can send, the
53 driver returns ``EINVAL``.
54
55 When in :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` mode, one
56 ``struct lirc_scancode`` must be written to the chardev at a time, else
57 ``EINVAL`` is returned. Set the desired scancode in the ``scancode`` member,
58 and the :ref:`IR protocol <Remote_controllers_Protocols>` in the
59 :c:type:`rc_proto`: member. All other members must be
60 set to 0, else ``EINVAL`` is returned. If there is no protocol encoder
61 for the protocol or the scancode is not valid for the specified protocol,
62 ``EINVAL`` is returned. The write function blocks until the scancode
63 is transmitted by the hardware.
64
65 Return Value
66 ============
67
68 On success, the number of bytes written is returned. It is not an error if
69 this number is smaller than the number of bytes requested, or the amount
70 of data required for one frame. On error, -1 is returned, and the ``errno``
71 variable is set appropriately. The generic error codes are described at the
72 :ref:`Generic Error Codes <gen-errors>` chapter.
73

3. 한국어 전문 번역

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

이름, 선언과 인자

1-35

LIRC `write()`는 application buffer의 송신 data를 열린 LIRC 장치에 기록합니다.

#include <unistd.h>

ssize_t write(int fd, void *buf, size_t count);
LIRC write 인자
인자설명
fdopen()이 반환한 LIRC 장치 file descriptor
buf송신할 data가 들어 있는 buffer 시작 주소
countBuffer에 들어 있는 byte 수

장치, data buffer와 byte 수를 전달합니다.

.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
.. c:namespace:: RC

.. _lirc-write:

************
LIRC write()
************

Name
====

lirc-write - Write to a LIRC device

Synopsis
========

.. code-block:: c

    #include <unistd.h>

.. c:function:: ssize_t write( int fd, void *buf, size_t count )

Arguments
=========

``fd``
    File descriptor returned by ``open()``.

``buf``
    Buffer with data to be written

``count``
    Number of bytes at the buffer

공통 쓰기 동작과 mode 선택

36-46

`write()`는 `buf`에서 최대 `count` byte를 `fd`가 가리키는 LIRC 장치로 씁니다. 정확한 형식은 현재 transmit mode에 따라 달라집니다.

먼저 `LIRC_GET_FEATURES`로 driver가 지원하는 송신 mode를 확인하고 `LIRC_SET_SEND_MODE`로 PULSE 또는 SCANCODE mode를 선택해야 합니다.

LIRC 송신 준비
LIRC_GET_FEATURES로 송신 capability 확인LIRC_SET_SEND_MODE로 mode 선택Mode에 맞는 buffer 구성write() 호출 후 반환 byte 수 확인

Capability와 활성 mode를 맞춘 뒤 data를 기록합니다.

Description
===========

:c:func:`write()` writes up to ``count`` bytes to the device
referenced by the file descriptor ``fd`` from the buffer starting at
``buf``.

The exact format of the data depends on what mode a driver is in, use
:ref:`lirc_get_features` to get the supported modes and use
:ref:`lirc_set_send_mode` set the mode.

LIRC_MODE_PULSE 송신

47-54

`LIRC_MODE_PULSE`에서 buffer는 정수 pulse/space 길이의 sequence입니다. Pulse와 space는 별도 tag 없이 배열 위치로 구분되며 첫 값과 마지막 값은 pulse여야 합니다.

따라서 sample 개수는 반드시 홀수입니다. `write()`는 hardware가 전체 data를 송신할 때까지 block하며 hardware가 처리할 수 있는 양보다 많은 data를 주면 `EINVAL`을 반환합니다.

PULSE buffer 규칙
조건의미 또는 결과
첫 samplePulse 길이
짝수 위치 sampleSpace 길이
마지막 samplePulse 길이
전체 sample 수홀수
Hardware 한도 초과EINVAL

암시적 위치 규칙을 위반하면 올바른 waveform이 되지 않습니다.

When in :ref:`LIRC_MODE_PULSE <lirc-mode-PULSE>` mode, the data written to
the chardev is a pulse/space sequence of integer values. Pulses and spaces
are only marked implicitly by their position. The data must start and end
with a pulse, therefore, the data must always include an uneven number of
samples. The write function blocks until the data has been transmitted
by the hardware. If more data is provided than the hardware can send, the
driver returns ``EINVAL``.

LIRC_MODE_SCANCODE 송신

55-64

`LIRC_MODE_SCANCODE`에서는 한 번에 `struct lirc_scancode` 하나만 써야 하며 크기가 다르면 `EINVAL`입니다. `scancode` member에 원하는 값, `rc_proto`에 IR protocol을 설정합니다.

나머지 모든 member는 0이어야 하며 그렇지 않으면 `EINVAL`입니다. 지정 protocol의 encoder가 없거나 scan code가 그 protocol에서 유효하지 않아도 `EINVAL`을 반환합니다.

검증을 통과한 뒤 `write()`는 hardware가 scan code를 실제 송신할 때까지 block합니다.

SCANCODE write 검증
검사 항목요구 사항
Structure 개수한 번에 정확히 1개
scancode송신할 protocol별 scan code
rc_proto송신에 사용할 IR protocol
그 밖의 member모두 0
Protocol encoder존재해야 함
Invalid 조건EINVAL

Structure 크기, member와 encoder를 모두 검사합니다.

When in :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` mode, one
``struct lirc_scancode`` must be written to the chardev at a time, else
``EINVAL`` is returned. Set the desired scancode in the ``scancode`` member,
and the :ref:`IR protocol <Remote_controllers_Protocols>` in the
:c:type:`rc_proto`: member. All other members must be
set to 0, else ``EINVAL`` is returned. If there is no protocol encoder
for the protocol or the scancode is not valid for the specified protocol,
``EINVAL`` is returned. The write function blocks until the scancode
is transmitted by the hardware.

반환값과 short write

65-72

성공하면 실제로 쓴 byte 수를 반환합니다. 요청한 byte 수나 한 frame 분량보다 작은 short write도 그 자체로 오류는 아닙니다.

오류이면 -1을 반환하고 `errno`를 설정합니다. Application은 반환 byte 수를 확인하고 일반적인 short write 처리 원칙을 따라야 하며 공통 오류는 Generic Error Codes 절을 참조합니다.

Return Value
============

On success, the number of bytes written is returned. It is not an error if
this number is smaller than the number of bytes requested, or the amount
of data required for one frame.  On error, -1 is returned, and the ``errno``
variable is set appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.