LIRC libraries
LinuxInfraredRemoteControl
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Modules Pages
dump_config.c
Go to the documentation of this file.
1 
2 /****************************************************************************
3  ** dump_config.c ***********************************************************
4  ****************************************************************************
5  *
6  * dump_config.c - dumps data structures into file
7  *
8  * Copyright (C) 1998 Pablo d'Angelo <pablo@ag-trek.allgaeu.org>
9  *
10  */
11 
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20 
21 #ifdef TIME_WITH_SYS_TIME
22 # include <sys/time.h>
23 # include <time.h>
24 #else
25 # ifdef HAVE_SYS_TIME_H
26 # include <sys/time.h>
27 # else
28 # include <time.h>
29 # endif
30 #endif
31 
32 #include <stdio.h>
33 #include "include/media/lirc.h"
34 #include "lirc/config_file.h"
35 #include "lirc/dump_config.h"
36 #include "lirc/config_flags.h"
37 #include "lirc/ir_remote_types.h"
38 
39 void fprint_comment(FILE * f, const struct ir_remote *rem, const char* commandline)
40 {
41  time_t timet;
42  struct tm *tmp;
43  char cmd[128];
44  char uname[64];
45  FILE* p;
46 
47  p = popen("uname -r", "r");
48  if (p < 0) {
49  strcat(uname, "Cannot run uname -r(!)");
50  } else {
51  if (fgets(uname, sizeof(uname), p) != uname)
52  strcat(uname, "Cannot run uname -r (!)");
53  pclose(p);
54  }
55  if (commandline)
56  snprintf(cmd, sizeof(cmd), "%s", commandline);
57  else
58  strcat(cmd, "");
59 
60  timet = time(NULL);
61  tmp = localtime(&timet);
62  fprintf(f,
63  "#\n"
64  "# This config file was automatically generated\n"
65  "# using lirc-%s(%s) on %s"
66  "# Command line used: %s\n"
67  "# Kernel version (uname -r): %s"
68  "#\n"
69  "# Remote name (as of config file): %s\n"
70  "# Brand of remote device, the thing you hold in your hand:\n"
71  "# Remote device model nr: \n"
72  "# Remote device info url: \n"
73  "# Does remote device has a bundled capture device e. g., a usb\n"
74  "# dongle? : \n"
75  "# For bundled USB capture devices: usb vendor id, product id \n"
76  "# and device string (use dmesg or lsusb): \n"
77  "# Type of device controlled \n"
78  "# (TV, VCR, Audio, DVD, Satellite, Cable, PVR, HTPC, ...) : \n"
79  "# Device(s) controlled by this remote: \n\n",
80  VERSION, curr_driver->name, asctime(tmp), cmd, uname, rem->name);
81 }
82 
83 void fprint_flags(FILE * f, int flags)
84 {
85  int i;
86  int begin = 0;
87 
88  for (i = 0; all_flags[i].flag; i++) {
89  if (flags & all_flags[i].flag) {
90  flags &= (~all_flags[i].flag);
91  if (begin == 0)
92  fprintf(f, " flags ");
93  else if (begin == 1)
94  fprintf(f, "|");
95  fprintf(f, "%s", all_flags[i].name);
96  begin = 1;
97  }
98  }
99  if (begin == 1)
100  fprintf(f, "\n");
101 }
102 
103 void fprint_remotes(FILE * f, const struct ir_remote *all, const char* commandline)
104 {
105  while (all) {
106  fprint_remote(f, all, commandline);
107  fprintf(f, "\n\n");
108  all = all->next;
109  }
110 }
111 
112 void fprint_remote_gap(FILE * f, const struct ir_remote *rem)
113 {
114  if (rem->gap2 != 0) {
115  fprintf(f, " gap %u %u\n", (__u32) rem->gap, (__u32) rem->gap2);
116  } else {
117  fprintf(f, " gap %u\n", (__u32) rem->gap);
118  }
119 }
120 
121 void fprint_remote_head(FILE * f, const struct ir_remote *rem)
122 {
123  fprintf(f, "begin remote\n\n");
124  fprintf(f, " name %s\n", rem->name);
125  if (rem->manual_sort){
126  fprintf(f, " manual_sort %d\n", rem->manual_sort);
127  }
128  if (rem->driver) {
129  fprintf(f, " driver %s\n", rem->driver);
130  }
131  if (!is_raw(rem)) {
132  fprintf(f, " bits %5d\n", rem->bits);
133  }
134  fprint_flags(f, rem->flags);
135  fprintf(f, " eps %5d\n", rem->eps);
136  fprintf(f, " aeps %5d\n\n", rem->aeps);
137  if (!is_raw(rem)) {
138  if (has_header(rem)) {
139  fprintf(f, " header %5u %5u\n", (__u32) rem->phead, (__u32) rem->shead);
140  }
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  }
151  if (!is_raw(rem)) {
152  if (rem->plead != 0) {
153  fprintf(f, " plead %5u\n", (__u32) rem->plead);
154  }
155  if (has_foot(rem)) {
156  fprintf(f, " foot %5u %5u\n", (__u32) rem->pfoot, (__u32) rem->sfoot);
157  }
158  }
159  if (has_repeat(rem)) {
160  fprintf(f, " repeat %5u %5u\n", (__u32) rem->prepeat, (__u32) rem->srepeat);
161  }
162  if (!is_raw(rem)) {
163  if (rem->pre_data_bits > 0) {
164  fprintf(f, " pre_data_bits %d\n", rem->pre_data_bits);
165  fprintf(f, " pre_data 0x%llX\n", (unsigned long long)rem->pre_data);
166  }
167  if (rem->post_data_bits > 0) {
168  fprintf(f, " post_data_bits %d\n", rem->post_data_bits);
169  fprintf(f, " post_data 0x%llX\n", (unsigned long long)rem->post_data);
170  }
171  if (rem->pre_p != 0 && rem->pre_s != 0) {
172  fprintf(f, " pre %5u %5u\n", (__u32) rem->pre_p, (__u32) rem->pre_s);
173  }
174  if (rem->post_p != 0 && rem->post_s != 0) {
175  fprintf(f, " post %5u %5u\n", (__u32) rem->post_p, (__u32) rem->post_s);
176  }
177  }
178  fprint_remote_gap(f, rem);
179  if (has_repeat_gap(rem)) {
180  fprintf(f, " repeat_gap %u\n", (__u32) rem->repeat_gap);
181  }
182  if (rem->suppress_repeat > 0) {
183  fprintf(f, " suppress_repeat %d\n", rem->suppress_repeat);
184  }
185  if (rem->min_repeat > 0) {
186  fprintf(f, " min_repeat %d\n", rem->min_repeat);
187  if (rem->suppress_repeat == 0) {
188  fprintf(f, "# suppress_repeat %d\n", rem->min_repeat);
189  fprintf(f, "# uncomment to suppress unwanted repeats\n");
190  }
191  }
192  if (!is_raw(rem)) {
193  if (rem->min_code_repeat > 0) {
194  fprintf(f, " min_code_repeat %d\n", rem->min_code_repeat);
195  }
196  fprintf(f, " toggle_bit_mask 0x%llX\n", (unsigned long long)rem->toggle_bit_mask);
197  if (has_toggle_mask(rem)) {
198  fprintf(f, " toggle_mask 0x%llX\n", (unsigned long long)rem->toggle_mask);
199  }
200  if (rem->repeat_mask != 0) {
201  fprintf(f, " repeat_mask 0x%llX\n", (unsigned long long)rem->repeat_mask);
202  }
203  if (rem->rc6_mask != 0) {
204  fprintf(f, " rc6_mask 0x%llX\n", (unsigned long long)rem->rc6_mask);
205  }
206  if (has_ignore_mask(rem)) {
207  fprintf(f, " ignore_mask 0x%llX\n", (unsigned long long)rem->ignore_mask);
208  }
209  if (is_serial(rem)) {
210  fprintf(f, " baud %d\n", rem->baud);
211  fprintf(f, " serial_mode %dN%d%s\n", rem->bits_in_byte, rem->stop_bits / 2,
212  rem->stop_bits % 2 ? ".5" : "");
213  }
214  }
215  if (rem->freq != 0) {
216  fprintf(f, " frequency %u\n", rem->freq);
217  }
218  if (rem->duty_cycle != 0) {
219  fprintf(f, " duty_cycle %u\n", rem->duty_cycle);
220  }
221  fprintf(f, "\n");
222 }
223 
224 void fprint_remote_foot(FILE * f, const struct ir_remote *rem)
225 {
226  fprintf(f, "end remote\n");
227 }
228 
229 void fprint_remote_signal_head(FILE * f, const struct ir_remote *rem)
230 {
231  if (!is_raw(rem))
232  fprintf(f, " begin codes\n");
233  else
234  fprintf(f, " begin raw_codes\n\n");
235 }
236 
237 void fprint_remote_signal_foot(FILE * f, const struct ir_remote *rem)
238 {
239  if (!is_raw(rem))
240  fprintf(f, " end codes\n\n");
241  else
242  fprintf(f, " end raw_codes\n\n");
243 }
244 
245 void fprint_remote_signal(FILE * f, const struct ir_remote *rem, const struct ir_ncode *codes)
246 {
247  int i, j;
248 
249  if (!is_raw(rem)) {
250  char format[30];
251  const struct ir_code_node *loop;
252 
253  sprintf(format, " %%-24s 0x%%0%dllX", (rem->bits + 3) / 4);
254  fprintf(f, format, codes->name, codes->code);
255  sprintf(format, " 0x%%0%dlX", (rem->bits + 3) / 4);
256  for (loop = codes->next; loop != NULL; loop = loop->next) {
257  fprintf(f, format, loop->code);
258  }
259 
260  fprintf(f, "\n");
261  } else {
262  fprintf(f, " name %s\n", codes->name);
263  j = 0;
264  for (i = 0; i < codes->length; i++) {
265  if (j == 0) {
266  fprintf(f, " %7u", (__u32) codes->signals[i]);
267  } else if (j < 5) {
268  fprintf(f, " %7u", (__u32) codes->signals[i]);
269  } else {
270  fprintf(f, " %7u\n", (__u32) codes->signals[i]);
271  j = -1;
272  }
273  j++;
274  }
275  codes++;
276  if (j == 0) {
277  fprintf(f, "\n");
278  } else {
279  fprintf(f, "\n\n");
280  j = 0;
281  }
282  }
283 }
284 
285 void fprint_remote_signals(FILE * f, const struct ir_remote *rem)
286 {
287  const struct ir_ncode *codes;
288 
289  fprint_remote_signal_head(f, rem);
290  codes = rem->codes;
291  while (codes->name != NULL) {
292  fprint_remote_signal(f, rem, codes);
293  codes++;
294  }
295  fprint_remote_signal_foot(f, rem);
296 }
297 
298 void fprint_remote(FILE * f, const struct ir_remote *rem, const char* commandline)
299 {
300  fprint_comment(f, rem, commandline);
301  fprint_remote_head(f, rem);
302  fprint_remote_signals(f, rem);
303  fprint_remote_foot(f, rem);
304 }
unsigned int freq
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
lirc_t srepeat
const char * name
Definition: driver.h:170
ir_code code
const char * driver
unsigned int min_code_repeat
const struct flaglist all_flags[]
Definition: config_file.c:87
const struct driver const * curr_driver
Definition: driver.c:24
ir_code rc6_mask
ir_code toggle_bit_mask
ir_code ignore_mask
unsigned int bits_in_byte