~ubuntu-branches/ubuntu/natty/lirc/natty-proposed

« back to all changes in this revision

Viewing changes to daemons/config_file.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2010-04-02 15:06:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100402150619-y1z8c1yqv621a11o
Tags: 0.8.7~pre2-0ubuntu1
* Update to 0.8.7~pre2
  - Fixes issues with lirc on maverick. (LP: #620498)
* Add lirc-in-kernel-ioctls.patch to use ioctls from the kernel for drivers.
* Drop patches upstream now:
  - debian/patches/appleir_repeat_issue.patch
  - debian/patches/hauppauge-tv-card.patch
  - debian/patches/lirc-i2c-2.6.patch
  - debian/patches/lirc_dev-2.6.33.patch
* Add updated-driver-names.patch 
* Refresh patches:
  - debian/patches/02_Makefile.in
  - debian/patches/13-warning-cleanup
* Update extra transmitter and remote databases to not reference atiusb.
* debian/control:
  - Update branches to be owned by ~mythbuntu-dev
* Disable in-kernel-support when starting lircd, and re-enable when
  stopping.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $Id: config_file.c,v 5.30 2009/01/31 09:46:47 lirc Exp $      */
 
1
/*      $Id: config_file.c,v 5.34 2010/07/11 03:28:21 jarodwilson Exp $      */
2
2
 
3
3
/****************************************************************************
4
4
 ** config_file.c ***********************************************************
31
31
#include "lircd.h"
32
32
#include "ir_remote.h"
33
33
#include "config_file.h"
 
34
#include "transmit.h"
34
35
 
35
36
#define LINE_LEN 1024
36
37
#define MAX_INCLUDES 10
41
42
static int parse_error;
42
43
 
43
44
static struct ir_remote * read_config_recursive(FILE *f, const char *name, int depth);
 
45
static void calculate_signal_lengths(struct ir_remote *remote);
44
46
 
45
47
void **init_void_array(struct void_array *ar,size_t chunk_size, size_t item_size)
46
48
{
165
167
        char *endptr;
166
168
        long n;
167
169
        int h;
168
 
        
 
170
 
169
171
        n=strtol(val,&endptr,0);
170
172
        h=(int) n;
171
173
        if(!*val || *endptr || n!=((long) h))
184
186
        char *endptr;
185
187
        unsigned long n;
186
188
        unsigned int h;
187
 
        
 
189
 
188
190
        n=strtoul(val,&endptr,0);
189
191
        h=(unsigned int) n;
190
192
        if(!*val || *endptr || n!=((unsigned long) h))
203
205
        unsigned long n;
204
206
        lirc_t h;
205
207
        char *endptr;
206
 
        
 
208
 
207
209
        n=strtoul(val,&endptr,0);
208
210
        h=(lirc_t) n;
209
211
        if(!*val || *endptr || n!=((unsigned long) h))
238
240
 
239
241
int addSignal(struct void_array *signals, char *val)
240
242
{
241
 
        lirc_t t;
242
 
        
243
 
        t=s_strtolirc_t(val);
244
 
        if(parse_error) return(0);
245
 
        if(!add_void_array(signals, &t)){
246
 
                return(0);
247
 
        }
248
 
        return(1);
 
243
        unsigned int t;
 
244
 
 
245
        t = s_strtoui(val);
 
246
        if (parse_error)
 
247
                return 0;
 
248
        if (!add_void_array(signals, &t))
 
249
                return 0;
 
250
 
 
251
        return 1;
249
252
}
250
 
              
 
253
 
251
254
struct ir_ncode *defineCode(char *key, char *val, struct ir_ncode *code)
252
255
{
253
256
        memset(code, 0, sizeof(*code));
264
267
struct ir_code_node *defineNode(struct ir_ncode *code, const char *val)
265
268
{
266
269
        struct ir_code_node *node;
267
 
        
 
270
 
268
271
        node=s_malloc(sizeof(*node));
269
272
        if(node==NULL) return NULL;
270
 
        
 
273
 
271
274
        node->code=s_strtocode(val);
272
275
        node->next=NULL;
273
 
        
 
276
 
274
277
#       ifdef LONG_IR_CODE
275
278
        LOGPRINTF(3,"                           0x%016llX", node->code);
276
279
#       else
308
311
                {
309
312
                        help=NULL;
310
313
                }
311
 
        
 
314
 
312
315
                flaglptr=all_flags;
313
316
                while(flaglptr->name!=NULL){
314
317
                        if(strcasecmp(flaglptr->name,flag)==0){
416
419
                rem->repeat_gap=s_strtoul(val);
417
420
                return(1);
418
421
        }
419
 
        /* obsolete: use toggle_bit_mask instead */
 
422
        /* obsolete: use toggle_bit_mask instead */
420
423
        else if (strcasecmp("toggle_bit",key)==0){
421
424
                rem->toggle_bit = s_strtoi(val);
422
425
                return 1;
442
445
                rem->toggle_bit=s_strtoi(val);
443
446
                return(1);
444
447
        }
 
448
        else if (strcasecmp("suppress_repeat",key)==0){
 
449
                rem->suppress_repeat=s_strtoi(val);
 
450
                return(1);
 
451
        }
445
452
        else if (strcasecmp("min_repeat",key)==0){
446
453
                rem->min_repeat=s_strtoi(val);
447
454
                return(1);
560
567
        parse_error=1;
561
568
        return(0);
562
569
}
563
 
    
 
570
 
564
571
static int sanityChecks(struct ir_remote *rem)
565
572
{
566
573
        struct ir_ncode *codes;
567
574
        struct ir_code_node *node;
568
 
        
 
575
 
569
576
        if (!rem->name)
570
577
        {
571
578
                logprintf(LOG_ERR,"you must specify a remote name");
614
621
                        }
615
622
                }
616
623
        }
