LIRC libraries
LinuxInfraredRemoteControl
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 
33 #ifdef HAVE_KERNEL_LIRC_H
34 #include <linux/lirc.h>
35 #else
36 #include "include/media/lirc.h"
37 #endif
38 
39 #include "lirc/config_file.h"
40 #include "lirc/dump_config.h"
41 #include "lirc/config_flags.h"
42 #include "lirc/ir_remote_types.h"
43 
44 void fprint_comment(FILE* f, const struct ir_remote* rem, const char* commandline)
45 {
46  time_t timet;
47  struct tm* tmp;
48  char cmd[128];
49  char uname[64];
50  FILE* p;
51 
52  p = popen("uname -r", "r");
53  if (p < 0) {
54  strcat(uname, "Cannot run uname -r(!)");
55  } else {
56  if (fgets(uname, sizeof(uname), p) != uname)
57  strcat(uname, "Cannot run uname -r (!)");
58  pclose(p);
59  }
60  if (commandline)
61  snprintf(cmd, sizeof(cmd), "%s", commandline);
62  else
63  strcat(cmd, "");
64 
65  timet = time(NULL);
66  tmp = localtime(&timet);
67  fprintf(f,
68  "#\n"
69  "# This config file was automatically generated\n"
70  "# using lirc-%s(%s) on %s"
71  "# Command line used: %s\n"
72  "# Kernel version (uname -r): %s"
73  "#\n"
74  "# Remote name (as of config file): %s\n"
75  "# Brand of remote device, the thing you hold in your hand:\n"
76  "# Remote device model nr:\n"
77  "# Remote device info url:\n"
78  "# Does remote device has a bundled capture device e. g., a\n"
79  "# usb dongle? :\n"
80  "# For bundled USB devices: usb vendor id, product id\n"
81  "# and device string (use dmesg or lsusb):\n"
82  "# Type of device controlled\n"
83  "# (TV, VCR, Audio, DVD, Satellite, Cable, HTPC, ...) :\n"
84  "# Device(s) controlled by this remote:\n\n",
85  VERSION, curr_driver->name, asctime(tmp), cmd, uname, rem->name);
86 }
87 
88 void fprint_flags(FILE* f, int flags)
89 {
90  int i;
91  int begin = 0;
92 
93  for (i = 0; all_flags[i].flag; i++) {
94  if (flags & all_flags[i].flag) {
95  flags &= (~all_flags[i].flag);
96  if (begin == 0)
97  fprintf(f, " flags ");
98  else if (begin == 1)
99  fprintf(f, "|");
100  fprintf(f, "%s", all_flags[i].name);
101  begin = 1;
102  }
103  }
104  if (begin == 1)
105  fprintf(f, "\n");
106 }
107 
108 void fprint_remotes(FILE* f, const struct ir_remote* all, const char* commandline)
109 {
110  while (all) {
111  fprint_remote(f, all, commandline);
112  fprintf(f, "\n\n");
113  all = all->next;
114  }
115 }
116 
117 void fprint_remote_gap(FILE* f, const struct ir_remote* rem)
118 {
119  if (rem->gap2 != 0)
120  fprintf(f, " gap %u %u\n", (__u32)rem->gap, (__u32)rem->gap2);
121  else
122  fprintf(f, " gap %u\n", (__u32)rem->gap);
123 }
124 
125 void fprint_remote_head(FILE* f, const struct ir_remote* rem)
126 {
127  fprintf(f, "begin remote\n\n");
128  fprintf(f, " name %s\n", rem->name);
129  if (rem->manual_sort)
130  fprintf(f, " manual_sort %d\n", rem->manual_sort);
131  if (rem->driver)
132  fprintf(f, " driver %s\n", rem->driver);
133  if (!is_raw(rem))
134  fprintf(f, " bits %5d\n", rem->bits);
135  fprint_flags(f, rem->flags);
136  fprintf(f, " eps %5d\n", rem->eps);
137  fprintf(f, " aeps %5d\n\n", rem->aeps);
138  if (!is_raw(rem)) {
139  if (has_header(rem))
140  fprintf(f, " header %5u %5u\n", (__u32)rem->phead, (__u32)rem->shead);
141  if (rem->pthree != 0 || rem->sthree != 0)
142  fprintf(f, " three %5u %5u\n", (__u32)rem->pthree, (__u32)rem->sthree);
143  if (rem->ptwo != 0 || rem->stwo != 0)
144  fprintf(f, " two %5u %5u\n", (__u32)rem->ptwo, (__u32)rem->stwo);
145  fprintf(f, " one %5u %5u\n", (__u32)rem->pone, (__u32)rem->sone);
146  fprintf(f, " zero %5u %5u\n", (__u32)rem->pzero, (__u32)rem->szero);
147  }
148  if (rem->ptrail != 0)
149  fprintf(f, " ptrail %5u\n", (__u32)rem->ptrail);
150  if (!is_raw(rem)) {
151  if (rem->plead != 0)
152  fprintf(f, " plead %5u\n", (__u32)rem->plead);
153  if (has_foot(rem))
154  fprintf(f, " foot %5u %5u\n", (__u32)rem->pfoot, (__u32)rem->sfoot);
155  }
156  if (has_repeat(rem))
157  fprintf(f, " repeat %5u %5u\n", (__u32)rem->prepeat, (__u32)rem->srepeat);
158  if (!is_raw(rem)) {
159  if (rem->pre_data_bits > 0) {
160  fprintf(f, " pre_data_bits %d\n", rem->pre_data_bits);
161  fprintf(f, " pre_data 0x%llX\n", (unsigned long long)rem->pre_data);
162  }
163  if (rem->post_data_bits > 0) {
164  fprintf(f, " post_data_bits %d\n", rem->post_data_bits);
165  fprintf(f, " post_data 0x%llX\n", (unsigned long long)rem->post_data);
166  }
167  if (rem->pre_p != 0 && rem->pre_s != 0)
168  fprintf(f, " pre %5u %5u\n", (__u32)rem->pre_p, (__u32)rem->pre_s);
169  if (rem->post_p != 0 && rem->post_s != 0)
170  fprintf(f, " post %5u %5u\n", (__u32)rem->post_p, (__u32)rem->post_s);
171  }
172  fprint_remote_gap(f, rem);
173  if (has_repeat_gap(rem))
174  fprintf(f, " repeat_gap %u\n", (__u32)rem->repeat_gap);
175  if (rem->suppress_repeat > 0)
176  fprintf(f, " suppress_repeat %d\n", rem->suppress_repeat);
177  if (rem->min_repeat > 0) {
178  fprintf(f, " min_repeat %d\n", rem->min_repeat);
179  if (rem->suppress_repeat == 0) {
180  fprintf(f, "# suppress_repeat %d\n", rem->min_repeat);
181  fprintf(f, "# uncomment to suppress unwanted repeats\n");
182  }
183  }
184  if (!is_raw(rem)) {
185  if (rem->min_code_repeat > 0)
186  fprintf(f, " min_code_repeat %d\n", rem->min_code_repeat);
187  fprintf(f, " toggle_bit_mask 0x%llX\n", (unsigned long long)rem->toggle_bit_mask);
188  if (has_toggle_mask(rem))
189  fprintf(f, " toggle_mask 0x%llX\n", (unsigned long long)rem->toggle_mask);
190  if (rem->repeat_mask != 0)
191  fprintf(f, " repeat_mask 0x%llX\n", (unsigned long long)rem->repeat_mask);
192  if (rem->rc6_mask != 0)
193  fprintf(f, " rc6_mask 0x%llX\n", (unsigned long long)rem->rc6_mask);
194  if (has_ignore_mask(rem))
195  fprintf(f, " ignore_mask 0x%llX\n", (unsigned long long)rem->ignore_mask);
196  if (is_serial(rem)) {
197  fprintf(f, " baud %d\n", rem->baud);
198  fprintf(f, " serial_mode %dN%d%s\n", rem->bits_in_byte, rem->stop_bits / 2,
199  rem->stop_bits % 2 ? ".5" : "");
200  }
201  }
202  if (rem->freq != 0)
203  fprintf(f, " frequency %u\n", rem->freq);
204  if (rem->duty_cycle != 0)
205  fprintf(f, " duty_cycle %u\n", rem->duty_cycle);
206  fprintf(f, "\n");
207 }
208 
209 void fprint_remote_foot(FILE* f, const struct ir_remote* rem)
210 {
211  fprintf(f, "end remote\n");
212 }
213 
214 void fprint_remote_signal_head(FILE* f, const struct ir_remote* rem)
215 {
216  if (!is_raw(rem))
217  fprintf(f, " begin codes\n");
218  else
219  fprintf(f, " begin raw_codes\n\n");
220 }
221 
222 void fprint_remote_signal_foot(FILE* f, const struct ir_remote* rem)
223 {
224  if (!is_raw(rem))
225  fprintf(f, " end codes\n\n");
226  else
227  fprintf(f, " end raw_codes\n\n");
228 }
229 
230 void fprint_remote_signal(FILE* f, const struct ir_remote* rem, const struct ir_ncode* codes)
231 {
232  int i, j;
233 
234  if (!is_raw(rem)) {
235  char format[30];
236  const struct ir_code_node* loop;
237 
238  sprintf(format, " %%-24s 0x%%0%dllX", (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", (__u32)codes->signals[i]);
251  } else if (j < 5) {
252  fprintf(f, " %7u", (__u32)codes->signals[i]);
253  } else {
254  fprintf(f, " %7u\n", (__u32)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 
268 void 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 
281 void 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 }
unsigned int freq
const struct driver *const curr_driver
Definition: driver.c:28
ir_code post_data
ir_code repeat_mask
struct ir_code_node * next
unsigned int baud
const char * name
lirc_t * signals
char * name
unsigned int duty_cycle
ir_code toggle_mask
ir_code pre_data
__u32 repeat_gap
unsigned int stop_bits
unsigned int aeps
lirc_t srepeat
const char * name
Definition: driver.h:219
ir_code code
const char * driver
unsigned int min_code_repeat
const struct flaglist all_flags[]
Definition: config_file.c:98
ir_code rc6_mask
ir_code toggle_bit_mask
ir_code ignore_mask
unsigned int bits_in_byte