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