617
 
        
 
624
 
618
625
        return 1;
619
626
}
620
627
 
621
628
struct ir_remote *sort_by_bit_count(struct ir_remote *remotes)
622
629
{
623
630
        struct ir_remote *top, *rem, *next, *prev, *scan;
624
 
        
 
631
 
625
632
        rem = remotes;
626
633
        top = NULL;
627
634
        while(rem!=NULL)
628
635
        {
629
636
                next = rem->next;
630
 
                
 
637
 
631
638
                scan = top;
632
639
                prev = NULL;
633
640
                while(scan && bit_count(scan)<=bit_count(rem))
651
658
                {
652
659
                        rem->next = NULL;
653
660
                }
654
 
                
 
661
 
655
662
                rem = next;
656
663
        }
657
 
        
 
664
 
658
665
        return top;
659
666
}
660
667
 
662
669
{
663
670
        char *last;
664
671
        size_t len;
665
 
        
 
672
 
666
673
        len=strlen(s);
667
674
        if(len<2)
668
675
        {
726
733
        }
727
734
        strcat(dst, "/");
728
735
        strcat(dst, child);
729
 
        
 
736
 
730
737
        return dst;
731
738
}
732
739
 
820
827
                                }
821
828
                                else{
822
829
                                        int save_line = line;
823
 
                                        
 
830
 
824
831
                                        if (!top_rem){
825
832
                                                /* create first remote */
826
833
                                                LOGPRINTF(2,"creating first remote");
855
862
                                                parse_error=1;
856
863
                                                break;
857
864
                                        }
858
 
                                        
 
865
 
859
866
                                        init_void_array(&codes_list,30, sizeof(struct ir_ncode));
860
867
                                        mode=ID_codes;
861
868
                                }else if(strcasecmp("raw_codes",val)==0){
894
901
                                        while(!parse_error && val2!=NULL)
895
902
                                        {
896
903
                                                struct ir_code_node *node;
897
 
                                                
 
904
 
898
905
                                                if(val2[0]=='#') break; /* comment */
899
906
                                                node=defineNode(code, val2);
900
907
                                                val2=strtok(NULL, whitespace);
925
932
                                }else if(strcasecmp("raw_codes",val)==0){
926
933
                                        /* end raw codes mode */
927
934
                                        LOGPRINTF(2,"    end raw_codes");
928
 
                                        
 
935
 
929
936
                                        if(mode==ID_raw_name){
930
937
                                                raw_code.signals=get_void_array(&signals);
931
938
                                                raw_code.length=signals.nr_items;
972
979
                                        while(!parse_error && val2!=NULL)
973
980
                                        {
974
981
                                                struct ir_code_node *node;
975
 
                                                
 
982
 
976
983
                                                if(val2[0]=='#') break; /* comment */
977
984
                                                node=defineNode(code, val2);
978
985
                                                val2=strtok(NULL, whitespace);
1007
1014
                                        while(!parse_error && val2!=NULL)
1008
1015
                                        {
1009
1016
                                                struct ir_code_node *node;
1010
 
                                                
 
1017
 
1011
1018
                                                if(val2[0]=='#') break; /* comment */
1012
1019
                                                node=defineNode(code, val2);
1013
1020
                                                val2=strtok(NULL, whitespace);
1104
1111
        }
1105
1112
        if (parse_error){
1106
1113
                static int print_error = 1;
1107
 
                
 
1114
 
1108
1115
                if(print_error) {
1109
1116
                        logprintf(LOG_ERR, "reading of file '%s' failed",
1110
1117
                                  name);
1123
1130
                if((!is_raw(rem)) && rem->flags&REVERSE)
1124
1131
                {
1125
1132
                        struct ir_ncode *codes;
1126
 
                        
 
1133
 
1127
1134
                        if(has_pre(rem))
1128
1135
                        {
1129
1136
                                rem->pre_data=reverse(rem->pre_data,
1149
1156
                if(rem->flags&RC6 && rem->rc6_mask==0 && rem->toggle_bit>0)
1150
1157
                {
1151
1158
                        int all_bits=bit_count(rem);
1152
 
                        
 
1159
 
1153
1160
                        rem->rc6_mask=((ir_code) 1)<<(all_bits-rem->toggle_bit);
1154
1161
                }
1155
1162
                if(rem->toggle_bit > 0)
1156
1163
                {
1157
1164
                        int all_bits=bit_count(rem);
1158
 
                        
 
1165
 
1159
1166
                        if(has_toggle_bit_mask(rem))
1160
1167
                        {
1161
1168
                                logprintf(LOG_WARNING,
1183
1190
                if(is_serial(rem))
1184
1191
                {
1185
1192
                        lirc_t base;
1186
 
                        
 
1193
 
1187
1194
                        if(rem->baud>0)
1188
1195
                        {
1189
1196
                                base=1000000/rem->baud;
1211
1218
                                rem->min_code_repeat = 0;
1212
1219
                        }
1213
1220
                }
 
1221
                calculate_signal_lengths(rem);
1214
1222
                rem=rem->next;
1215
1223
        }
1216
1224
 
1221
1229
        return (top_rem);
1222
1230
}
1223
1231
 
 
1232
void calculate_signal_lengths(struct ir_remote *remote)
 
1233
{
 
1234
        if(is_const(remote))
 
1235
        {
 
1236
                remote->min_total_signal_length = min_gap(remote);
 
1237
                remote->max_total_signal_length = max_gap(remote);
 
1238
        }
 
1239
        else
 
1240
        {
 
1241
                remote->min_gap_length = min_gap(remote);
 
1242
                remote->max_gap_length = max_gap(remote);
 
1243
        }
 
1244
 
 
1245
        lirc_t min_signal_length = 0, max_signal_length = 0;
 
1246
        lirc_t max_pulse = 0, max_space = 0;
 
1247
        int first_sum = 1;
 
1248
        struct ir_ncode *c = remote->codes;
 
1249
        int i;
 
1250
 
 
1251
        while(c->name)
 
1252
        {
 
1253
                struct ir_ncode code = *c;
 
1254
                struct ir_code_node *next = code.next;
 
1255
                int first = 1;
 
1256
                int repeat = 0;
 
1257
                do{
 
1258
                        if(first)
 
1259
                        {
 
1260
                                first = 0;
 
1261
                        }
 
1262
                        else
 
1263
                        {
 
1264
                                code.code = next->code;
 
1265
                                next = next->next;
 
1266
                        }
 
1267
                        for(repeat = 0; repeat < 2; repeat++)
 
1268
                        {
 
1269
                                if(init_sim(remote, &code, repeat))
 
1270
                                {
 
1271
                                        lirc_t sum = send_buffer.sum;
 
1272
 
 
1273
                                        if(sum)
 
1274
                                        {
 
1275
                                                if(first_sum ||
 
1276
                                                   sum < min_signal_length)
 
1277
                                                {
 
1278
                                                        min_signal_length = sum;
 
1279
                                                }
 
1280
                                                if(first_sum ||
 
1281
                                                   sum > max_signal_length)
 
1282
                                                {
 
1283
                                                        max_signal_length = sum;
 
1284
                                                }
 
1285
                                                first_sum = 0;
 
1286
                                        }
 
1287
                                        for(i=0; i<send_buffer.wptr; i++)
 
1288
                                        {
 
1289
                                                if(i&1) /* space */
 
1290
                                                {
 
1291
                                                        if(send_buffer.data[i] > max_space)
 
1292
                                                        {
 
1293
                                                                max_space = send_buffer.data[i];
 
1294
                                                        }
 
1295
                                                }
 
1296
                                                else /* pulse */
 
1297
                                                {
 
1298
                                                        if(send_buffer.data[i] > max_pulse)
 
1299
                                                        {
 
1300
                                                                max_pulse = send_buffer.data[i];
 
1301
                                                        }
 
1302
                                                }
 
1303
                                        }
 
1304
                                }
 
1305
                        }
 
1306
                } while(next);
 
1307
                c++;
 
1308
        }
 
1309
        if(first_sum)
 
1310
        {
 
1311
                /* no timing data, so assume gap is the actual total
 
1312
                   length */
 
1313
                remote->min_total_signal_length = min_gap(remote);
 
1314
                remote->max_total_signal_length = max_gap(remote);
 
1315
                remote->min_gap_length = min_gap(remote);
 
1316
                remote->max_gap_length = max_gap(remote);
 
1317
        }
 
1318
        else if(is_const(remote))
 
1319
        {
 
1320
                if(remote->min_total_signal_length > max_signal_length)
 
1321
                {
 
1322
                        remote->min_gap_length =
 
1323
                                remote->min_total_signal_length
 
1324
                                - max_signal_length;
 
1325
                }
 
1326
                else
 
1327
                {
 
1328
                        logprintf(LOG_WARNING, "min_gap_length is 0 for "
 
1329
                                  "'%s' remote", remote->name);
 
1330
                        remote->min_gap_length = 0;
 
1331
                }
 
1332
                if(remote->max_total_signal_length > min_signal_length)
 
1333
                {
 
1334
                        remote->max_gap_length =
 
1335
                                remote->max_total_signal_length
 
1336
                                - min_signal_length;
 
1337
                }
 
1338
                else
 
1339
                {
 
1340
                        logprintf(LOG_WARNING, "max_gap_length is 0 for "
 
1341
                                  "'%s' remote", remote->name);
 
1342
                        remote->max_gap_length = 0;
 
1343
                }
 
1344
        }
 
1345
        else
 
1346
        {
 
1347
                remote->min_total_signal_length = min_signal_length +
 
1348
                        remote->min_gap_length;
 
1349
                remote->max_total_signal_length = max_signal_length +
 
1350
                        remote->max_gap_length;
 
1351
        }
 
1352
        LOGPRINTF(1, "lengths: %lu %lu %lu %lu",
 
1353
                  remote->min_total_signal_length,
 
1354
                  remote->max_total_signal_length,
 
1355
                  remote->min_gap_length,
 
1356
                  remote->max_gap_length);
 
1357
}
 
1358
 
1224
1359
void free_config(struct ir_remote *remotes)
1225
1360
{
1226
1361
        struct ir_remote *next;
1227
1362
        struct ir_ncode *codes;
1228
 
        
 
1363
 
1229
1364
        while(remotes!=NULL)
1230
1365
        {
1231
1366
                next=remotes->next;
1240
1375
                        while(codes->name!=NULL)
1241
1376
                        {
1242
1377
                                struct ir_code_node *node,*next_node;
1243
 
                                
 
1378
 
1244
1379
                                free(codes->name);
1245
1380
                                if(codes->signals!=NULL)
1246
1381
                                        free(codes->signals);
1259
1394
                remotes=next;
1260
1395
        }
1261
1396
}
 
1397