LIRC libraries: /tmp/work/src/lirc-0.10.2/lib/dump_config.c Source File

LIRC libraries Linux Infrared Remote Control

Loading...
Searching...
No Matches
dump_config.c
Go to the documentation of this file.
1/****************************************************************************
2** dump_config.c ***********************************************************
3****************************************************************************
4*
5* dump_config.c - dumps data structures into file
6*
7* Copyright (C) 1998 Pablo d'Angelo <pablo@ag-trek.allgaeu.org>
8*
9*/
10
16#ifdef HAVE_CONFIG_H
17# include <config.h>
18#endif
19
20#ifdef TIME_WITH_SYS_TIME
21# include <sys/time.h>
22# include <time.h>
23#else
24# ifdef HAVE_SYS_TIME_H
25# include <sys/time.h>
26# else
27# include <time.h>
28# endif
29#endif
30
31#include <stdio.h>
32#include <stdint.h>
33
34#include "media/lirc.h"
35
36#include "lirc/config_file.h"
37#include "lirc/dump_config.h"
38#include "lirc/config_flags.h"
39#include "lirc/ir_remote_types.h"
40
41void fprint_comment(FILE* f, const struct ir_remote* rem, const char* commandline)
42{
43 time_t timet;
44 struct tm* tmp;
45 char cmd[128];
46 char uname[64];
47 FILE* p;
48
49 p = popen("uname -r", "r");
50 if (p < 0) {
51 strcat(uname, "Cannot run uname -r(!)");
52 } else {
53 if (fgets(uname, sizeof(uname), p) != uname)
54 strcat(uname, "Cannot run uname -r (!)");
55 pclose(p);
56 }
57 if (commandline)
58 snprintf(cmd, sizeof(cmd), "%s", commandline);
59 else
60 strcat(cmd, "");
61
62 timet = time(NULL);
63 tmp = localtime(&timet);
64 fprintf(f,
65 "#\n"
66 "# This config file was automatically generated\n"
67 "# using lirc-%s(%s) on %s"
68 "# Command line used: %s\n"
69 "# Kernel version (uname -r): %s"
70 "#\n"
71 "# Remote name (as of config file): %s\n"
72 "# Brand of remote device, the thing you hold in your hand:\n"
73 "# Remote device model nr:\n"
74 "# Remote device info url:\n"
75 "# Does remote device has a bundled capture device e. g., a\n"
76 "# usb dongle? :\n"
77 "# For bundled USB devices: usb vendor id, product id\n"
78 "# and device string (use dmesg or lsusb):\n"
79 "# Type of device controlled\n"
80 "# (TV, VCR, Audio, DVD, Satellite, Cable, HTPC, ...) :\n"
81 "# Device(s) controlled by this remote:\n\n",
82 VERSION, curr_driver->name, asctime(tmp), cmd, uname, rem->name);
83}
84
85void fprint_flags(FILE* f, int flags)
86{
87 int i;
88 int begin = 0;
89
90 for (i = 0; all_flags[i].flag; i++) {
91 if (flags & all_flags[i].flag) {
92 flags &= (~all_flags[i].flag);
93 if (begin == 0)
94 fprintf(f, " flags ");
95 else if (begin == 1)
96 fprintf(f, "|");
97 fprintf(f, "%s", all_flags[i].name);
98 begin = 1;
99 }
100 }
101 if (begin == 1)
102 fprintf(f, "\n");
103}
104
105void fprint_remotes(FILE* f, const struct ir_remote* all, const char* commandline)
106{
107 while (all) {
108 fprint_remote(f, all, commandline);
109 fprintf(f, "\n\n");
110 all = all->next;
111 }
112}
113
114void fprint_remote_gap(FILE* f, const struct ir_remote* rem)
115{
116 if (rem->gap2 != 0)
117 fprintf(f, " gap %u %u\n", (uint32_t)rem->gap, (uint32_t)rem->gap2);
118 else
119 fprintf(f, " gap %u\n", (uint32_t)rem->gap);
120}
121
122void fprint_remote_head(FILE* f, const struct ir_remote* rem)
123{
124 fprintf(f, "begin remote\n\n");
125 fprintf(f, " name %s\n", rem->name);
126 if (rem->manual_sort)
127 fprintf(f, " manual_sort %d\n", rem->manual_sort);
128 if (rem->driver)
129 fprintf(f, " driver %s\n", rem->driver);
130 if (!is_raw(rem))
131 fprintf(f, " bits %5d\n", rem->bits);
132 fprint_flags(f, rem->flags);
133 fprintf(f, " eps %5d\n", rem->eps);
134 fprintf(f, " aeps %5d\n\n", rem->aeps);
135 if (!is_raw(rem)) {
136 if (has_header(rem))
137 fprintf(f, " header %5u %5u\n", (uint32_t)rem->phead, (uint32_t)rem->shead);
138 if (rem->pthree != 0 || rem->sthree != 0)
139 fprintf(f, " three %5u %5u\n", (uint32_t)rem->pthree, (uint32_t)rem->sthree);
140 if (rem->ptwo != 0 || rem->stwo != 0)
141 fprintf(f, " two %5u %5u\n", (uint32_t)rem->ptwo, (uint32_t)rem->stwo);
142 fprintf(f, " one %5u %5u\n", (uint32_t)rem->pone, (uint32_t)rem->sone);
143 fprintf(f, " zero %5u %5u\n", (uint32_t)rem->pzero, (uint32_t)rem->szero);
144 }
145 if (rem->ptrail != 0)
146 fprintf(f, " ptrail %5u\n", (uint32_t)rem->ptrail);
147 if (!is_raw(rem)) {
148 if (rem->plead != 0)
149 fprintf(f, " plead %5u\n", (uint32_t)rem->plead);
150 if (has_foot(rem))
151 fprintf(f, " foot %5u %5u\n", (uint32_t)rem->pfoot, (uint32_t)rem->sfoot);
152 }
153 if (has_repeat(rem))
154 fprintf(f, " repeat %5u %5u\n", (uint32_t)rem->prepeat, (uint32_t)rem->srepeat);
155 if (!is_raw(rem)) {
156 if (rem->pre_data_bits > 0) {
157 fprintf(f, " pre_data_bits %d\n", rem->pre_data_bits);
158 fprintf(f, " pre_data 0x%llX\n", (unsigned long long)rem->pre_data);
159 }
160 if (rem->post_data_bits > 0) {
161 fprintf(f, " post_data_bits %d\n", rem->post_data_bits);
162 fprintf(f, " post_data 0x%llX\n", (unsigned long long)rem->post_data);
163 }
164 if (rem->pre_p != 0 && rem->pre_s != 0)
165 fprintf(f, " pre %5u %5u\n", (uint32_t)rem->pre_p, (uint32_t)rem->pre_s);
166 if (rem->post_p != 0 && rem->post_s != 0)
167 fprintf(f, " post %5u %5u\n", (uint32_t)rem->post_p, (uint32_t)rem->post_s);
168 }
169 fprint_remote_gap(f, rem);
170 if (has_repeat_gap(rem))
171 fprintf(f, " repeat_gap %u\n", (uint32_t)rem->repeat_gap);
172 if (rem->suppress_repeat > 0)
173 fprintf(f, " suppress_repeat %d\n", rem->suppress_repeat);
174 if (rem->min_repeat > 0) {
175 fprintf(f, " min_repeat %d\n", rem->min_repeat);
176 if (rem->suppress_repeat == 0) {
177 fprintf(f, "# suppress_repeat %d\n", rem->min_repeat);
178 fprintf(f, "# uncomment to suppress unwanted repeats\n");
179 }
180 }
181 if (!is_raw(rem)) {
182 if (rem->min_code_repeat > 0)
183 fprintf(f, " min_code_repeat %d\n", rem->min_code_repeat);
184 fprintf(f, " toggle_bit_mask 0x%llX\n", (unsigned long long)rem->toggle_bit_mask);
185 if (has_toggle_mask(rem))
186 fprintf(f, " toggle_mask 0x%llX\n", (unsigned long long)rem->toggle_mask);
187 if (rem->repeat_mask != 0)
188 fprintf(f, " repeat_mask 0x%llX\n", (unsigned long long)rem->repeat_mask);
189 if (rem->rc6_mask != 0)
190 fprintf(f, " rc6_mask 0x%llX\n", (unsigned long long)rem->rc6_mask);
191 if (has_ignore_mask(rem))
192 fprintf(f, " ignore_mask 0x%llX\n", (unsigned long long)rem->ignore_mask);
193 if (is_serial(rem)) {
194 fprintf(f, " baud %d\n", rem->baud);
195 fprintf(f, " serial_mode %dN%d%s\n", rem->bits_in_byte, rem->stop_bits / 2,
196 rem->stop_bits % 2 ? ".5" : "");
197 }
198 }
199 if (rem->freq != 0)
200 fprintf(f, " frequency %u\n", rem->freq);
201 if (rem->duty_cycle != 0)
202 fprintf(f, " duty_cycle %u\n", rem->duty_cycle);
203 fprintf(f, "\n");
204}
205
206void fprint_remote_foot(FILE* f, const struct ir_remote* rem)
207{
208 fprintf(f, "end remote\n");
209}
210
211void fprint_remote_signal_head(FILE* f, const struct ir_remote* rem)
212{
213 if (!is_raw(rem))
214 fprintf(f, " begin codes\n");
215 else
216 fprintf(f, " begin raw_codes\n\n");
217}
218
219void fprint_remote_signal_foot(FILE* f, const struct ir_remote* rem)
220{
221 if (!is_raw(rem))
222 fprintf(f, " end codes\n\n");
223 else
224 fprintf(f, " end raw_codes\n\n");
225}
226
227void fprint_remote_signal(FILE* f,
228 const struct ir_remote* rem,
229 const struct ir_ncode* codes)
230{
231 int i, j;
232
233 if (!is_raw(rem)) {
234 char format[64];
235 const struct ir_code_node* loop;
236
237 sprintf(format, " %%-24s 0x%%0%dllX",
238 (rem->bits + 3) / 4);
239 fprintf(f, format, codes->name, codes->code);
240 sprintf(format, " 0x%%0%dlX", (rem->bits + 3) / 4);
241 for (loop = codes->next; loop != NULL; loop = loop->next)
242 fprintf(f, format, loop->code);
243
244 fprintf(f, "\n");
245 } else {
246 fprintf(f, " name %s\n", codes->name);
247 j = 0;
248 for (i = 0; i < codes->length; i++) {
249 if (j == 0) {
250 fprintf(f, " %7u", (uint32_t)codes->signals[i]);
251 } else if (j < 5) {
252 fprintf(f, " %7u", (uint32_t)codes->signals[i]);
253 } else {
254 fprintf(f, " %7u\n", (uint32_t)codes->signals[i]);
255 j = -1;
256 }
257 j++;
258 }
259 codes++;
260 if (j == 0) {
261 fprintf(f, "\n");
262 } else {
263 fprintf(f, "\n\n");
264 }
265 }
266}
267
268void fprint_remote_signals(FILE* f, const struct ir_remote* rem)
269{
270 const struct ir_ncode* codes;
271
272 fprint_remote_signal_head(f, rem);
273 codes = rem->codes;
274 while (codes->name != NULL) {
275 fprint_remote_signal(f, rem, codes);
276 codes++;
277 }
278 fprint_remote_signal_foot(f, rem);
279}
280
281void fprint_remote(FILE* f, const struct ir_remote* rem, const char* commandline)
282{
283 fprint_comment(f, rem, commandline);
284 fprint_remote_head(f, rem);
285 fprint_remote_signals(f, rem);
286 fprint_remote_foot(f, rem);
287}
all_flags
const struct flaglist all_flags[]
All flags i config file: Their name and mask.
Definition config_file.c:95
curr_driver
const struct driver *const curr_driver
Read-only access to drv for client code.
Definition driver.c:34
driver::name
const char * name
Driver name, as listed by -H help and used as argument to i –driver.
Definition driver.h:224
flaglist::flag
int flag
Flag bitmask.
Definition config_flags.h:18
ir_code_node
An ir_code for entering into (singly) linked lists, i.e.
Definition ir_remote_types.h:49
ir_ncode
IR Command, corresponding to one (command defining) line of the configuration file.
Definition ir_remote_types.h:60
ir_ncode::next
struct ir_code_node * next
Linked list of the subsequent ir_code's, after the first one.
Definition ir_remote_types.h:75
ir_ncode::code
ir_code code
The first code of the command.
Definition ir_remote_types.h:65
ir_ncode::length
int length
(private)
Definition ir_remote_types.h:68
ir_ncode::signals
lirc_t * signals
(private)
Definition ir_remote_types.h:71
ir_ncode::name
char * name
Name of command.
Definition ir_remote_types.h:62
ir_remote
One remote as represented in the configuration file.
Definition ir_remote_types.h:150
ir_remote::driver
const char * driver
Name of driver for LIRCCODE cases.
Definition ir_remote_types.h:152
ir_remote::repeat_gap
uint32_t repeat_gap
time between two repeat codes if different from gap
Definition ir_remote_types.h:188
ir_remote::stwo
lirc_t stwo
2 (only used for RC-MM)
Definition ir_remote_types.h:171
ir_remote::freq
unsigned int freq
modulation frequency
Definition ir_remote_types.h:203
ir_remote::suppress_repeat
int suppress_repeat
suppress unwanted repeats
Definition ir_remote_types.h:191
ir_remote::aeps
unsigned int aeps
detecting very short pulses is difficult with relative tolerance for some remotes,...
Definition ir_remote_types.h:157
ir_remote::gap2
uint32_t gap2
time between signals in usecs
Definition ir_remote_types.h:187
ir_remote::stop_bits
unsigned int stop_bits
mapping: 1->2 1.5->3 2->4
Definition ir_remote_types.h:212
ir_remote::bits_in_byte
unsigned int bits_in_byte
default: 8
Definition ir_remote_types.h:210
ir_remote::sfoot
lirc_t sfoot
foot
Definition ir_remote_types.h:176
ir_remote::rc6_mask
ir_code rc6_mask
RC-6 doubles signal length of some bits.
Definition ir_remote_types.h:206
ir_remote::ptrail
lirc_t ptrail
trailing pulse
Definition ir_remote_types.h:175
ir_remote::duty_cycle
unsigned int duty_cycle
0<duty cycle<=100 default: 50
Definition ir_remote_types.h:204
ir_remote::repeat_mask
ir_code repeat_mask
mask defines which bits are inverted for repeats
Definition ir_remote_types.h:217
ir_remote::srepeat
lirc_t srepeat
indicate repeating
Definition ir_remote_types.h:177
ir_remote::pre_data
ir_code pre_data
data which the remote sends before actual keycode
Definition ir_remote_types.h:180
ir_remote::bits
int bits
bits (length of code)
Definition ir_remote_types.h:154
ir_remote::post_data_bits
int post_data_bits
length of post_data
Definition ir_remote_types.h:181
ir_remote::ignore_mask
ir_code ignore_mask
mask defines which bits can be ignored when matching a code
Definition ir_remote_types.h:216
ir_remote::plead
lirc_t plead
leading pulse
Definition ir_remote_types.h:174
ir_remote::sthree
lirc_t sthree
3 (only used for RC-MM)
Definition ir_remote_types.h:170
ir_remote::shead
lirc_t shead
header
Definition ir_remote_types.h:169
ir_remote::szero
lirc_t szero
0
Definition ir_remote_types.h:173
ir_remote::post_data
ir_code post_data
data which the remote sends after actual keycode
Definition ir_remote_types.h:182
ir_remote::toggle_mask
ir_code toggle_mask
Sharp (?) error detection scheme.
Definition ir_remote_types.h:205
ir_remote::flags
int flags
flags
Definition ir_remote_types.h:155
ir_remote::baud
unsigned int baud
can be overridden by [p|s]zero, [p|s]one
Definition ir_remote_types.h:209
ir_remote::min_repeat
int min_repeat
code is repeated at least x times code sent once -> min_repeat=0
Definition ir_remote_types.h:194
ir_remote::manual_sort
int manual_sort
If set in any remote, disables automatic sorting.
Definition ir_remote_types.h:237
ir_remote::post_s
lirc_t post_s
signal between keycode and post_code
Definition ir_remote_types.h:184
ir_remote::pre_s
lirc_t pre_s
signal between pre_data and keycode
Definition ir_remote_types.h:183
ir_remote::gap
uint32_t gap
time between signals in usecs
Definition ir_remote_types.h:186
ir_remote::eps
int eps
eps (relative tolerance)
Definition ir_remote_types.h:156
ir_remote::min_code_repeat
unsigned int min_code_repeat
meaningful only if remote sends a repeat code: in this case this value indicates how often the real c...
Definition ir_remote_types.h:202
ir_remote::sone
lirc_t sone
1
Definition ir_remote_types.h:172
ir_remote::name
const char * name
name of remote control
Definition ir_remote_types.h:151
ir_remote::toggle_bit_mask
ir_code toggle_bit_mask
previously only one bit called toggle_bit
Definition ir_remote_types.h:190
ir_remote::pre_data_bits
int pre_data_bits
length of pre_data
Definition ir_remote_types.h:179