2 * Copyright (c) 2007, IRTrans GmbH
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of IRTrans GmbH nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY IRTrans GmbH ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL IRTrans GmbH BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #define MSG_NOSIGNAL 0
43 #define MSG_NOSIGNAL 0
51 #include <sys/types.h>
52 #include <sys/socket.h>
53 #include <netinet/in.h>
55 #include <arpa/inet.h>
66 #define closesocket close
81 #define PATH_SEPARATOR '\\'
83 #define PATH_SEPARATOR '/'
90 int ReadIRTransDirectory (char filetype
[],REMOTEBUFFER
*buf
,int start
,byte statustype
)
93 int fd
,i
,len
,pos
,res
,fl
,dlen
;
95 char st
[2048],msg
[256];
98 int cnt
,cnt_total
,nlen
;
99 memset (buf
,0,sizeof (REMOTEBUFFER
));
100 buf
->statustype
= statustype
;
101 buf
->statuslen
= sizeof (REMOTEBUFFER
);
102 buf
->offset
= (short)start
;
104 if (statustype
== STATUS_IRDBFILE
) dlen
= 5;
110 len
= getdirentries (fd
,st
,2048,&off
);
114 di
= (struct dirent
*)&st
[pos
];
115 fl
= strlen (di
-> d_name
) - dlen
;
116 if (fl
>= 1 && !strcmp (di
->d_name
+ fl
,filetype
)) {
117 if (cnt_total
>= start
&& cnt
< 40) {
118 nlen
= strlen (di
-> d_name
) - dlen
;
119 if (nlen
> 80) nlen
= 80;
120 memset (buf
->remotes
[cnt
].name
,' ',80);
121 memcpy (buf
->remotes
[cnt
].name
,di
-> d_name
,nlen
);
126 pos
+= di
-> d_reclen
;
130 buf
->count_buffer
= cnt
;
131 buf
->count_total
= cnt_total
;
132 if (cnt
== 40) buf
->count_remaining
= cnt_total
-cnt
;
133 else buf
->count_remaining
= 0;
144 int ReadIRTransDirectory (char filetype
[],REMOTEBUFFER
*buf
,int start
,byte statustype
)
146 struct _finddata_t c_file
;
153 int cnt
,cnt_total
,len
,dlen
;
154 memset (buf
,0,sizeof (REMOTEBUFFER
));
155 buf
->statustype
= statustype
;
156 buf
->statuslen
= sizeof (REMOTEBUFFER
);
157 buf
->offset
= (short)start
;
159 if (statustype
== STATUS_IRDBFILE
) dlen
= 5;
163 if((hFile
= _findfirst( filetype
, &c_file
)) != -1L) {
165 if (cnt_total
>= start
&& cnt
< 40) {
166 len
= (int)strlen (c_file
.name
) - dlen
;
167 if (len
> 80) len
= 80;
168 memset (buf
->remotes
[cnt
].name
,' ',80);
169 memcpy (buf
->remotes
[cnt
].name
,c_file
.name
,len
);
173 } while( _findnext( hFile
, &c_file
) == 0);
176 buf
->count_buffer
= cnt
;
177 buf
->count_total
= cnt_total
;
178 if (cnt
== 40) buf
->count_remaining
= cnt_total
-cnt
;
179 else buf
->count_remaining
= 0;
186 void GetNumericCode (char command
[],char numeric
[],char rem
[],char com
[])
190 if (*command
< '0') {
192 while (rem
[q
] && q
< 4) {
193 sprintf (numeric
+ q
* 2,"%02x",rem
[q
]);
197 while (com
[b
] && b
< 4) {
198 sprintf (numeric
+ q
* 2,"%02x",com
[b
]);
203 while (q
< 16) numeric
[q
++] = '0';
208 if (strlen (command
) == 22 && !strncmp (command
,"004011",6)) {
211 val
|= (command
[q
] - '0') << b
;
215 if (val
< 10) val
+= '0';
216 else val
+= 'a' - 10;
225 if (val
< 10) val
+= '0';
226 else val
+= 'a' - 10;
229 while (z
< 16) numeric
[z
++] = '0';
233 if (command
[q
] == 'S') q
++;
235 val
|= (command
[q
] - '0') << b
;
239 if (val
< 10) val
+= '0';
240 else val
+= 'a' - 10;
249 if (val
< 10) val
+= '0';
250 else val
+= 'a' - 10;
253 while (z
< 16) numeric
[z
++] = '0';
257 FILE *ASCIIOpenRemote (char name
[],NETWORKCLIENT
*client
)
260 char nm
[256],st
[256];
263 if (strcmp (nm
+ strlen (nm
) - 4,".rem")) strcat (nm
,".rem");
264 fp
= DBOpenFile (nm
,"r");
265 memset (&client
->ird
,0,sizeof (IRDATA
));
266 client
->learnstatus
.received
[0] = 0;
267 client
->learnstatus
.adress
= 0;
268 client
->learnstatus
.statustype
= STATUS_LEARN
;
269 client
->learnstatus
.statuslen
= sizeof (NETWORKLEARNSTAT
);
270 memset (client
->learnstatus
.remote
,' ',80);
271 memset (client
->learnstatus
.received
,' ',CODE_LEN
);
272 client
->learnstatus
.num_timings
= 0;
273 client
->learnstatus
.num_commands
= 0;
274 client
->learnstatus
.learnok
= 0;
277 ASCIITimingSample (fp
,client
);
279 fp
= DBOpenFile (nm
,"r+");
280 memcpy (client
->learnstatus
.remote
,name
,strlen (name
));
281 strcpy (client
->filename
,nm
);
285 fp
= DBOpenFile (nm
,"w+");
287 sprintf (st
,"Error opening remote file %s [%d]",nm
,errno
);
288 log_print (st
,LOG_ERROR
);
292 fprintf (fp
,"[REMOTE]\n");
293 fprintf (fp
," [NAME]%s\n\n",name
);
294 fprintf (fp
,"[TIMING]\n");
298 memcpy (client
->learnstatus
.remote
,name
,strlen (name
));
299 strcpy (client
->filename
,nm
);
305 void ASCIITimingSample (FILE *fp
,NETWORKCLIENT
*client
)
314 data
= DBFindSection (fp
,"TIMING",NULL
,NULL
,NULL
);
317 data
= DBFindSection (fp
,"0",ln
,"[COMMANDS]",NULL
);
320 StoreIRTiming (&irt
,ln
);
321 client
->learnstatus
.num_timings
++;
323 while (data
&& *data
== '[' && data
[1] != 'C') {
324 data
= DBReadString (ln
,fp
,NULL
);
325 if (data
&& *data
== '[' && data
[1] != 'C') client
->learnstatus
.num_timings
++;
328 memcpy (&client
->ird
.ir_length
,&irt
.ir_length
,sizeof (IRTIMING
) - 4);
329 client
->ird
.ir_length
= 1;
334 data
= DBFindSection (fp
,"COMMANDS",NULL
,NULL
,NULL
);
337 data
= DBReadString (ln
,fp
,NULL
);
338 if (!data
|| *data
!= '[') return;
340 i
= (int)strlen (data
);
341 while (i
&& data
[i
] != ']') i
--;
345 if ((rp
= strstr(data
, "[RAW]")))
349 sscanf(rp
, "%d", &client
->ird
.ir_length
);
351 for (jj
= 0;jj
< client
->ird
.ir_length
; jj
++)
355 sscanf(rp
, "%d%n", &val
, &len
);
356 client
->ird
.data
[jj
] = val
/8;
362 strncpy (client
->ird
.data
,data
+i
,CODE_LEN
);
363 if (strlen (data
+i
) > CODE_LEN
) client
->ird
.ir_length
= CODE_LEN
;
364 else client
->ird
.ir_length
= (byte
)strlen (data
+i
);
368 client
->learnstatus
.num_commands
++;
370 while (data
&& *data
== '[') {
371 data
= DBReadString (ln
,fp
,NULL
);
372 if (data
&& *data
== '[') client
->learnstatus
.num_commands
++;
377 // Sucht nach existierenden Toggle - Commands
378 int ASCIIFindToggleSeq (FILE *fp
,IRDATA
*ird
,char name
[])
386 data
= DBFindSection (fp
,"COMMANDS",NULL
,NULL
,NULL
);
388 if (!data
) return (-1);
390 data
= DBReadString (ln
,fp
,NULL
);
391 if (data
&& *data
== '[') {
394 while (data
[i
] && data
[i
] != '#' && data
[i
] != ']') i
++;
395 if (data
[i
] && !memcmp (name
,data
,i
)) {
396 if (data
[i
] == ']') a
= 1;
397 else a
= atoi (data
+ i
+ 1) + 1;
398 while (data
[i
] != 'D') i
++;
400 if (!strcmp (ird
->data
,data
+i
)) {
401 fseek (fp
,0,SEEK_END
);
409 fseek (fp
,0,SEEK_END
);
415 int ASCIIFindCommand (FILE *fp
,char name
[],NETWORKCLIENT
*client
)
419 int pos
,new,len
,oldlen
;
425 data
= DBFindSection (fp
,"COMMANDS",NULL
,NULL
,NULL
);
428 fseek (fp
,0,SEEK_END
);
429 fprintf (fp
,"\n\n[COMMANDS]\n");
433 ConvertLcase (com
,(int)strlen (com
));
436 data
= DBReadString (ln
,fp
,NULL
);
437 if (data
&& *data
== '[') {
438 ConvertLcase (data
,(int)strlen (data
));
441 while (data
[i
] && data
[i
] != ']') i
++;
442 if (data
[i
] && !memcmp (com
,data
,i
) && i
== (int)strlen (com
)) {
443 new = ftell (fp
); // Debug Info über Update
445 fseek (fp
,0,SEEK_END
);
446 len
= ftell (fp
) - new;
447 fseek (fp
,new,SEEK_SET
);
448 data
= malloc (len
+ 1);
449 len
= (int)fread (data
,1,len
+ 1,fp
);
450 fseek (fp
,pos
,SEEK_SET
);
451 fwrite (data
,1,len
,fp
);
454 data
= malloc (oldlen
);
455 memset (data
,' ',oldlen
);
456 fwrite (data
,1,oldlen
,fp
);
457 fseek (fp
,pos
,SEEK_SET
);
462 hfile
= CreateFile (client
->filename
,GENERIC_WRITE
,FILE_SHARE_READ
| FILE_SHARE_WRITE
,NULL
,OPEN_EXISTING
,FILE_ATTRIBUTE_NORMAL
,NULL
);
464 SetFilePointer (hfile
,pos
,NULL
,FILE_BEGIN
);
465 SetEndOfFile (hfile
);
470 truncate (client
->filename
,pos
);
479 fseek (fp
,0,SEEK_END
);
486 int ASCIIStoreCommand (FILE *fp
,IRDATA
*ird
,char name
[],int timing
,int seq_number
)
490 if (seq_number
) fprintf (fp
," [%s#%02d][T]%d",name
,seq_number
,timing
);
491 else fprintf (fp
," [%s][T]%d",name
,timing
);
495 if (ird
->data
[0] & LONG_CODE_FLAG
) {
496 for (i
=0;i
< ird
-> ir_length
-1;i
++) {
497 if (i
&& (ird
-> data
[i
] & 128)) { // Calibration
498 if (ird
-> data
[i
] & 64) fprintf (fp
,"#-%03d;",(ird
-> data
[i
] & 63) * 8);
499 else fprintf (fp
,"#0%03d;",(ird
-> data
[i
] & 63) * 8);
501 else fprintf (fp
,"%d%d",ird
-> data
[i
] & 7,(ird
-> data
[i
] >> 4) & 7);
503 fprintf (fp
,"%d",ird
-> data
[i
] & 7);
504 if (!(ird
->data
[0] & LONG_CODE_LEN
)) fprintf (fp
,"%d",(ird
-> data
[i
] >> 4) & 7);
508 for (i
=0;i
< ird
-> ir_length
;i
++) {
509 if (ird
-> data
[i
] & 128) { // Calibration
510 if (ird
-> data
[i
] & 64) fprintf (fp
,"#-%03d;",(ird
-> data
[i
] & 63) * 8);
511 else fprintf (fp
,"#0%03d;",(ird
-> data
[i
] & 63) * 8);
513 else fprintf (fp
,"%c",ird
-> data
[i
]);
521 int ASCIIStoreRAW (FILE *fp
,IRRAW
*ird
,char name
[])
524 if (ird
->transmit_freq
== 255)
525 fprintf (fp
," [%s][RAW]%d[FREQ]455[D]",name
,ird
->ir_length
);
527 fprintf (fp
," [%s][RAW]%d[FREQ]%d[D]",name
,ird
->ir_length
,ird
->transmit_freq
);
528 for (i
=0;i
< ird
->ir_length
;i
++) fprintf (fp
,"%d ",ird
->data
[i
] * 8);
534 int TestTimeValue (int val
,int sollk
,int sollg
)
536 if (val
< sollk
|| val
> sollg
) return (0);
541 void CheckRCMMCode (IRDATA
*ird
)
546 if (ird
->time_cnt
< 3) return;
548 for (i
=0;i
<ird
->time_cnt
;i
++) {
549 if (i
== (ird
->data
[0] - '0')) {
550 if (!TestTimeValue (ird
->pulse_len
[i
],47,60)) return;
551 if (!TestTimeValue (ird
->pause_len
[i
],33,40)) return;
554 if (!TestTimeValue (ird
->pulse_len
[i
],19,26)) return;
555 if (!TestTimeValue (ird
->pause_len
[i
],31,39) && !TestTimeValue (ird
->pause_len
[i
],52,59) &&
556 !TestTimeValue (ird
->pause_len
[i
],71,80) && !TestTimeValue (ird
->pause_len
[i
],93,101)) return;
560 sprintf (msg
,"RCMM Timing found\n");
561 log_print (msg
,LOG_DEBUG
);
563 for (i
=0;i
<ird
->time_cnt
;i
++) {
564 if (TestTimeValue (ird
->pulse_len
[i
],15,22)) ird
->pulse_len
[i
] = 21;
565 if (TestTimeValue (ird
->pulse_len
[i
],48,55)) ird
->pulse_len
[i
] = 52;
566 if (TestTimeValue (ird
->pause_len
[i
],32,40)) ird
->pause_len
[i
] = 35;
567 if (TestTimeValue (ird
->pause_len
[i
],53,60)) ird
->pause_len
[i
] = 55;
568 if (TestTimeValue (ird
->pause_len
[i
],72,80)) ird
->pause_len
[i
] = 76;
569 if (TestTimeValue (ird
->pause_len
[i
],93,101)) ird
->pause_len
[i
] = 97;
571 ird
->repeat_pause
= 87;
573 ird
->transmit_freq
= 36;
578 int ASCIIStoreTiming (FILE *fp
,IRDATA
*ird
,NETWORKLEARNSTAT
*stat
)
588 pos
= ASCIIFindTiming (fp
,ird
);
590 if (pos
== -1) return (-ERR_TIMINGNOTFOUND
);
594 fseek (fp
,0,SEEK_END
);
599 DBFindSection (fp
,"TIMING",NULL
,NULL
,NULL
);
600 sprintf (st
,"%d",pos
-1);
601 DBFindSection (fp
,st
,NULL
,NULL
,NULL
);
603 fseek (fp
,0,SEEK_END
);
604 size
= 1024 + ftell (fp
) - fpos
;
606 fseek (fp
,fpos
,SEEK_SET
);
607 size
= (int)fread (mem
,1,size
,fp
);
608 fseek (fp
,fpos
,SEEK_SET
);
609 ASCIIStoreTimingParam (fp
,ird
,pos
);
611 fwrite (mem
,1,size
,fp
);
620 fseek (fp
,0,SEEK_END
);
621 ASCIIStoreTimingParam (fp
,ird
,pos
);
622 fprintf (fp
,"\n\n[COMMANDS]\n");
632 void ASCIIStoreTimingParam (FILE *fp
,IRDATA
*ird
,int timing
)
636 fprintf (fp
," [%d][N]%d",timing
,ird
->time_cnt
& (TIME_LEN
- 1));
637 for (i
=1;i
<= (ird
->time_cnt
& (TIME_LEN
- 1));i
++) {
638 fprintf (fp
,"[%d]%d %d",i
,ird
->pulse_len
[i
-1] * 8,ird
->pause_len
[i
-1] * 8);
640 fprintf (fp
,"[RC]%d[RP]%d",ird
->ir_repeat
,ird
->repeat_pause
);
641 if (ird
->transmit_freq
== 255)
642 fprintf (fp
,"[FREQ]455");
644 fprintf (fp
,"[FREQ]%d",ird
->transmit_freq
);
645 if (ird
->mode
& START_BIT
) fprintf (fp
,"[SB]");
646 if (ird
->mode
& REPEAT_START
) fprintf (fp
,"[RS]");
647 if (ird
->mode
& RC5_DATA
) fprintf (fp
,"[RC5]");
648 if (ird
->mode
& RC6_DATA
) fprintf (fp
,"[RC6]");
652 int ASCIIFindTiming (FILE *fp
,IRDATA
*ird
)
661 data
= DBFindSection (fp
,"TIMING",NULL
,NULL
,NULL
);
663 if (!data
) return (-1);
668 data
= DBFindSection (fp
,st
,ln
,"[COMMANDS]",NULL
);
671 StoreIRTiming (&irt
,ln
);
672 if (CompareTiming (ird
,&irt
)) return (i
+ 100);
678 if (!flag
) fseek (fp
,0,SEEK_END
);
683 int CompareTiming (IRDATA
*ird
,IRTIMING
*irt
)
686 // Check for Timing Adjustments
688 if (ird
->mode
!= irt
->mode
|| ird
->time_cnt
!= irt
->time_cnt
|| ird
->transmit_freq
!= ird
->transmit_freq
) return (0);
690 for (i
=1;i
< ird
->ir_length
;i
++) if (ird
->data
[i
] & 128) break;
692 if (i
< ird
->ir_length
) {
693 for (i
= 0;i
< ird
->time_cnt
;i
++) if (ird
->pause_len
[i
] != irt
->pause_len
[i
] || ird
->pulse_len
[i
] != irt
->pulse_len
[i
]) return (0);
697 for (i
= 0;i
< ird
->time_cnt
;i
++) {
698 if (ird
->pause_len
[i
] < (irt
->pause_len
[i
] - IR_TOLERANCE
) || ird
->pause_len
[i
] > (irt
->pause_len
[i
] + IR_TOLERANCE
) ||
699 ird
->pulse_len
[i
] < (irt
->pulse_len
[i
] - IR_TOLERANCE
) || ird
->pulse_len
[i
] > (irt
->pulse_len
[i
] + IR_TOLERANCE
)) return (0);
713 MACROCOMMAND
*mac_pnt
;
715 ROUTING
*recv_routing
;
716 int recv_routing_cnt
;
717 ROUTING
*send_routing
;
718 int send_routing_cnt
;
730 void GetRemoteDatabase (REMOTEBUFFER
*buf
,int offset
)
733 memset (buf
,0,sizeof (REMOTEBUFFER
));
734 buf
->statustype
= STATUS_REMOTELIST
;
735 buf
->statuslen
= sizeof (REMOTEBUFFER
);
736 buf
->offset
= (short)offset
;
739 while (i
< 40 && offset
< rem_cnt
) {
740 memset (buf
->remotes
[i
].name
,' ',80);
741 memcpy (buf
->remotes
[i
].name
,rem_pnt
[offset
].name
,strlen (rem_pnt
[offset
].name
));
742 buf
->remotes
[i
].source_mask
= rem_pnt
[offset
].source_mask
;
743 buf
->remotes
[i
].target_mask
= rem_pnt
[offset
].target_mask
;
748 buf
->count_buffer
= i
;
749 buf
->count_total
= (word
)rem_cnt
;
750 if (i
== 40) buf
->count_remaining
= (short)(rem_cnt
- offset
);
751 else buf
->count_remaining
= 0;
754 int GetCommandDatabase (COMMANDBUFFER
*buf
,char remote
[],int offset
)
760 memset (buf
,0,sizeof (COMMANDBUFFER
));
761 buf
->statustype
= STATUS_COMMANDLIST
;
762 buf
->statuslen
= sizeof (COMMANDBUFFER
);
763 buf
->offset
= (short)offset
;
765 memset (remcmp
,0,100);
766 strcpy (remcmp
,remote
);
767 ConvertLcase (remcmp
,(int)strlen (remcmp
));
769 if (!offset
|| remote
[0]) {
770 nrem
= DBFindRemote (remcmp
);
771 if (nrem
== -1) return (1);
774 start
= rem_pnt
[nrem
].command_start
;
776 i
= rem_pnt
[nrem
].command_start
;
777 while (i
< rem_pnt
[nrem
].command_end
) {
778 if (cmd_pnt
[i
].toggle_seq
> 1) tog
++;
784 while (i
< 200 && offset
< rem_pnt
[nrem
].command_end
-start
) {
785 if (cmd_pnt
[offset
+start
].toggle_seq
<= 1) {
786 memset (buf
->commands
[i
],' ',20);
787 memcpy (buf
->commands
[i
],cmd_pnt
[offset
+start
].name
,strlen (cmd_pnt
[offset
+start
].name
));
793 buf
->count_buffer
= i
;
794 buf
->count_total
= (word
)rem_pnt
[nrem
].command_end
- start
- tog
;
795 if (i
== 200) buf
->count_remaining
= (short)(rem_pnt
[nrem
].command_end
- start
- offset
- tog
);
796 else buf
->count_remaining
= 0;
800 void FreeDatabaseMemory (void)
802 if (rem_pnt
) free (rem_pnt
);
805 if (cmd_pnt
) free (cmd_pnt
);
809 if (tim_pnt
) free (tim_pnt
);
812 if (mac_pnt
) free (mac_pnt
);
815 if (recv_routing
) free (recv_routing
);
817 recv_routing_cnt
= 0;
818 if (send_routing
) free (send_routing
);
820 send_routing_cnt
= 0;
821 if (rooms
) free (rooms
);
824 ccf_data
= ccf_raw
= ccf_err
= 0;
826 memset (app_pnt
,0,sizeof (app_pnt
));
829 int cmpRawData (byte
*rcv
,byte
*mem
,int len
);
830 int getRawValue (byte
*pnt
,int pos
,word
*val
);
832 void put_mousemovement (byte pnt
[],char name
[])
837 memset (st
,0,sizeof (st
));
840 y
= strtoul (st
,NULL
,2);
841 if (y
> 32) y
= y
- 64;
844 memcpy (st
,pnt
+14,6);
845 x
= strtoul (st
,NULL
,2);
846 if (x
> 32) x
= x
- 64;
848 sprintf (name
,"%03d %03d %c%c%",x
,y
,pnt
[20],pnt
[21]);
851 int DBFindCommandName (byte command
[],char remote
[],char name
[],byte address
,int *remote_num
,int *command_num
,word
*command_num_rel
,int start
)
858 static char last_name
[50];
859 static byte last_address
;
860 mask
= 1 << (address
& 15);
861 mode
= (address
& 0xf0) >> 2;
862 len
= (int)strlen (command
);
864 *command_num
= *remote_num
= 0;
865 if ((mode
& RAW_DATA
) || *command
< '0') { // RAW Vergleich
866 if (mode
& RAW_DATA
) pnt
= (byte
*)command
;
867 else pnt
= (byte
*)command
+ 1;
868 while (i
< cmd_cnt
) {
870 if (cmd_pnt
[i
].mode
& RAW_DATA
&& (rem_pnt
[cmd_pnt
[i
].remote
].source_mask
& mask
)) {
871 if (cmpRawData (pnt
,cmd_pnt
[i
].data
,cmd_pnt
[i
].ir_length
)) {
872 if (cmd_pnt
[i
].name
[strlen (cmd_pnt
[i
].name
) - 1] == '@') {
873 if (!strncmp (last_name
,cmd_pnt
[i
].name
,strlen (cmd_pnt
[i
].name
) - 1)) {
874 strcpy (remote
,rem_pnt
[cmd_pnt
[i
].remote
].name
);
875 strcpy (name
,cmd_pnt
[i
].name
);
876 name
[strlen (name
) - 1] = 0;
877 *command_num_rel
= (word
)(i
- rem_pnt
[cmd_pnt
[i
].remote
].command_start
);
879 *remote_num
= cmd_pnt
[i
].remote
;
880 last_address
= address
;
885 strcpy (remote
,rem_pnt
[cmd_pnt
[i
].remote
].name
);
886 strcpy (name
,cmd_pnt
[i
].name
);
887 strcpy (last_name
,name
);
888 *command_num_rel
= (word
)(i
- rem_pnt
[cmd_pnt
[i
].remote
].command_start
);
890 *remote_num
= cmd_pnt
[i
].remote
;
891 last_address
= address
;
898 if (!start
) last_name
[0] = 0;
902 if (mode
& RC5_DATA
) command
[2] = '0'; // Toggle Bit maskieren
903 if (mode
& RC6_DATA
) {
904 if (len
== 39) command
[23] = '0'; // RC6 Mode 6A
905 else command
[5] = command
[6] = '0'; // Toggle Bit maskieren
908 while (i
< cmd_cnt
) {
909 if (!cmd_pnt
[i
].mode
&& (rem_pnt
[cmd_pnt
[i
].remote
].source_mask
& mask
) &&
910 ((rem_pnt
[cmd_pnt
[i
].remote
].rcv_len
&& len
>= rem_pnt
[cmd_pnt
[i
].remote
].rcv_len
&& !memcmp (command
,cmd_pnt
[i
].data
,rem_pnt
[cmd_pnt
[i
].remote
].rcv_len
)) ||
911 (len
== cmd_pnt
[i
].ir_length
&& !memcmp (command
,cmd_pnt
[i
].data
,len
)))) {
912 if (cmd_pnt
[i
].name
[strlen (cmd_pnt
[i
].name
) - 1] == '@') {
913 if (!strncmp (last_name
,cmd_pnt
[i
].name
,strlen (cmd_pnt
[i
].name
) - 1)) {
914 strcpy (remote
,rem_pnt
[cmd_pnt
[i
].remote
].name
);
915 strcpy (name
,cmd_pnt
[i
].name
);
916 name
[strlen (name
) - 1] = 0;
917 *command_num_rel
= (word
)(i
- rem_pnt
[cmd_pnt
[i
].remote
].command_start
);
919 *remote_num
= cmd_pnt
[i
].remote
;
920 last_address
= address
;
925 strcpy (remote
,rem_pnt
[cmd_pnt
[i
].remote
].name
);
926 strcpy (name
,cmd_pnt
[i
].name
);
927 if (*command
== 'K') strcat (name
,command
+9);
929 if (*command
== 'M') put_mousemovement (command
,name
);
931 strcpy (last_name
,name
);
932 *command_num_rel
= (word
)(i
- rem_pnt
[cmd_pnt
[i
].remote
].command_start
);
934 *remote_num
= cmd_pnt
[i
].remote
;
935 last_address
= address
;
942 if (!start
) last_name
[0] = 0;
947 int cmpRawData (byte
*rcv
,byte
*mem
,int len
)
950 word recvdata
,memdata
;
951 getRawValue (rcv
,pos
,&recvdata
);
952 pos
= getRawValue (mem
,pos
,&memdata
);
954 if (recvdata
< (memdata
- (RAW_TOLERANCE
+ (memdata
>> 4))) ||
955 recvdata
> (memdata
+ (RAW_TOLERANCE
+ (memdata
>> 4)))) return (0);
956 getRawValue (rcv
,pos
,&recvdata
);
957 pos
= getRawValue (mem
,pos
,&memdata
);
963 int getRawValue (byte
*pnt
,int pos
,word
*val
)
968 *val
= pnt
[pos
++] << 8;
976 int DBFindRemoteCommand (char remote
[],char command
[],int *cmd_num
,int *rem_num
)
984 memset (remcmp
,0,100);
985 memset (cmdcmp
,0,100);
987 strcpy (remcmp
,remote
);
988 strcpy (cmdcmp
,command
);
989 ConvertLcase (remcmp
,(int)strlen (remcmp
));
990 ConvertLcase (cmdcmp
,(int)strlen (cmdcmp
));
993 nrem
= DBFindRemote (remcmp
);
994 if (nrem
== -1) return (ERR_REMOTENOTFOUND
);
995 if (rem_num
) *rem_num
= nrem
;
996 ncmd
= DBFindCommand (cmdcmp
,nrem
);
997 if (ncmd
== -1) return (ERR_COMMANDNOTFOUND
);
1002 int DBGetRepeatCode (int cmd_num
,IRDATA
*ir
,byte calflag
)
1004 int mac_len
,mac_pause
;
1010 m_pnt
= (IRMACRO
*)(cmd_pnt
+ cmd_num
);
1012 if (cmd_pnt
[cmd_num
].mode
== MACRO_DATA
) return (-1);
1015 nrem
= cmd_pnt
[ncmd
].remote
;
1017 memset (cmd
,' ',20);
1018 memcpy (cmd
,cmd_pnt
[ncmd
].name
,20);
1019 cmd
[strlen (cmd_pnt
[ncmd
].name
)] = '@';
1020 nrep
= DBFindCommand (cmd
,nrem
);
1021 if (nrep
== -1) return (ERR_COMMANDNOTFOUND
);
1023 return (DBGetIRCode (nrep
,ir
,0,&mac_len
,&mac_pause
,0,calflag
));
1026 int DBGetIRCode (int cmd_num
,IRDATA
*ir
,int idx
,int *mac_len
,int *mac_pause
,int *rpt_len
,byte calflag
)
1029 int nrem
,ncmd
,ntim
,mcmd
;
1034 m_pnt
= (IRMACRO
*)(cmd_pnt
+ cmd_num
);
1036 if (cmd_pnt
[cmd_num
].mode
== MACRO_DATA
) {
1037 *mac_len
= m_pnt
->macro_len
;
1038 res
= DBFindRemoteCommand (mac_pnt
[m_pnt
->macro_num
+ idx
].mac_remote
,mac_pnt
[m_pnt
->macro_num
+ idx
].mac_command
,&mcmd
,NULL
);
1039 if (res
) return (res
);
1041 *mac_pause
= mac_pnt
[m_pnt
->macro_num
+ idx
].pause
;
1050 nrem
= cmd_pnt
[ncmd
].remote
;
1052 if (cmd_pnt
[ncmd
].mode
& RAW_DATA
) {
1054 memset (rd
,0,sizeof (IRRAW
));
1055 rd
->mode
= cmd_pnt
[ncmd
].mode
;
1056 rd
->target_mask
= rem_pnt
[nrem
].target_mask
;
1057 if (rem_pnt
[nrem
].transmitter
) rd
->address
= rem_pnt
[nrem
].transmitter
;
1058 if (cmd_pnt
[ncmd
].timing
> 127) {
1059 if (cmd_pnt
[ncmd
].timing
> 500) rd
->transmit_freq
= 255;
1060 else rd
->transmit_freq
= (byte
)((cmd_pnt
[ncmd
].timing
/ 4) | 128);
1063 else rd
->transmit_freq
= (byte
)cmd_pnt
[ncmd
].timing
;
1064 rd
->ir_length
= (byte
)cmd_pnt
[ncmd
].ir_length
;
1065 memcpy (rd
->data
,cmd_pnt
[ncmd
].data
,CODE_LENRAW
);
1066 if (rpt_len
) *rpt_len
= cmd_pnt
[ncmd
].command_length
;
1068 if (!cmd_pnt
[ncmd
].mode
) {
1069 ntim
= rem_pnt
[nrem
].timing_start
+ cmd_pnt
[ncmd
].timing
;
1070 if (ntim
>= rem_pnt
[nrem
].timing_end
) return (ERR_TIMINGNOTFOUND
);
1072 memset (ir
,0,sizeof (IRDATA
));
1074 ir
->target_mask
= rem_pnt
[nrem
].target_mask
;
1075 if (rem_pnt
[nrem
].transmitter
) ir
->address
= rem_pnt
[nrem
].transmitter
;
1076 memcpy (&ir
->transmit_freq
,&tim_pnt
[ntim
].transmit_freq
,sizeof (IRTIMING
));
1078 if ((calflag
&& cmd_pnt
[ncmd
].ir_length_cal
> CODE_LEN
) || cmd_pnt
[ncmd
].ir_length
> CODE_LEN
) { // Long Codes packen
1082 while (p
< cmd_pnt
[ncmd
].ir_length_cal
) {
1083 if (cmd_pnt
[ncmd
].data_cal
[p
] & 128) ir
->data
[i
++] = cmd_pnt
[ncmd
].data_cal
[p
++];
1085 ir
->data
[i
] = (cmd_pnt
[ncmd
].data_cal
[p
++] & 7);
1086 if (p
< cmd_pnt
[ncmd
].ir_length_cal
) ir
->data
[i
] |= ((cmd_pnt
[ncmd
].data_cal
[p
] & 7) << 4);
1092 ir
->data
[0] |= LONG_CODE_FLAG
;
1093 if (p
> cmd_pnt
[ncmd
].ir_length_cal
) ir
->data
[0] |= LONG_CODE_LEN
;
1097 while (p
< cmd_pnt
[ncmd
].ir_length
) {
1098 if (cmd_pnt
[ncmd
].data
[p
] & 128) p
++;
1100 ir
->data
[i
] = (cmd_pnt
[ncmd
].data
[p
++] & 7);
1101 if (p
< cmd_pnt
[ncmd
].ir_length
) ir
->data
[i
] |= ((cmd_pnt
[ncmd
].data
[p
] & 7) << 4);
1107 ir
->data
[0] |= LONG_CODE_FLAG
;
1108 if (p
> cmd_pnt
[ncmd
].ir_length
) ir
->data
[0] |= LONG_CODE_LEN
;
1114 memcpy (ir
->data
,cmd_pnt
[ncmd
].data_cal
,CODE_LEN
);
1115 ir
->ir_length
= (byte
)cmd_pnt
[ncmd
].ir_length_cal
;
1118 memcpy (ir
->data
,cmd_pnt
[ncmd
].data
,CODE_LEN
);
1119 ir
->ir_length
= (byte
)cmd_pnt
[ncmd
].ir_length
;
1123 if (ir
->mode
& NO_TOGGLE_H
) {
1124 if (ir
->mode
& RC5_DATA
) ir
->data
[2] = '1';
1125 else if (ir
->mode
& RC6_DATA
) {
1126 if (ir
->ir_length
== 40) ir
->data
[23] = '1';
1127 else ir
->data
[5] = '1';
1130 ir
->mode
&= NO_TOGGLE_H
-1;
1133 *rpt_len
= cmd_pnt
[ncmd
].command_length
;
1134 if (mac_pause
&& *rpt_len
) *mac_pause
= cmd_pnt
[ncmd
].pause
;
1143 int DBFindRemoteCommandEx(char remote
[],char command
[],IRDATA
*ir
,byte calflag
)
1152 memset (remcmp
,0,100);
1153 memset (cmdcmp
,0,100);
1155 strcpy (remcmp
,remote
);
1156 strcpy (cmdcmp
,command
);
1157 ConvertLcase (remcmp
,(int)strlen (remcmp
));
1158 ConvertLcase (cmdcmp
,(int)strlen (cmdcmp
));
1161 nrem
= DBFindRemote (remcmp
);
1162 if (nrem
== -1) return (ERR_REMOTENOTFOUND
);
1163 ncmd
= DBFindCommand (cmdcmp
,nrem
);
1164 if (ncmd
== -1) return (ERR_COMMANDNOTFOUND
);
1166 if (cmd_pnt
[ncmd
].mode
== MACRO_DATA
) return (ERR_ISMACRO
);
1168 if (cmd_pnt
[ncmd
].mode
& RAW_DATA
) {
1170 memset (rd
,0,sizeof (IRRAW
));
1171 rd
->mode
= cmd_pnt
[ncmd
].mode
;
1172 rd
->target_mask
= rem_pnt
[nrem
].target_mask
;
1173 if (rem_pnt
[nrem
].transmitter
) rd
->address
= rem_pnt
[nrem
].transmitter
;
1174 // if (extended_carrier) {
1175 if (cmd_pnt
[ncmd
].timing
> 127) {
1176 if (cmd_pnt
[ncmd
].timing
> 500) rd
->transmit_freq
= 255;
1177 else rd
->transmit_freq
= (byte
)((cmd_pnt
[ncmd
].timing
/ 4) | 128);
1179 else rd
->transmit_freq
= (byte
)cmd_pnt
[ncmd
].timing
;
1181 rd
->ir_length
= (byte
)cmd_pnt
[ncmd
].ir_length
;
1182 memcpy (rd
->data
,cmd_pnt
[ncmd
].data
,CODE_LENRAW
);
1184 if (!cmd_pnt
[ncmd
].mode
) {
1185 ntim
= rem_pnt
[nrem
].timing_start
+ cmd_pnt
[ncmd
].timing
;
1186 if (ntim
>= rem_pnt
[nrem
].timing_end
) return (ERR_TIMINGNOTFOUND
);
1188 memset (ir
,0,sizeof (IRDATA
));
1190 ir
->target_mask
= rem_pnt
[nrem
].target_mask
;
1191 if (rem_pnt
[nrem
].transmitter
) ir
->address
= rem_pnt
[nrem
].transmitter
;
1192 memcpy (&ir
->transmit_freq
,&tim_pnt
[ntim
].transmit_freq
,sizeof (IRTIMING
));
1195 if ((calflag
&& cmd_pnt
[ncmd
].ir_length_cal
> CODE_LEN
) || cmd_pnt
[ncmd
].ir_length
> CODE_LEN
) { // Long Codes packen
1199 while (p
< cmd_pnt
[ncmd
].ir_length_cal
) {
1200 if (cmd_pnt
[ncmd
].data_cal
[p
] & 128) ir
->data
[i
++] = cmd_pnt
[ncmd
].data_cal
[p
++];
1202 ir
->data
[i
] = (cmd_pnt
[ncmd
].data_cal
[p
++] & 7);
1203 if (p
< cmd_pnt
[ncmd
].ir_length_cal
) ir
->data
[i
] |= ((cmd_pnt
[ncmd
].data_cal
[p
] & 7) << 4);
1209 ir
->data
[0] |= LONG_CODE_FLAG
;
1210 if (p
> cmd_pnt
[ncmd
].ir_length_cal
) ir
->data
[0] |= LONG_CODE_LEN
;
1214 while (p
< cmd_pnt
[ncmd
].ir_length
) {
1215 if (cmd_pnt
[ncmd
].data
[p
] & 128) p
++;
1217 ir
->data
[i
] = (cmd_pnt
[ncmd
].data
[p
++] & 7);
1218 if (p
< cmd_pnt
[ncmd
].ir_length
) ir
->data
[i
] |= ((cmd_pnt
[ncmd
].data
[p
] & 7) << 4);
1224 ir
->data
[0] |= LONG_CODE_FLAG
;
1225 if (p
> cmd_pnt
[ncmd
].ir_length
) ir
->data
[0] |= LONG_CODE_LEN
;
1231 memcpy (ir
->data
,cmd_pnt
[ncmd
].data_cal
,CODE_LEN
);
1232 ir
->ir_length
= (byte
)cmd_pnt
[ncmd
].ir_length_cal
;
1235 memcpy (ir
->data
,cmd_pnt
[ncmd
].data
,CODE_LEN
);
1236 ir
->ir_length
= (byte
)cmd_pnt
[ncmd
].ir_length
;
1240 if (ir
->mode
& NO_TOGGLE_H
) {
1241 if (ir
->mode
& RC5_DATA
) ir
->data
[2] = '1';
1242 else if (ir
->mode
& RC6_DATA
) {
1243 if (ir
->ir_length
== 40) ir
->data
[23] = '1';
1244 else ir
->data
[5] = '1';
1247 ir
->mode
&= NO_TOGGLE_H
-1;
1256 int DBFindCommand (char command
[],int remote
)
1259 int i
= rem_pnt
[remote
].command_start
;
1260 while (i
< rem_pnt
[remote
].command_end
) {
1261 if (!memcmp (command
,cmd_pnt
[i
].name
,20)) {
1262 if (rem_pnt
[remote
].toggle_pos
) {
1263 s
= rem_pnt
[remote
].toggle_pos
;
1265 while ((cmd_pnt
[p
].toggle_seq
!= s
|| memcmp (command
,cmd_pnt
[p
].name
,20)) && p
< rem_pnt
[remote
].command_end
) p
++;
1266 if (cmd_pnt
[p
].toggle_seq
== s
) {
1267 rem_pnt
[remote
].toggle_pos
++;
1271 rem_pnt
[remote
].toggle_pos
= 2;
1276 else if (cmd_pnt
[i
].toggle_seq
) {
1277 s
= cmd_pnt
[i
].toggle_pos
;
1279 while ((cmd_pnt
[p
].toggle_seq
!= s
|| memcmp (command
,cmd_pnt
[p
].name
,20)) && p
< rem_pnt
[remote
].command_end
) p
++;
1280 if (cmd_pnt
[p
].toggle_seq
== s
) {
1281 cmd_pnt
[i
].toggle_pos
++;
1285 cmd_pnt
[i
].toggle_pos
= 2;
1297 int DBFindRemote (char remote
[])
1300 while (i
< rem_cnt
) {
1301 if (!memcmp (remote
,rem_pnt
[i
].name
,80)) return (i
);
1309 int StoreSwitch (word id
,word num
,char *rem
,char *com
,word mode
)
1312 while (i
< switch_cnt
) {
1313 if (switches
[i
].id
== id
&& switches
[i
].num
== num
) {
1314 switches
[i
].mode
= mode
;
1315 strcpy (switches
[i
].remote
,rem
);
1316 strcpy (switches
[i
].command
,com
);
1322 switches
= realloc (switches
,(switch_cnt
+ 1) * sizeof (SWITCH
));
1323 switches
[switch_cnt
].id
= id
;
1324 switches
[switch_cnt
].num
= num
;
1325 switches
[switch_cnt
].mode
= mode
;
1326 strcpy (switches
[switch_cnt
].remote
,rem
);
1327 strcpy (switches
[switch_cnt
].command
,com
);
1334 void WriteSwitches (void)
1340 if (switch_cnt
== 0) return;
1342 fp
= DBOpenFile ("switches.cfg","w");
1344 while (i
< switch_cnt
) {
1345 if (*switches
[i
].remote
&& *switches
[i
].command
) {
1346 if (switches
[i
].mode
== 1) m
= 'T';
1347 if (switches
[i
].mode
== 2) m
= 'S';
1348 if (switches
[i
].mode
== 4) m
= '0';
1349 if (switches
[i
].mode
== 8) m
= '1';
1350 fprintf (fp
,"[ID]%02d.%02d [NR]%d [%c] %s %s\n",switches
[i
].id
>> 8,switches
[i
].id
& 0xff,switches
[i
].num
,m
,switches
[i
].remote
,switches
[i
].command
);
1359 int FindSwitch (word id
,word num
,char *rem
,char *com
,word
*mode
)
1365 while (i
< switch_cnt
) {
1366 if (switches
[i
].id
== id
&& switches
[i
].num
== num
) {
1367 *mode
= switches
[i
].mode
;
1368 strcpy (rem
,switches
[i
].remote
);
1369 strcpy (com
,switches
[i
].command
);
1377 void ReadSwitches (void)
1381 char ln
[2048],*data
;
1384 fp
= DBOpenFile ("switches.cfg","r");
1391 data
= DBReadString (ln
,fp
,NULL
);
1395 while (ln
[i
] && ln
[i
] != ']') i
++;
1397 if (ln
[i
+2] == '.') {
1399 sw
.id
= atoi (ln
+ i
) * 256 + atoi (ln
+ i
+ 3);
1402 else sw
.id
= atoi (ln
+ i
);
1404 while (ln
[i
] && ln
[i
] != ']') i
++;
1406 sw
.num
= atoi (ln
+ i
);
1409 while (ln
[i
] && ln
[i
] != '[') i
++;
1411 if (ln
[i
] == 'T') sw
.mode
= 1;
1412 if (ln
[i
] == 'S') sw
.mode
= 2;
1413 if (ln
[i
] == '0') sw
.mode
= 4;
1414 if (ln
[i
] == '1') sw
.mode
= 8;
1418 while (ln
[i
] == ' ' || ln
[i
] == '\t') i
++;
1420 while (ln
[i
] != ' ' && ln
[i
] != '\t') i
++;
1422 strcpy (sw
.remote
,ln
+ j
);
1423 while (ln
[i
] == ' ' || ln
[i
] == '\t') i
++;
1424 strcpy (sw
.command
,ln
+ i
);
1426 switches
= realloc (switches
,(switch_cnt
+ 1) * sizeof (SWITCH
));
1427 switches
[switch_cnt
++] = sw
;
1429 data
= DBReadString (ln
,fp
,NULL
);
1436 void ReadRoutingTable (void)
1442 fp
= DBOpenFile ("routing","r");
1444 if (!fp
) return; // No routing table found
1446 res
= DBStoreRooms (fp
); // Read Rooms
1448 DBStoreRouting (fp
,"SEND-ROUTING",&send_routing
,&send_routing_cnt
); // Read Recv Routing
1449 DBStoreRouting (fp
,"RECV-ROUTING",&recv_routing
,&recv_routing_cnt
); // Read Send Routing
1458 void ReadAppConfig (void)
1462 int i
,j
,p
,cf
,res
,cnum
;
1464 char ln
[2048],*data
,lchar
;
1466 fp
= DBOpenFile ("apps.cfg","r");
1468 if (!fp
) return; // No APP Config found
1476 data
= DBReadString (ln
,fp
,NULL
);
1481 if (!strncmp (data
,"[APP]",5)) {
1482 strcpy (app_pnt
[app_cnt
].name
,data
+ 5);
1483 app_pnt
[app_cnt
].com_cnt
= 0;
1485 else if (!strncmp (data
,"[CLASSNAME]",11)) {
1486 strcpy (app_pnt
[app_cnt
].classname
,data
+ 11);
1488 else if (!strncmp (data
,"[APPNAME]",9)) {
1489 strcpy (app_pnt
[app_cnt
].appname
,data
+ 9);
1491 else if (!strncmp (data
,"[ACTIVE]",8)) {
1492 app_pnt
[app_cnt
].active
= 1;
1494 else if (!strncmp (data
,"[TYPE]",6)) {
1495 if (!strcmp (data
+6,"MCE")) app_pnt
[app_cnt
].type
= TYPE_MCE
;
1496 if (!strcmp (data
+6,"KEY")) app_pnt
[app_cnt
].type
= TYPE_KEY
;
1497 if (!strcmp (data
+6,"APPCOM")) app_pnt
[app_cnt
].type
= TYPE_APPCOM
;
1498 if (!strcmp (data
+6,"COM")) app_pnt
[app_cnt
].type
= TYPE_COM
;
1499 if (!strcmp (data
+6,"KEYBOARD")) app_pnt
[app_cnt
].type
= TYPE_KEYBOARD
;
1500 if (!strcmp (data
+6,"SCANCODE")) app_pnt
[app_cnt
].type
= TYPE_SCANCODE
;
1501 if (!strcmp (data
+6,"MOUSE")) app_pnt
[app_cnt
].type
= TYPE_MOUSE
;
1502 //------------------------------------------modified------------------------------------------
1503 if (!strcmp (data
+6,"SHORTCUT")) app_pnt
[app_cnt
].type
= TYPE_SHORTCUT
;
1505 else if (!strncmp (data
,"[REMOTE]",8)) {
1506 strcpy (app_pnt
[app_cnt
].remote
,data
+ 8);
1507 ConvertLcase (app_pnt
[app_cnt
].remote
,(int)strlen (app_pnt
[app_cnt
].remote
));
1508 app_pnt
[app_cnt
].remnum
= DBFindRemote (app_pnt
[app_cnt
].remote
);
1510 else if (!strncmp (data
,"[COMMANDS]",10)) {
1513 else if (!strncmp (data
,"[END-COMMANDS]",14)) {
1516 else if (!strncmp (data
,"[END-APP]",9)) {
1522 while (data
[i
] && data
[i
] != ' ' && data
[i
] != '\t' && data
[i
] != '[') i
++;
1523 if (data
[i
] == ' ' || data
[i
] == '\t') data
[i
++] = 0;
1524 ConvertLcase (data
,(int)strlen (data
));
1525 while (data
[i
] && data
[i
] != '[') i
++;
1526 if (!data
[i
]) continue;
1527 res
= DBFindRemoteCommand (app_pnt
[app_cnt
].remote
,data
,&app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].comnum
,&app_pnt
[app_cnt
].remnum
);
1533 while (data
[j
] && data
[j
] != ' ' && data
[j
] != '\t' && data
[j
] != '[') j
++;
1536 ConvertLcase (data
+i
,(int)strlen (data
+i
));
1537 if (!strncmp (data
+p
,"[FNC]",5)) {
1538 res
= GetFunctionCode (app_pnt
[app_cnt
].type
,data
+i
);
1539 if (!res
) goto notfound
;
1540 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].type
[cnum
] = app_pnt
[app_cnt
].type
;
1541 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].function
[cnum
] = res
;
1544 else if (!strncmp (data
+p
,"[KEY]",5)) {
1545 res
= GetKeyCode (data
+i
);
1546 if (!res
) goto notfound
;
1547 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].type
[cnum
] = TYPE_KEY
;
1548 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].function
[cnum
] = res
;
1551 else if (!strncmp (data
+p
,"[KEF]",5)) {
1552 res
= GetKeyCode (data
+i
);
1553 if (!res
) goto notfound
;
1554 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].type
[cnum
] = TYPE_KEYF
;
1555 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].function
[cnum
] = res
;
1558 else if (!strncmp (data
+p
,"[CHR]",5)) {
1559 res
= GetKeyCode (data
+i
);
1560 if (!res
) goto notfound
;
1561 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].type
[cnum
] = TYPE_CHR
;
1562 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].function
[cnum
] = res
;
1565 else if (!strncmp (data
+p
,"[APP]",5)) {
1566 res
= GetFunctionCode (TYPE_APPCOM
,data
+i
);
1567 if (!res
) goto notfound
;
1568 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].type
[cnum
] = TYPE_APPCOM
;
1569 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].function
[cnum
] = res
;
1572 else if (!strncmp (data
+p
,"[RUN]",5)) {
1573 app_pnt
[app_cnt
].com
[app_pnt
[app_cnt
].com_cnt
].type
[cnum
] = TYPE_RUN
;
1580 if (cnum
) app_pnt
[app_cnt
].com_cnt
++;
1587 void DBStoreRouting (FILE *fp
,char section
[],ROUTING
**pnt
,int *cnt
)
1590 char ln
[2048],*data
;
1594 data
= DBFindSection (fp
,section
,NULL
,NULL
,NULL
);
1599 data
= DBFindSection (fp
,"REM",ln
,"[END]",NULL
);
1602 while (data
[i
] && data
[i
] != '[') i
++;
1603 if (data
[i
] == '[') {
1605 while (data
[i
] && data
[i
] != ']') i
++;
1606 if (data
[i
] == ']') {
1608 *pnt
= realloc (*pnt
,(*cnt
+ 1) * sizeof (ROUTING
));
1609 memset (*pnt
+ *cnt
,0,sizeof (ROUTING
));
1610 if (strlen (data
) > 80) data
[80] = 0;
1611 ConvertLcase (data
,(int)strlen (data
));
1612 ((*pnt
) + *cnt
)->target_mask
= (word
)strtol (data
+ i
,NULL
,0);
1613 strncpy (((*pnt
) + *cnt
)->name
,data
,80);
1621 int DBStoreRooms (FILE *fp
)
1624 char ln
[2048],*data
;
1629 data
= DBFindSection (fp
,"ADDRESS",NULL
,NULL
,NULL
);
1631 if (!data
) return (-1);
1633 data
= DBFindSection (fp
,"NAME",ln
,NULL
,NULL
);
1636 while (data
[i
] && data
[i
] != '[') i
++;
1637 if (data
[i
] == '[') {
1639 while (data
[i
] && data
[i
] != ']') i
++;
1640 if (data
[i
] == ']') {
1642 rooms
= realloc (rooms
,(room_cnt
+ 1) * sizeof (ROOMS
));
1643 memset (rooms
+ room_cnt
,0,sizeof (ROOMS
));
1644 if (strlen (data
) > 80) data
[80] = 0;
1645 ConvertLcase (data
,(int)strlen (data
));
1646 rooms
[room_cnt
].addr
= atoi (data
+ i
);
1647 strncpy (rooms
[room_cnt
].name
,data
,80);
1658 int DBReadCommandFile (char remote
[])
1661 char includeremote
[100];
1665 fp
= DBOpenFile (remote
,"r");
1667 if (!fp
) return (ERR_DBOPENINPUT
);
1669 res
= DBStoreRemote (fp
,includeremote
);
1671 if (*includeremote
) {
1672 if (strcmp (includeremote
+ strlen (includeremote
) - 4,".rem")) strcat (includeremote
,".rem");
1674 fp
= DBOpenFile (includeremote
,"r");
1676 if (!fp
) return (ERR_DBOPENINCLUDE
);
1678 res
= DBStoreTimings (fp
);
1680 res
= DBStoreCommands (fp
);
1682 sprintf (st
,"Remote %-20s compiled:",rem_pnt
[rem_cnt
].name
);
1683 log_print (st
,LOG_INFO
);
1684 sprintf (st
," %4d Timings - ",rem_pnt
[rem_cnt
].timing_end
-rem_pnt
[rem_cnt
].timing_start
);
1685 log_print (st
,LOG_INFO
);
1686 sprintf (st
," %4d Commands\n",rem_pnt
[rem_cnt
].command_end
-rem_pnt
[rem_cnt
].command_start
);
1687 log_print (st
,LOG_INFO
);
1696 void FindDuplicateCommands (void)
1702 while (i
< cmd_cnt
) {
1704 if (cmd_pnt
[i
].mode
== 0 && cmd_pnt
[i
].name
[strlen (cmd_pnt
[i
].name
) - 1] != '@') {
1706 while (j
< cmd_cnt
) {
1707 if (cmd_pnt
[j
].mode
== 0 && cmd_pnt
[j
].name
[strlen (cmd_pnt
[j
].name
) - 1] != '@') {
1708 if (cmd_pnt
[i
].ir_length
== cmd_pnt
[j
].ir_length
&& !memcmp (cmd_pnt
[j
].data
,cmd_pnt
[i
].data
,cmd_pnt
[i
].ir_length
)) {
1710 sprintf (st
,"Duplicate Commands for %s.%s: ",rem_pnt
[cmd_pnt
[i
].remote
].name
,cmd_pnt
[i
].name
);
1711 log_print (st
,LOG_ERROR
);
1713 sprintf (st
," %s.%s",rem_pnt
[cmd_pnt
[j
].remote
].name
,cmd_pnt
[j
].name
);
1714 log_print (st
,LOG_ERROR
);
1722 log_print (st
,LOG_ERROR
);
1730 void DBShowStatus (void)
1733 sprintf (st
,"Total: %3d Remotes - %3d Timings - %4d Commands - %4d Calib. Commands\n",rem_cnt
,tim_cnt
,cmd_cnt
,cal_cnt
);
1734 FindDuplicateCommands ();
1735 log_print (st
,LOG_INFO
);
1736 sprintf (st
," %3d CCF Data - %3d CCF RAW - %4d CCF Error\n",ccf_data
,ccf_raw
,ccf_err
);
1737 log_print (st
,LOG_INFO
);
1740 int DBStoreCommands (FILE *fp
)
1742 int i
,p
,j
,ccf_rpt
,ccf_pause
,cmd_length
,n
,res
,maxlen
,ntim
;
1743 char ln
[2048],*data
,st
[255];
1746 rem_pnt
[rem_cnt
].command_start
= cmd_cnt
;
1747 rem_pnt
[rem_cnt
].command_end
= cmd_cnt
;
1749 if (time_len
== TIME_LEN
) maxlen
= CODE_LENRAW
;
1750 else maxlen
= OLD_LENRAW
;
1751 data
= DBFindSection (fp
,"COMMANDS",NULL
,NULL
,NULL
);
1753 if (!data
) return (-1);
1755 data
= DBReadString (ln
,fp
,NULL
);
1756 if (data
&& *data
== '[') {
1757 ccf_rpt
= ccf_pause
= cmd_length
= 0;
1760 while (data
[i
] && data
[i
] != ']') i
++;
1762 cmd_pnt
= realloc (cmd_pnt
,(cmd_cnt
+ 1) * sizeof (IRCOMMAND
));
1763 memset (cmd_pnt
+ cmd_cnt
,0,sizeof (IRCOMMAND
));
1765 if (strlen (data
) > 20) data
[20] = 0;
1766 ConvertLcase (data
,(int)strlen (data
));
1767 if (data
[strlen (data
) - 3] == '#') {
1768 data
[strlen (data
) - 3] = 0;
1769 memcpy (cmd_pnt
[cmd_cnt
].name
,data
,strlen (data
));
1771 if (atoi (data
+ strlen (data
) + 1) == 1) while (j
>= 0) {
1772 if (!memcmp (cmd_pnt
[j
].name
,cmd_pnt
[cmd_cnt
].name
,20) && !cmd_pnt
[j
].toggle_seq
) {
1773 cmd_pnt
[j
].toggle_seq
= 1;
1774 cmd_pnt
[j
].toggle_pos
= 1;
1779 cmd_pnt
[cmd_cnt
].toggle_seq
= atoi (data
+ strlen (data
) + 1) + 1;
1782 cmd_pnt
[cmd_cnt
].toggle_seq
= 0;
1783 memcpy (cmd_pnt
[cmd_cnt
].name
,data
,strlen (data
));
1786 cmd_pnt
[cmd_cnt
].toggle_pos
= 0;
1787 cmd_pnt
[cmd_cnt
].remote
= rem_cnt
;
1788 if (!memcmp (data
+ i
,"[RL]",4)) {
1790 cmd_length
= atoi (data
+ i
);
1791 while (data
[i
] && data
[i
] != '[') i
++;
1793 if (!memcmp (data
+ i
,"[RC]",4)) {
1795 ccf_rpt
= atoi (data
+ i
);
1797 while (data
[i
] && data
[i
] != '[') i
++;
1799 if (!memcmp (data
+ i
,"[RP]",4)) {
1801 ccf_pause
= atoi (data
+ i
);
1802 while (data
[i
] && data
[i
] != '[') i
++;
1804 if (!memcmp (data
+ i
,"[RAW]",5)) {
1805 cmd_pnt
[cmd_cnt
].command_length
= cmd_length
;
1806 cmd_pnt
[cmd_cnt
].mode
= RAW_DATA
;
1809 while (data
[i
] && data
[i
] != '[') i
++;
1811 cmd_pnt
[cmd_cnt
].ir_length
= atoi (data
+p
);
1812 if (cmd_pnt
[cmd_cnt
].ir_length
<= maxlen
) {
1815 while (data
[i
] && data
[i
] != '[') i
++;
1817 cmd_pnt
[cmd_cnt
].timing
= atoi (data
+p
);
1821 while (i
< cmd_pnt
[cmd_cnt
].ir_length
) {
1822 cmd_pnt
[cmd_cnt
].data
[i
] = atoi (data
+ p
) / 8;
1823 while (data
[p
] && data
[p
] != ' ') p
++;
1830 else if (!memcmp (data
+ i
,"[MACRO]",7)) {
1831 m_pnt
= (IRMACRO
*)&cmd_pnt
[cmd_cnt
];
1832 cmd_pnt
[cmd_cnt
].mode
= MACRO_DATA
;
1836 while (data
[i
] && data
[i
] != '[') i
++;
1838 m_pnt
->macro_len
= atoi (data
+p
);
1839 m_pnt
->macro_num
= mac_cnt
;
1841 mac_pnt
= realloc (mac_pnt
,(mac_cnt
+ m_pnt
->macro_len
) * sizeof (MACROCOMMAND
));
1842 memset (mac_pnt
[mac_cnt
].mac_remote
,0,m_pnt
->macro_len
* sizeof (MACROCOMMAND
));
1843 for (n
=0;n
< m_pnt
->macro_len
&& !strncmp (data
+i
,"IR]",3);n
++) {
1845 if (data
[i
++] != '[') break;
1847 while (data
[i
] && data
[i
] != ']') i
++;
1848 if (data
[i
] != ']') break;
1850 strcpy (mac_pnt
[mac_cnt
+ n
].mac_remote
,data
+ p
);
1851 if (data
[i
++] != '[') break;
1853 while (data
[i
] && data
[i
] != ']') i
++;
1854 if (data
[i
] != ']') break;
1856 strcpy (mac_pnt
[mac_cnt
+ n
].mac_command
,data
+ p
);
1857 if (data
[i
++] != '[') break;
1859 while (data
[i
] && data
[i
] != ']') i
++;
1860 if (data
[i
] != ']') break;
1862 mac_pnt
[mac_cnt
+ n
].pause
= atoi (data
+ p
);
1866 m_pnt
->macro_len
= n
;
1871 else if (!memcmp (data
+ i
,"[CCF]",5)) {
1872 cmd_pnt
[cmd_cnt
].command_length
= cmd_length
;
1873 res
= DBStoreCCFCode (data
+ i
+ 5);
1875 sprintf (st
,"**** CCF Error: %s [See below for Remote name]\n",cmd_pnt
[cmd_cnt
].name
);
1876 log_print (st
,LOG_ERROR
);
1878 else cmd_cnt
+= res
;
1881 cmd_pnt
[cmd_cnt
].pause
= ccf_pause
;
1882 cmd_pnt
[cmd_cnt
].command_length
= cmd_length
;
1883 cmd_pnt
[cmd_cnt
].timing
= atoi (data
+ i
+ FindLineSection (data
+i
,"T"));
1884 ntim
= rem_pnt
[rem_cnt
].timing_start
+ cmd_pnt
[cmd_cnt
].timing
;
1886 if (ntim
< rem_pnt
[rem_cnt
].timing_end
) {
1887 tim_pnt
[ntim
].link_count
++;
1888 strcpy (cmd_pnt
[cmd_cnt
].data
,data
+ i
+ FindLineSection (data
+i
,"D"));
1889 ReadCalibrateData (cmd_pnt
[cmd_cnt
].data
,cmd_pnt
[cmd_cnt
].data_cal
);
1890 if (tim_pnt
[rem_pnt
[cmd_pnt
[cmd_cnt
].remote
].timing_start
+ cmd_pnt
[cmd_cnt
].timing
].mode
== IRDA_DATA
) ConvertIRDARAW (cmd_pnt
[cmd_cnt
].data
);
1891 cmd_pnt
[cmd_cnt
].ir_length
= (word
)strlen (cmd_pnt
[cmd_cnt
].data
);
1892 cmd_pnt
[cmd_cnt
].ir_length_cal
= (word
)strlen (cmd_pnt
[cmd_cnt
].data_cal
);
1893 cmd_pnt
[cmd_cnt
].mode
= 0;
1894 if (tim_pnt
[cmd_pnt
[cmd_cnt
].timing
+ rem_pnt
[rem_cnt
].timing_start
].time_cnt
<= time_len
) cmd_cnt
++;
1903 rem_pnt
[rem_cnt
].command_end
= cmd_cnt
;
1908 void ReadCalibrateData (byte
*pnt
,byte
*pntcal
)
1910 int j
= 0,i
= 0,val
;
1913 if (pnt
[i
] == '#') break;
1917 strcpy (pntcal
,pnt
);
1924 if (pnt
[i
] == '#') {
1927 val
= atoi(pnt
+i
) / 8;
1928 pntcal
[j
] = (byte
)(abs (val
)) | 128;
1929 if (val
< 0) pntcal
[j
] |= 64;
1933 else pntcal
[j
++] = pnt
[i
++];
1939 if (pntcal
[i
] & 128) i
++;
1940 else pnt
[j
++] = pntcal
[i
++];
1945 void ConvertIRDARAW (char data
[])
1955 for (i
=0;data
[i
] && j
< CODE_LEN
;i
++) {
1960 if (data
[i
+1]) tar
[j
++] = '0';
1968 int DBStoreCCFCode (char cd
[])
1974 res
= DecodeCCF (cd
,&ird
,START
);
1983 irr
= (IRRAW
*)&ird
;
1985 cmd_pnt
[cmd_cnt
].mode
= irr
->mode
;
1987 cmd_pnt
[cmd_cnt
].ir_length
= irr
->ir_length
;
1988 cmd_pnt
[cmd_cnt
].timing
= irr
->transmit_freq
;
1990 memcpy (cmd_pnt
[cmd_cnt
].data
,irr
->data
,irr
->ir_length
);
1995 cmd_pnt
= realloc (cmd_pnt
,(cmd_cnt
+ 1) * sizeof (IRCOMMAND
));
1996 memset (cmd_pnt
+ cmd_cnt
,0,sizeof (IRCOMMAND
));
1997 cmd_pnt
[cmd_cnt
].toggle_seq
= 0;
1998 memcpy (cmd_pnt
[cmd_cnt
].name
,cmd_pnt
[cmd_cnt
-1].name
,strlen (cmd_pnt
[cmd_cnt
-1].name
));
1999 strcat (cmd_pnt
[cmd_cnt
].name
,"@");
2001 DecodeCCF (cd
,&ird
,REPEAT
);
2002 cmd_pnt
[cmd_cnt
].mode
= irr
->mode
;
2004 cmd_pnt
[cmd_cnt
].ir_length
= irr
->ir_length
;
2005 cmd_pnt
[cmd_cnt
].timing
= irr
->transmit_freq
;
2007 memcpy (cmd_pnt
[cmd_cnt
].data
,irr
->data
,irr
->ir_length
);
2008 cmd_pnt
[cmd_cnt
].remote
= rem_cnt
;
2017 tim_pnt
= realloc (tim_pnt
,(tim_cnt
+ 1) * sizeof (IRTIMING
));
2018 memset (&tim_pnt
[tim_cnt
],0,sizeof (IRTIMING
));
2020 memcpy (&tim_pnt
[tim_cnt
].ir_length
,&ird
.ir_length
,sizeof (IRTIMING
) - 4);
2022 cmd_pnt
[cmd_cnt
].mode
= 0;
2024 cmd_pnt
[cmd_cnt
].ir_length
= ird
.ir_length
;
2025 cmd_pnt
[cmd_cnt
].timing
= tim_cnt
- rem_pnt
[rem_cnt
].timing_start
;
2026 cmd_pnt
[cmd_cnt
].remote
= rem_cnt
;
2028 memcpy (cmd_pnt
[cmd_cnt
].data
,ird
.data
,ird
.ir_length
);
2030 memcpy (cmd_pnt
[cmd_cnt
].data_cal
,ird
.data
,ird
.ir_length
); // Später ggf. auch Calibrate für CCF
2031 cmd_pnt
[cmd_cnt
].ir_length_cal
= ird
.ir_length
;
2037 cmd_pnt
= realloc (cmd_pnt
,(cmd_cnt
+ 1) * sizeof (IRCOMMAND
));
2038 memset (cmd_pnt
+ cmd_cnt
,0,sizeof (IRCOMMAND
));
2039 cmd_pnt
[cmd_cnt
].toggle_seq
= 0;
2040 memcpy (cmd_pnt
[cmd_cnt
].name
,cmd_pnt
[cmd_cnt
-1].name
,strlen (cmd_pnt
[cmd_cnt
-1].name
));
2041 strcat (cmd_pnt
[cmd_cnt
].name
,"@");
2043 DecodeCCF (cd
,&ird
,REPEAT
);
2044 tim_pnt
= realloc (tim_pnt
,(tim_cnt
+ 1) * sizeof (IRTIMING
));
2045 memset (&tim_pnt
[tim_cnt
],0,sizeof (IRTIMING
));
2047 memcpy (&tim_pnt
[tim_cnt
].ir_length
,&ird
.ir_length
,sizeof (IRTIMING
) - 4);
2049 cmd_pnt
[cmd_cnt
].mode
= 0;
2051 cmd_pnt
[cmd_cnt
].ir_length
= ird
.ir_length
;
2052 cmd_pnt
[cmd_cnt
].timing
= tim_cnt
- rem_pnt
[rem_cnt
].timing_start
;
2053 cmd_pnt
[cmd_cnt
].remote
= rem_cnt
;
2055 memcpy (cmd_pnt
[cmd_cnt
].data
,ird
.data
,ird
.ir_length
);
2057 memcpy (cmd_pnt
[cmd_cnt
].data_cal
,ird
.data
,ird
.ir_length
); // Später ggf. auch Calibrate für CCF
2058 cmd_pnt
[cmd_cnt
].ir_length_cal
= ird
.ir_length
;
2064 rem_pnt
[rem_cnt
].timing_end
= tim_cnt
;
2072 int DBStoreTimings (FILE *fp
)
2079 rem_pnt
[rem_cnt
].timing_start
= tim_cnt
;
2080 rem_pnt
[rem_cnt
].timing_end
= tim_cnt
;
2083 data
= DBFindSection (fp
,"TIMING",NULL
,NULL
,NULL
);
2085 if (!data
) return (-1);
2089 sprintf (st
,"%d",i
);
2090 data
= DBFindSection (fp
,st
,ln
,"[COMMANDS]",NULL
);
2092 tim_pnt
= realloc (tim_pnt
,(tim_cnt
+ 1) * sizeof (IRTIMING
));
2093 StoreIRTiming (tim_pnt
+ tim_cnt
,ln
);
2098 rem_pnt
[rem_cnt
].timing_end
= tim_cnt
;
2104 int DBStoreRemote (FILE *fp
,char newremote
[])
2106 char name
[100],*data
,tra
[100];
2110 rem_pnt
= realloc (rem_pnt
,(rem_cnt
+ 1) * sizeof (IRREMOTE
));
2112 data
= DBFindSection (fp
,"REMOTE",NULL
,NULL
,NULL
);
2114 if (!data
) return (-1);
2116 data
= DBFindSection (fp
,"NAME",name
,"[TIMING]",NULL
);
2118 if (!data
) return (-1);
2121 memset (&rem_pnt
[rem_cnt
],0,sizeof (IRREMOTE
));
2122 ConvertLcase (data
,(int)strlen (data
));
2123 strncpy (rem_pnt
[rem_cnt
].name
,data
,80);
2124 rem_pnt
[rem_cnt
].number
= rem_cnt
;
2125 GetRemoteAddressMask (rem_cnt
);
2127 data
= DBFindSection (fp
,"GLOBAL-TOGGLE",NULL
,NULL
,NULL
);
2128 if (data
) rem_pnt
[rem_cnt
].toggle_pos
= 1;
2132 data
= DBFindSection (fp
,"TRANSMITTER",tra
,"[TIMING]",NULL
);
2134 ConvertLcase (data
,(int)strlen (data
));
2135 if (!strcmp (data
,"extern") || !strcmp (data
,"external")) rem_pnt
[rem_cnt
].transmitter
= EXTERNAL_LEDS
;
2136 if (!strcmp (data
,"intern") || !strcmp (data
,"internal")) rem_pnt
[rem_cnt
].transmitter
= INTERNAL_LEDS
;
2137 if (!strcmp (data
,"both") || !strcmp (data
,"beide") || !strcmp (data
,"all") || !strcmp (data
,"alle")) rem_pnt
[rem_cnt
].transmitter
= INTERNAL_LEDS
| EXTERNAL_LEDS
;
2142 data
= DBFindSection (fp
,"RCV-LEN",tra
,"[TIMING]",NULL
);
2143 if (data
) rem_pnt
[rem_cnt
].rcv_len
= (byte
)atoi (data
);
2144 else rem_pnt
[rem_cnt
].rcv_len
= 0;
2148 data
= DBFindSection (fp
,"INCLUDE",newremote
,NULL
,NULL
);
2153 void GetRemoteAddressMask (int num
)
2157 rem_pnt
[num
].target_mask
= 0xffff;
2158 rem_pnt
[num
].source_mask
= 0xffff;
2160 while (i
< send_routing_cnt
) {
2161 if (!memcmp (rem_pnt
[num
].name
,send_routing
[i
].name
,80)) {
2162 rem_pnt
[num
].target_mask
= send_routing
[i
].target_mask
;
2168 while (i
< recv_routing_cnt
) {
2169 if (!memcmp (rem_pnt
[num
].name
,recv_routing
[i
].name
,80)) {
2170 rem_pnt
[num
].source_mask
= recv_routing
[i
].target_mask
;
2176 void StoreIRTiming (IRTIMING
*irp
,char data
[])
2178 int i
= 0,p
,flag
= 0,rp
;
2179 char cm
[10],par
[100];
2181 memset (irp
,0,sizeof (IRTIMING
));
2182 irp
-> transmit_freq
= 39;
2185 if (data
[i
] == '[') {
2188 while (data
[i
] && data
[i
] != ']') cm
[p
++] = data
[i
++];
2191 while (data
[i
] && data
[i
] != '[') i
++;
2192 strncpy (par
,data
+p
,i
-p
);
2194 if (!strcmp (cm
,"N")) irp
-> time_cnt
|= atoi (par
);
2195 if (*cm
>= '1' && *cm
<= TIME_LEN
+ 48) StorePulseTiming (irp
,cm
,par
);
2196 if (!strcmp (cm
,"RC")) irp
-> ir_repeat
= atoi (par
);
2197 if (!strcmp (cm
,"RP")) irp
-> repeat_pause
= (rp
= atoi (par
));
2198 if (!strcmp (cm
,"SB")) irp
-> mode
|= START_BIT
;
2199 if (!strcmp (cm
,"RS")) irp
-> mode
|= REPEAT_START
;
2200 if (!strcmp (cm
,"NOTOG")) flag
= 1;
2201 if (!strcmp (cm
,"NOTOG1")) flag
= 2;
2202 if (!strcmp (cm
,"FREQ")) {
2203 if (atoi (par
) > 127) {
2204 if (atoi (par
) > 500) irp
-> transmit_freq
= 255;
2205 else irp
-> transmit_freq
= (atoi (par
) / 4) | 128;
2207 else irp
-> transmit_freq
= atoi (par
);
2209 if (!strcmp (cm
,"RC5")) irp
-> mode
|= RC5_DATA
;
2210 if (!strcmp (cm
,"RC6")) irp
-> mode
|= RC6_DATA
;
2211 if (!strcmp (cm
,"IRDA-RAW")) {
2212 irp
-> mode
= IRDA_DATA
| START_BIT
;
2213 irp
-> transmit_freq
= 0;
2214 irp
-> repeat_pause
= rp
/ 100;
2216 if (!strcmp (cm
,"IRDA")) {
2217 irp
-> mode
= IRDA_DATA
;
2218 irp
-> transmit_freq
= 0;
2219 irp
-> repeat_pause
= rp
/ 100;
2224 if (!((irp
->mode
& IRDA_DATA
) == IRDA_DATA
) && irp
-> mode
& (RC5_DATA
| RC6_DATA
)) {
2225 irp
-> mode
&= ~START_MASK
;
2226 if (flag
) irp
-> mode
|= NO_TOGGLE
;
2227 if (flag
== 2) irp
-> mode
|= NO_TOGGLE_H
;
2231 void StorePulseTiming (IRTIMING
*irp
,char cmd
[],char data
[])
2235 while (data
[i
] && data
[i
] >= '0') i
++;
2237 if (!data
[i
]) return;
2240 irp
->pulse_len
[atoi (cmd
)-1] = atoi (data
) / 8;
2241 irp
->pause_len
[atoi (cmd
)-1] = atoi (data
+i
) / 8;
2244 int FindLineSection (char ln
[],char section
[])
2246 unsigned int pnt
,len
;
2249 sprintf (cmp
,"[%s]",section
);
2251 len
= (int)strlen (cmp
);
2255 while (len
+ pnt
< strlen (ln
)) {
2256 if (!memcmp (ln
+pnt
,cmp
,len
)) return (pnt
+len
);
2265 FILE *DBOpenFile (char remote
[],char mode
[])
2269 sprintf (nm
,"%s%c%s",dbpath
,PATH_SEPARATOR
,remote
);
2271 return (fopen (nm
,mode
));
2275 char *DBFindSection (FILE *fp
,char section
[],char data
[],char end
[],int *fpos
)
2278 static char ln
[2048];
2282 sprintf (cmp
,"[%s]",section
);
2283 len
= (int)strlen (cmp
);
2285 pnt
= DBReadString (ln
,fp
,fpos
);
2287 if (end
&& !strcmp (ln
,end
)) return (0);
2288 if (!strncmp (pnt
,cmp
,len
)) {
2289 if (data
) strcpy (data
,pnt
+len
);
2292 pnt
= DBReadString (ln
,fp
,fpos
);
2298 char *DBReadString (char ln
[],FILE *fp
,int *fpos
)
2304 if (fpos
) *fpos
= ftell (fp
);
2305 pnt
= fgets (ln
,2048,fp
);
2306 if (!pnt
) return (NULL
);
2307 while (*pnt
== ' ' || *pnt
== '\t') pnt
++;
2309 i
= (int)strlen (pnt
) - 1;
2311 while (i
&& pnt
[i
-1] && ((byte
)pnt
[i
-1]) <= ' ') i
--;
2313 if (((byte
)pnt
[i
]) <= ' ') pnt
[i
] = 0;
2314 } while (*pnt
== 0);
2319 void ConvertLcase (char *pnt
,int len
)
2323 pnt
[i
] = tolower (pnt
[i
]);