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

Linux 6.18.37 · Userspace API / Media / Remote Controller

LIRC read()

활성 수신 mode에 따라 raw MODE2 packet 또는 decoded scan code를 읽습니다.

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

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

1. 요약·해설

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

요약·해설

lirc-read.rst:1-65

`read()`의 buffer 형식은 현재 receive mode에 달려 있으며 short read는 정상입니다. MODE2와 SCANCODE structure를 구분하고 반환 byte 수를 기준으로 frame을 조립해야 합니다.

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-read:
5
6 ***********
7 LIRC read()
8 ***********
9
10 Name
11 ====
12
13 lirc-read - Read from a LIRC device
14
15 Synopsis
16 ========
17
18 .. code-block:: c
19
20 #include <unistd.h>
21
22 .. c:function:: ssize_t read( 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 to be filled
32
33 ``count``
34 Max number of bytes to read
35
36 Description
37 ===========
38
39 :c:func:`read()` attempts to read up to ``count`` bytes from file
40 descriptor ``fd`` into the buffer starting at ``buf``. If ``count`` is zero,
41 :c:func:`read()` returns zero and has no other results. If ``count``
42 is greater than ``SSIZE_MAX``, the result is unspecified.
43
44 The exact format of the data depends on what :ref:`lirc_modes` a driver
45 uses. Use :ref:`lirc_get_features` to get the supported mode, and use
46 :ref:`lirc_set_rec_mode` set the current active mode.
47
48 The mode :ref:`LIRC_MODE_MODE2 <lirc-mode-mode2>` is for raw IR,
49 in which packets containing an unsigned int value describing an IR signal are
50 read from the chardev.
51
52 Alternatively, :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` can be available,
53 in this mode scancodes which are either decoded by software decoders, or
54 by hardware decoders. The :c:type:`rc_proto` member is set to the
55 :ref:`IR protocol <Remote_controllers_Protocols>`
56 used for transmission, and ``scancode`` to the decoded scancode,
57 and the ``keycode`` set to the keycode or ``KEY_RESERVED``.
58
59 Return Value
60 ============
61
62 On success, the number of bytes read is returned. It is not an error if
63 this number is smaller than the number of bytes requested, or the amount
64 of data required for one frame. On error, -1 is returned, and the ``errno``
65 variable is set appropriately.
66

3. 한국어 전문 번역

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

이름, 선언과 인자

1-35

LIRC `read()`는 열린 LIRC 장치에서 데이터를 읽어 application buffer를 채웁니다.

#include <unistd.h>

ssize_t read(int fd, void *buf, size_t count);
LIRC read 인자
인자설명
fdopen()이 반환한 LIRC 장치 file descriptor
buf읽은 데이터를 채울 buffer 시작 주소
count읽으려는 최대 byte 수

읽을 장치, 결과 buffer와 최대 byte 수를 전달합니다.

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

.. _lirc-read:

***********
LIRC read()
***********

Name
====

lirc-read - Read from a LIRC device

Synopsis
========

.. code-block:: c

    #include <unistd.h>

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

Arguments
=========

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

``buf``
   Buffer to be filled

``count``
   Max number of bytes to read

읽기 동작과 mode별 data 형식

36-58

`read()`는 `fd`에서 최대 `count` byte를 `buf`로 읽습니다. `count`가 0이면 다른 효과 없이 0을 반환하며, `SSIZE_MAX`보다 크면 결과가 정의되지 않습니다.

정확한 data 형식은 driver의 활성 LIRC mode에 달려 있습니다. `LIRC_GET_FEATURES`로 지원 mode를 확인하고 `LIRC_SET_REC_MODE`로 현재 수신 mode를 선택합니다.

`LIRC_MODE_MODE2`에서는 raw IR 신호를 설명하는 unsigned int packet을 문자 장치에서 읽습니다. Packet은 pulse, space, frequency, timeout 또는 overflow type과 payload를 담습니다.

`LIRC_MODE_SCANCODE`에서는 software 또는 hardware decoder가 만든 scan code를 읽습니다. `rc_proto`에는 사용한 IR protocol, `scancode`에는 decode 값, `keycode`에는 대응 key code가 들어가며 mapping이 없으면 `KEY_RESERVED`입니다.

LIRC read data 형식
mode읽는 data
LIRC_MODE_MODE2Raw IR을 나타내는 unsigned int packet sequence
LIRC_MODE_SCANCODErc_proto, scancode, keycode 등을 가진 struct lirc_scancode

활성 receive mode에 따라 buffer element가 달라집니다.

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

:c:func:`read()` attempts to read up to ``count`` bytes from file
descriptor ``fd`` into the buffer starting at ``buf``.  If ``count`` is zero,
:c:func:`read()` returns zero and has no other results. If ``count``
is greater than ``SSIZE_MAX``, the result is unspecified.

The exact format of the data depends on what :ref:`lirc_modes` a driver
uses. Use :ref:`lirc_get_features` to get the supported mode, and use
:ref:`lirc_set_rec_mode` set the current active mode.

The mode :ref:`LIRC_MODE_MODE2 <lirc-mode-mode2>` is for raw IR,
in which packets containing an unsigned int value describing an IR signal are
read from the chardev.

Alternatively, :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` can be available,
in this mode scancodes which are either decoded by software decoders, or
by hardware decoders. The :c:type:`rc_proto` member is set to the
:ref:`IR protocol <Remote_controllers_Protocols>`
used for transmission, and ``scancode`` to the decoded scancode,
and the ``keycode`` set to the keycode or ``KEY_RESERVED``.

반환값과 short read

59-65

성공하면 실제로 읽은 byte 수를 반환합니다. 요청한 byte 수보다 작거나 한 frame에 필요한 data보다 적은 short read도 오류가 아닙니다. 오류이면 -1을 반환하고 `errno`를 설정합니다.

Application은 한 번의 `read()`가 완전한 frame을 보장한다고 가정하지 말고, 반환 byte 수에 따라 남은 data를 이어서 읽어야 합니다.

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

On success, the number of bytes read 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.