LIRC libraries LinuxInfraredRemoteControl

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

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