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.
45 #define closesocket close
48 #include <sys/socket.h>
49 #include <netinet/in.h>
51 #include <arpa/inet.h>
70 extern IRREMOTE
*rem_pnt
;
72 extern IRCOMMAND
*cmd_pnt
;
74 extern IRTIMING
*tim_pnt
;
80 #define INITIAL_VALUE 0x92f3
81 #define INITIAL_VALUE_V2 0x143a
84 void set_entry (char entry
[],int pos
,FLASH_CONTENT
*content
,byte type
,byte remote
,byte group
,byte shift
,byte setup
,word sourcemask
,word acc_timeout
,word acc_repeat
,char *version
,byte nmflag
,char *remname
,char *comname
,byte rcv_len
);
85 word
FindIRDBCommand (byte remote
[],byte command
[],IRDB_HEADER
*pnt
,byte vers
);
86 word
FindIRDBRemote (byte remote
[],IRDB_HEADER
*pnt
,byte vers
);
87 void ReadTraReceive (char tp
[]);
88 void ReadTraConfig ();
89 word
CRC (byte
*Data
, int Length
,word init
);
92 word flash_data
[65536];
95 TRANSLATECOMMAND trans
[10000];
96 IRDBCOMMAND irdb
[10000];
97 IRDBHEADER irdbheader
;
100 extern STATUS_BUFFER remote_statusex
[MAX_IR_DEVICES
];
102 void StoreDbItem (IRDBCOMMAND
*db
)
107 trans_num
= db
->number
;
109 if (db
->type
== IRDB_REM
|| db
->type
== IRDB_TYPEACTION
) {
111 memset (remcmp
,0,100);
112 memset (cmdcmp
,0,100);
114 strcpy (remcmp
,db
->remote
);
115 strcpy (cmdcmp
,db
->command
);
116 ConvertLcase (remcmp
,(int)strlen (remcmp
));
117 ConvertLcase (cmdcmp
,(int)strlen (cmdcmp
));
120 db
->remote_num
= DBFindRemote (remcmp
);
122 if (db
->type
== IRDB_TYPEACTION
) db
->command_num
= DBFindCommand (cmdcmp
,db
->remote_num
);
125 if (db
->type
== IRDB_TYPEHEADER
) {
126 memcpy (&irdbheader
,db
,sizeof (IRDBHEADER
));
128 memcpy (&irdb
[trans_num
],db
,sizeof (IRDBCOMMAND
));
133 void StoreTransItem (TRANSLATECOMMAND
*tr
)
135 trans_num
= tr
->number
;
136 memcpy (&trans
[trans_num
],tr
,sizeof (TRANSLATECOMMAND
));
141 int SetIRDBEx (byte bus
,int iradr
,STATUSBUFFER
*stat
)
145 int i
,j
,flashwordsize
,len
,lenf
,ntim
,act_cnt
;
146 word adr
,cmd_cnt
,rem_cnt
,com_adr
;
149 IRDB_REMOTE_COMPACT
*remc
;
150 IRDB_REMOTE_EX
*remex
;
153 IRDB_COMMAND_COMPACT
*comc
;
154 IRDB_IRCOMMAND
*ircom
;
156 IRDB_ACTION_EX
*actex
;
157 word rem_adr_det
[4000],cadr
;
159 IRDB_FLASHINFO
*finfo
;
162 finfo
= (IRDB_FLASHINFO
*)stat
;
163 memset (flash_data
,0,sizeof (flash_data
));
164 pnt
= (IRDB_HEADER
*)flash_data
;
168 if (strcmp (IRDevices
[bus
].version
+1,"5.04.17") >= 0) vers
= 1; // Erste IRDB Command Struktur
169 if (strcmp (IRDevices
[bus
].version
+1,"5.04.28") >= 0) vers
= 2; // GeƤnderte IRDB Command Struktur: Compact Structs
170 if (strcmp (IRDevices
[bus
].version
+1,"5.05.04") >= 0) vers
= 3; // EX IRDB Struktur (IPs, RS232 separat, Remote Action
171 calflag
= (IRDevices
[bus
].fw_capabilities
& FN_CALIBRATE
) != 0;
173 pnt
->type
= FLASH_TYPE_IRDB
;
175 adr
= pnt
->table
.remote_adr
= IRDB_HEADER_LEN
;
177 if (irdb
[0].type
== IRDB_TYPEHEADER
) {
178 memcpy (pnt
->table
.default_action
,irdbheader
.default_action
,100);
179 memcpy (pnt
->table
.return_stat_ok
,irdbheader
.ok_status
,20);
180 memcpy (pnt
->table
.return_stat_err
,irdbheader
.err_status
,20);
182 for (i
=0;i
<= 3;i
++) {
183 pnt
->table
.adc
[i
].mode
= irdbheader
.inputmode
[i
];
184 pnt
->table
.adc
[i
].low_value
= irdbheader
.min
[i
];
185 pnt
->table
.adc
[i
].high_value
= irdbheader
.max
[i
];
186 pnt
->table
.adc
[i
].hysteresis
= irdbheader
.hyst
[i
];
187 pnt
->table
.adc
[i
].low_ledsel
= irdbheader
.minledsel
[i
];
188 pnt
->table
.adc
[i
].high_ledsel
= irdbheader
.maxledsel
[i
];
189 pnt
->table
.adc
[i
].low_mask
= irdbheader
.minmask
[i
];
190 pnt
->table
.adc
[i
].high_mask
= irdbheader
.maxmask
[i
];
192 if (!(irdbheader
.active
& 1)) pnt
->type
= 0xffff; // Ausschalten der IRDB
194 if ((irdbheader
.active
& 2) && vers
>= 3) pnt
->type
= FLASH_TYPE_IRDBAUX
;
195 if ((irdbheader
.active
& 4) && vers
>= 3) pnt
->type
|= FLASH_MODE_LAN_DB
;
196 if ((irdbheader
.active
& 8) && vers
>= 3) pnt
->type
|= FLASH_MODE_LANRELAIS
;
202 rem
= (IRDB_REMOTE
*)(flash_data
+ adr
);
203 remc
= (IRDB_REMOTE_COMPACT
*)(flash_data
+ adr
);
204 remex
= (IRDB_REMOTE_EX
*)(flash_data
+ adr
);
206 for (i
=0;i
<= trans_num
;i
++) {
207 if (irdb
[i
].type
== IRDB_REM
) {
208 rem_adr_det
[rem_cnt
] = adr
;
211 remex
->ip
= irdb
[i
].ip
;
212 remex
->port
= irdb
[i
].port
;
213 memcpy (remex
->name
,irdb
[i
].remote
,80);
214 len
= (int)strlen (irdb
[i
].remote
);
215 if (len
> 80) len
= 80;
216 remex
->namelen
= len
;
218 remex
->modeflags
= irdb
[i
].action_type
;
220 memcpy (remex
->name
+len
,irdb
[i
].action
,50);
221 lenf
= (int)strlen (irdb
[i
].action
);
222 if (lenf
> 50) lenf
= 50;
223 remex
->defactlen
= lenf
;
225 adr
+= (word
)((IRDB_REMOTE_LEN_EX
+ len
+ lenf
) / 2);
226 remex
= (IRDB_REMOTE_EX
*)(flash_data
+ adr
);
228 else if (vers
>= 2) {
229 memcpy (remc
->name
,irdb
[i
].remote
,80);
230 len
= (int)strlen (irdb
[i
].remote
);
231 if (len
> 80) len
= 80;
234 adr
+= (word
)((IRDB_REMOTE_LEN_COMPACT
+ len
) / 2);
235 remc
= (IRDB_REMOTE_COMPACT
*)(flash_data
+ adr
);
238 memcpy (rem
->name
,irdb
[i
].remote
,80);
239 adr
+= IRDB_REMOTE_LEN
;
240 rem
= (IRDB_REMOTE
*)(flash_data
+ adr
);
247 pnt
->table
.remote_cnt
= rem_cnt
;
250 pnt
->table
.remote_hash_adr
= adr
;
252 for (i
=0;i
<= trans_num
;i
++) {
253 if (irdb
[i
].type
== IRDB_REM
) {
254 hash
= (HASH_ENTRY
*)(flash_data
+ adr
);
255 len
= (int)strlen (irdb
[i
].remote
);
256 if (len
> 80) len
= 80;
257 hash
->hashcode
= get_hashcode (irdb
[i
].remote
,(byte
)len
);
258 hash
->adr
= rem_adr_det
[rem_cnt
];
266 pnt
->table
.ircommand_hash_adr
= adr
;
267 hash
= (HASH_ENTRY
*)(flash_data
+ adr
);
270 for (i
=0;i
<= trans_num
;i
++) {
271 if (irdb
[i
].type
== IRDB_REM
) {
272 j
= rem_pnt
[irdb
[i
].remote_num
].command_start
;
273 while (j
< rem_pnt
[irdb
[i
].remote_num
].command_end
) {
274 hash
->hashcode
= get_hashcode (cmd_pnt
[j
].data
,(byte
)cmd_pnt
[j
].ir_length
);
276 hash
= (HASH_ENTRY
*)(flash_data
+ adr
);
285 for (i
=0;i
<= trans_num
;i
++) {
286 if (irdb
[i
].type
== IRDB_REM
) {
287 j
= rem_pnt
[irdb
[i
].remote_num
].timing_start
;
289 while (j
< rem_pnt
[irdb
[i
].remote_num
].timing_end
) {
290 if (tim_pnt
[j
].link_count
) {
291 tim_pnt
[j
].flash_adr
= adr
;
292 memcpy (flash_data
+ adr
,&tim_pnt
[j
].ir_length
,sizeof (IRDB_TIMING
));
294 adr
+= IRDB_TIMING_LEN
;
301 pnt
->table
.command_cnt
= cmd_cnt
;
305 for (i
=0;i
<= trans_num
;i
++) {
306 if (irdb
[i
].type
== IRDB_REM
) {
307 j
= rem_pnt
[irdb
[i
].remote_num
].command_start
;
309 while (j
< rem_pnt
[irdb
[i
].remote_num
].command_end
) {
310 com
= (IRDB_COMMAND
*)(flash_data
+ adr
);
311 comc
= (IRDB_COMMAND_COMPACT
*)(flash_data
+ adr
);
314 memset (comc
,0,sizeof (IRDB_COMMAND_COMPACT
));
315 comc
->remote_adr
= rem_adr_det
[rem_cnt
];
316 len
= (int)strlen (cmd_pnt
[j
].name
);
317 if (len
> 20) len
= 20;
318 memcpy (comc
->name
,cmd_pnt
[j
].name
,len
);
320 ntim
= rem_pnt
[irdb
[i
].remote_num
].timing_start
+ cmd_pnt
[j
].timing
;
321 if (ntim
< rem_pnt
[irdb
[i
].remote_num
].timing_end
) comc
->timing_adr
= tim_pnt
[ntim
].flash_adr
;
323 remc
= (IRDB_REMOTE_COMPACT
*)(flash_data
+ comc
->remote_adr
);
324 if (!cmd_cnt
) remc
->command_adr
= adr
;
326 comc
->toggle_seq
= cmd_pnt
[j
].toggle_seq
;
329 adr
+= (word
)((IRDB_COMMAND_LEN_COMPACT
+ len
) / 2);
332 com
->remote_adr
= rem_adr_det
[rem_cnt
];
333 len
= (int)strlen (cmd_pnt
[j
].name
) + 1;
334 if (len
> 20) len
= 20;
335 memset (com
->name
,' ',20);
336 memcpy (com
->name
,cmd_pnt
[j
].name
,len
);
338 ntim
= rem_pnt
[irdb
[i
].remote_num
].timing_start
+ cmd_pnt
[j
].timing
;
339 if (ntim
< rem_pnt
[irdb
[i
].remote_num
].timing_end
) com
->timing_adr
= tim_pnt
[ntim
].flash_adr
;
341 rem
= (IRDB_REMOTE
*)(flash_data
+ com
->remote_adr
);
342 if (!cmd_cnt
) rem
->command_adr
= adr
;
345 com
->toggle_seq
= cmd_pnt
[j
].toggle_seq
;
346 adr
+= IRDB_COMMAND_LEN
;
348 else adr
+= IRDB_COMMAND_LEN_1
;
354 if (vers
>= 2) remc
->command_cnt
= cmd_cnt
;
355 else rem
->command_cnt
= cmd_cnt
;
363 for (i
=0;i
<= trans_num
;i
++) {
364 if (irdb
[i
].type
== IRDB_REM
) {
365 j
= rem_pnt
[irdb
[i
].remote_num
].command_start
;
367 rem
= (IRDB_REMOTE
*)(flash_data
+ rem_adr_det
[rem_cnt
]);
368 remc
= (IRDB_REMOTE_COMPACT
*)(flash_data
+ rem_adr_det
[rem_cnt
]);
369 cadr
= remc
->command_adr
;
371 while (j
< rem_pnt
[irdb
[i
].remote_num
].command_end
) {
372 hash
= (HASH_ENTRY
*)(flash_data
+ adr
);
374 len
= (int)strlen (cmd_pnt
[j
].name
);
375 if (len
> 20) len
= 20;
377 hash
->hashcode
= get_hashcode (cmd_pnt
[j
].name
,(byte
)len
);
379 if (vers
>= 2) hash
->adr
= cadr
;
380 else if (vers
>= 1) hash
->adr
= rem
->command_adr
+ cmd_cnt
* IRDB_COMMAND_LEN
;
381 else hash
->adr
= rem
->command_adr
+ cmd_cnt
* IRDB_COMMAND_LEN_1
;
385 if (vers
>= 2) remc
->command_hash
= adr
;
386 else rem
->command_hash
= adr
;
392 cadr
+= (word
)((IRDB_COMMAND_LEN_COMPACT
+ len
) / 2);
400 hash
= (HASH_ENTRY
*)(flash_data
+ pnt
->table
.ircommand_hash_adr
);
401 pnt
->table
.ircommand_adr
= adr
;
402 ircom
= (IRDB_IRCOMMAND
*)(flash_data
+ adr
);
404 for (i
=0;i
<= trans_num
;i
++) {
405 if (irdb
[i
].type
== IRDB_REM
) {
406 j
= rem_pnt
[irdb
[i
].remote_num
].command_start
;
407 rem
= (IRDB_REMOTE
*)(flash_data
+ rem_adr_det
[rem_cnt
]);
408 remc
= (IRDB_REMOTE_COMPACT
*)(flash_data
+ rem_adr_det
[rem_cnt
]);
410 if (vers
>= 2) chash
= (HASH_ENTRY
*)(flash_data
+ remc
->command_hash
);
411 else chash
= (HASH_ENTRY
*)(flash_data
+ rem
->command_hash
);
413 while (j
< rem_pnt
[irdb
[i
].remote_num
].command_end
) {
414 com
= (IRDB_COMMAND
*)(flash_data
+ chash
->adr
);
415 comc
= (IRDB_COMMAND_COMPACT
*)(flash_data
+ chash
->adr
);
417 if (!(cmd_pnt
[j
].mode
& RAW_DATA
) && ((calflag
&& cmd_pnt
[j
].ir_length_cal
> CODE_LEN
) || cmd_pnt
[j
].ir_length
> CODE_LEN
)) { // Long Codes packen
422 while (pp
< cmd_pnt
[j
].ir_length_cal
) {
423 if (cmd_pnt
[j
].data_cal
[pp
] & 128) ircom
->ir_data
[ii
++] = cmd_pnt
[j
].data_cal
[pp
++];
425 ircom
->ir_data
[ii
] = (cmd_pnt
[j
].data_cal
[pp
++] & 7);
426 if (pp
< cmd_pnt
[j
].ir_length_cal
) ircom
->ir_data
[ii
] |= ((cmd_pnt
[j
].data_cal
[pp
] & 7) << 4);
432 ircom
->ir_data
[0] |= LONG_CODE_FLAG
;
433 if (pp
> cmd_pnt
[j
].ir_length_cal
) ircom
->ir_data
[0] |= LONG_CODE_LEN
;
434 ircom
->ir_length
= ii
;
437 while (pp
< cmd_pnt
[j
].ir_length
) {
438 if (cmd_pnt
[j
].data
[pp
] & 128) pp
++;
440 ircom
->ir_data
[ii
] = (cmd_pnt
[j
].data
[pp
++] & 7);
441 if (pp
< cmd_pnt
[j
].ir_length
) ircom
->ir_data
[ii
] |= ((cmd_pnt
[j
].data
[pp
] & 7) << 4);
447 ircom
->ir_data
[0] |= LONG_CODE_FLAG
;
448 if (pp
> cmd_pnt
[j
].ir_length
) ircom
->ir_data
[0] |= LONG_CODE_LEN
;
449 ircom
->ir_length
= ii
;
453 if (calflag
&& !(cmd_pnt
[j
].mode
& RAW_DATA
)) {
454 memcpy (ircom
->ir_data
,cmd_pnt
[j
].data_cal
,(byte
)cmd_pnt
[j
].ir_length_cal
);
455 ircom
->ir_length
= (byte
)cmd_pnt
[j
].ir_length_cal
;
458 memcpy (ircom
->ir_data
,cmd_pnt
[j
].data
,(byte
)cmd_pnt
[j
].ir_length
);
459 ircom
->ir_length
= (byte
)cmd_pnt
[j
].ir_length
;
463 ircom
->command_adr
= chash
->adr
;
465 if (vers
>= 2) comc
->ird_adr
= adr
;
466 else com
->ird_adr
= adr
;
468 if (cmd_pnt
[j
].mode
& RAW_DATA
) {
469 if (vers
>= 2) comc
->timing_adr
= (word
)cmd_pnt
[j
].timing
;
470 else com
->timing_adr
= (word
)cmd_pnt
[j
].timing
;
471 ircom
->command_adr
= 0;
474 hash
[cmd_cnt
].adr
= adr
;
477 adr
+= (sizeof (IRDB_IRCOMMAND
) + ircom
->ir_length
) / 2; // +1 steckt bereits in der LƤnge 1 von data in IRDB_IRCOMMAND
478 ircom
= (IRDB_IRCOMMAND
*)(flash_data
+ adr
);
490 actex
= (IRDB_ACTION_EX
*)(flash_data
+ adr
);
491 for (i
=0;i
<= trans_num
;i
++) {
492 if (irdb
[i
].type
== IRDB_TYPEACTION_2
) {
494 actex
->relais
= irdb
[i
-2].relais
;
497 for (n
=0;n
<= 2;n
++) {
498 actex
->action_type
[n
] = irdb
[i
+n
].action_type
;
499 actex
->action_len
[n
] = irdb
[i
+n
].action_len
;
502 memcpy (actex
->action
+ p
,&irdb
[i
+n
].ip
,4);
504 actex
->action_type
[n
] |= ACTION_IP
;
506 if (irdb
[i
+n
].port
) {
507 memcpy (actex
->action
+ p
,&irdb
[i
+n
].port
,2);
509 actex
->action_type
[n
] |= ACTION_PORT
;
511 memcpy (actex
->action
+ p
,irdb
[i
+n
].action
,irdb
[i
+n
].action_len
);
512 p
+= irdb
[i
+n
].action_len
;
513 if (irdb
[i
+n
].action_len
& 1) p
++;
516 j
= FindIRDBCommand (irdb
[i
].remote
,irdb
[i
].command
,pnt
,vers
);
518 comc
= (IRDB_COMMAND_COMPACT
*)(flash_data
+ j
);
519 comc
->action_adr
= adr
;
522 adr
+= (word
)((sizeof (IRDB_ACTION_EX
) + p
) / 2); // +1 steckt bereits in der LƤnge 1 von action in IRDB_ACTION
523 actex
= (IRDB_ACTION_EX
*)(flash_data
+ adr
);
530 act
= (IRDB_ACTION
*)(flash_data
+ adr
);
531 for (i
=0;i
<= trans_num
;i
++) {
532 if (irdb
[i
].type
== IRDB_TYPEACTION
) {
533 act
->action_len
= irdb
[i
].action_len
;
534 act
->action_type
= irdb
[i
].action_type
;
535 act
->relais
= irdb
[i
].relais
;
536 memcpy (act
->action
,irdb
[i
].action
,irdb
[i
].action_len
);
538 j
= FindIRDBCommand (irdb
[i
].remote
,irdb
[i
].command
,pnt
,vers
);
540 com
= (IRDB_COMMAND
*)(flash_data
+ j
);
541 comc
= (IRDB_COMMAND_COMPACT
*)(flash_data
+ j
);
542 if (vers
>= 2) comc
->action_adr
= adr
;
543 else com
->action_adr
= adr
;
546 adr
+= (sizeof (IRDB_ACTION
) + act
->action_len
) / 2; // +1 steckt bereits in der LƤnge 1 von action in IRDB_ACTION
547 act
= (IRDB_ACTION
*)(flash_data
+ adr
);
554 if (irdb
[0].type
== IRDB_TYPEHEADER
) {
555 for (i
=0;i
<= 3;i
++) {
556 if (irdbheader
.minremote
[i
][0] && irdbheader
.mincommand
[i
][0]) {
557 j
= FindIRDBRemote (irdbheader
.minremote
[i
],pnt
,vers
);
559 pnt
->table
.adc
[i
].low_remote
= 0;
560 sprintf (st
,"Minremote %d [%s] not found in Flash IRDB\n",i
,irdbheader
.minremote
[i
]);
561 log_print (st
,LOG_ERROR
);
564 pnt
->table
.adc
[i
].low_remote
= j
;
565 memcpy (pnt
->table
.adc
[i
].low_commands
,irdbheader
.mincommand
[i
],sizeof (irdbheader
.mincommand
[i
]));
568 else pnt
->table
.adc
[i
].low_remote
= 0;
570 if (irdbheader
.maxremote
[i
][0] && irdbheader
.maxcommand
[i
][0]) {
571 j
= FindIRDBRemote (irdbheader
.maxremote
[i
],pnt
,vers
);
573 pnt
->table
.adc
[i
].high_remote
= 0;
574 sprintf (st
,"Maxremote %d [%s] not found in Flash IRDB\n",i
,irdbheader
.maxremote
[i
]);
575 log_print (st
,LOG_ERROR
);
578 pnt
->table
.adc
[i
].high_remote
= j
;
579 memcpy (pnt
->table
.adc
[i
].high_commands
,irdbheader
.maxcommand
[i
],sizeof (irdbheader
.maxcommand
[i
]));
582 else pnt
->table
.adc
[i
].high_remote
= 0;
588 if (vers
>= 2) pnt
->crc
= CRC ((byte
*)(flash_data
+ 1),((adr
- 1) * 2),INITIAL_VALUE_V2
);
589 else pnt
->crc
= CRC ((byte
*)(flash_data
+ 1),((adr
- 1) * 2),INITIAL_VALUE
);
592 // FlashgrƶĆe kontrollieren !
594 sprintf (st
,"Flash IRDB Size: %d Words (%d KBytes).\n%-3d Remotes\n%-3d Commands\n%-3d Actions\n",adr
,adr
/ 512,pnt
->table
.remote_cnt
,pnt
->table
.command_cnt
,act_cnt
);
595 log_print (st
,LOG_DEBUG
);
597 finfo
->statuslen
= sizeof (IRDB_FLASHINFO
);
598 finfo
->statustype
= STATUS_IRDBFLASH
;
599 sprintf (finfo
->memsize
,"%d Words (%d KBytes)",adr
,adr
/512);
600 sprintf (finfo
->remotes
,"%d",pnt
->table
.remote_cnt
);
601 sprintf (finfo
->commands
,"%d",pnt
->table
.command_cnt
);
602 sprintf (finfo
->actions
,"%d",act_cnt
);
603 if (IRDevices
[bus
].fw_capabilities
& FN_FLASH128
) sprintf (finfo
->flashsize
,"128K");
604 else sprintf (finfo
->flashsize
,"64K");
609 while (adr
< pnt
->len
) {
610 if ((adr
+ flashwordsize
/2) < pnt
->len
) TransferFlashdataEx (bus
,flash_data
+ adr
,adr
,flashwordsize
,0,iradr
);
611 else TransferFlashdataEx (bus
,flash_data
+ adr
,adr
,flashwordsize
,1,iradr
);
612 adr
+= flashwordsize
/ 2;
618 word
FindIRDBCommand (byte remote
[],byte command
[],IRDB_HEADER
*pnt
,byte vers
)
623 IRDB_COMMAND_COMPACT
*comc
;
624 IRDB_REMOTE_COMPACT
*remc
;
625 IRDB_REMOTE_EX
*remex
;
628 adr
= pnt
->table
.remote_adr
;
630 len
= (word
)strlen (remote
);
632 for (i
=0;i
< pnt
->table
.remote_cnt
;i
++) {
633 remex
= (IRDB_REMOTE_EX
*)(flash_data
+ adr
);
634 if (len
== remex
->namelen
&& !memcmp (remex
->name
,remote
,len
)) break;
635 adr
+= (IRDB_REMOTE_LEN_EX
+ remex
->namelen
) / 2;
638 if (i
== pnt
->table
.remote_cnt
) return (0);
640 cnt
= remex
->command_cnt
;
641 adr
= remex
->command_adr
;
643 len
= (word
)strlen (command
);
645 for (i
=0;i
< cnt
;i
++) {
646 comc
= (IRDB_COMMAND_COMPACT
*)(flash_data
+ adr
);
647 if (len
== comc
->namelen
&& !memcmp (comc
->name
,command
,len
)) return (adr
);
649 adr
+= (IRDB_COMMAND_LEN_COMPACT
+ comc
->namelen
) / 2;
653 else if (vers
>= 2) {
654 adr
= pnt
->table
.remote_adr
;
656 len
= (word
)strlen (remote
);
658 for (i
=0;i
< pnt
->table
.remote_cnt
;i
++) {
659 remc
= (IRDB_REMOTE_COMPACT
*)(flash_data
+ adr
);
660 if (len
== remc
->namelen
&& !memcmp (remc
->name
,remote
,len
)) break;
661 adr
+= (IRDB_REMOTE_LEN_COMPACT
+ remc
->namelen
) / 2;
665 if (i
== pnt
->table
.remote_cnt
) return (0);
667 cnt
= remc
->command_cnt
;
668 adr
= remc
->command_adr
;
670 len
= (word
)strlen (command
);
672 for (i
=0;i
< cnt
;i
++) {
673 comc
= (IRDB_COMMAND_COMPACT
*)(flash_data
+ adr
);
674 if (len
== comc
->namelen
&& !memcmp (comc
->name
,command
,len
)) return (adr
);
676 adr
+= (IRDB_COMMAND_LEN_COMPACT
+ comc
->namelen
) / 2;
681 rem
= (IRDB_REMOTE
*)(flash_data
+ pnt
->table
.remote_adr
);
683 for (i
=0;i
< pnt
->table
.remote_cnt
;i
++) if (!memcmp (rem
[i
].name
,remote
,80)) break;
685 if (i
== pnt
->table
.remote_cnt
) return (0);
687 cnt
= rem
[i
].command_cnt
;
688 adr
= rem
[i
].command_adr
;
690 for (i
=0;i
< cnt
;i
++) {
691 com
= (IRDB_COMMAND
*)(flash_data
+ adr
);
692 if (!memcmp (com
->name
,command
,20)) return (adr
);
694 if (vers
>= 1) adr
+= IRDB_COMMAND_LEN
;
695 else adr
+= IRDB_COMMAND_LEN_1
;
703 word
FindIRDBRemote (byte remote
[],IRDB_HEADER
*pnt
,byte vers
)
708 IRDB_REMOTE_COMPACT
*remc
;
711 adr
= pnt
->table
.remote_adr
;
713 len
= (word
)strlen (remote
);
715 for (i
=0;i
< pnt
->table
.remote_cnt
;i
++) {
716 remc
= (IRDB_REMOTE_COMPACT
*)(flash_data
+ adr
);
717 if (len
== remc
->namelen
&& !memcmp (remc
->name
,remote
,len
)) break;
718 adr
+= (IRDB_REMOTE_LEN_COMPACT
+ remc
->namelen
) / 2;
722 if (i
== pnt
->table
.remote_cnt
) return (0);
728 rem
= (IRDB_REMOTE
*)(flash_data
+ pnt
->table
.remote_adr
);
730 for (i
=0;i
< pnt
->table
.remote_cnt
;i
++) if (!memcmp (rem
[i
].name
,remote
,80)) break;
732 if (i
== pnt
->table
.remote_cnt
) return (0);
734 return ((word
)((word
*)(&rem
[i
]) - flash_data
));
742 int FileTransData (char nm
[],byte dbtype
,byte filemode
)
748 if (dbtype
== 1) strcat (st
,".tra");
749 if (dbtype
== 2) strcat (st
,".irdb");
750 if (filemode
== FILE_MODE_SAVEAS
) {
751 fptrans
= fopen (st
,"r");
754 return (ERR_OVERWRITE
);
758 fptrans
= fopen (st
,"w");
759 if (fptrans
== NULL
) return ERR_OPENTRANS
;
761 for (i
=0;i
<= trans_num
;i
++) {
763 if (irdb
[i
].type
== IRDB_TYPEHEADER
) {
765 fprintf (fptrans
,"[DEFAULTACTION]%s\n",irdbheader
.default_action
);
766 fprintf (fptrans
," [RESULT_ERR]%s\n",irdbheader
.err_status
);
767 fprintf (fptrans
," [RESULT_OK]%s\n",irdbheader
.ok_status
);
768 fprintf (fptrans
," [ACTIVE]%d\n",irdbheader
.active
);
769 for (j
=0;j
<= 3;j
++) {
770 fprintf (fptrans
," [INPUTMODE_%d]%d\n",j
,irdbheader
.inputmode
[j
]);
771 fprintf (fptrans
," [MIN_%d]%d\n",j
,irdbheader
.min
[j
]);
772 fprintf (fptrans
," [MAX_%d]%d\n",j
,irdbheader
.max
[j
]);
773 fprintf (fptrans
," [HYST_%d]%d\n",j
,irdbheader
.hyst
[j
]);
774 fprintf (fptrans
," [MINREMOTE_%d]%s\n",j
,irdbheader
.minremote
[j
]);
775 fprintf (fptrans
," [MINCOMMAND_%d]%s\n",j
,irdbheader
.mincommand
[j
]);
776 fprintf (fptrans
," [MAXREMOTE_%d]%s\n",j
,irdbheader
.maxremote
[j
]);
777 fprintf (fptrans
," [MAXCOMMAND_%d]%s\n",j
,irdbheader
.maxcommand
[j
]);
778 fprintf (fptrans
," [MINLED_%d]%d\n",j
,irdbheader
.minledsel
[j
]);
779 fprintf (fptrans
," [MINMASK_%d]%d\n",j
,irdbheader
.minmask
[j
]);
780 fprintf (fptrans
," [MAXLED_%d]%d\n",j
,irdbheader
.maxledsel
[j
]);
781 fprintf (fptrans
," [MAXMASK_%d]%d\n",j
,irdbheader
.maxmask
[j
]);
783 fprintf (fptrans
,"[END]\n");
785 if (irdb
[i
].type
== IRDB_REM
) {
786 fprintf (fptrans
,"[DBREMOTE2]%s\n",irdb
[i
].remote
);
788 fprintf (fptrans
," [IP]%03d.%03d.%03d.%03d\n",(irdb
[i
].ip
>> 24) & 255,(irdb
[i
].ip
>> 16) & 255,(irdb
[i
].ip
>> 8) & 255,irdb
[i
].ip
& 255);
789 fprintf (fptrans
," [PORT]%d\n",irdb
[i
].port
);
790 fprintf (fptrans
," [FLAGS]%d\n",irdb
[i
].action_type
);
791 fprintf (fptrans
," [RACTION]%s\n",irdb
[i
].action
);
792 fprintf (fptrans
,"[END]\n");
794 if (irdb
[i
].type
== IRDB_TYPEACTION
|| irdb
[i
].type
== IRDB_TYPEACTION_1
|| irdb
[i
].type
== IRDB_TYPEACTION_2
) {
795 fprintf (fptrans
,"[COMACTION_%d]\n [ACREMOTE]%s\n",irdb
[i
].type
- IRDB_TYPEACTION
,irdb
[i
].remote
);
796 fprintf (fptrans
," [ACCOMMAND]%s\n",irdb
[i
].command
);
797 fprintf (fptrans
," [ACFLAGS]%d\n",irdb
[i
].action_type
);
798 if (irdb
[i
].type
== IRDB_TYPEACTION
)
799 fprintf (fptrans
," [RELAIS]%c%d\n",irdb
[i
].relais
& 125,(irdb
[i
].relais
& 128)>>6 | (irdb
[i
].relais
& 2)>>1);
800 fprintf (fptrans
," [ACLEN]%d\n",irdb
[i
].action_len
);
801 fprintf (fptrans
," [IP]%03d.%03d.%03d.%03d\n",(irdb
[i
].ip
>> 24) & 255,(irdb
[i
].ip
>> 16) & 255,(irdb
[i
].ip
>> 8) & 255,irdb
[i
].ip
& 255);
802 fprintf (fptrans
," [PORT]%d\n",irdb
[i
].port
);
803 fprintf (fptrans
," [ACTION]");
804 fwrite (irdb
[i
].action
,1,irdb
[i
].action_len
,fptrans
);
805 fprintf (fptrans
,"\n[END]\n");
810 if (trans
[i
].type
== F_CONFIG
) {
811 fprintf (fptrans
,"[CONFIG]\n [NAME]%s\n",trans
[i
].remote
);
813 fprintf (fptrans
," [SETTINGS]0x%x\n",trans
[i
].setup
);
814 fprintf (fptrans
," [SOURCEMASK]0x%x\n",trans
[i
].source_mask
);
815 fprintf (fptrans
," [TARGETMASK]0x%x\n",trans
[i
].target_mask
);
816 fprintf (fptrans
,"[END]\n");
818 if ((trans
[i
].type
>= F_COMMAND
&& trans
[i
].type
<= F_VOLUMEMACROD
) ||
819 (trans
[i
].type
>= F_TOGGLE
&& trans
[i
].type
< (F_TOGGLE
+ 6*4)) || trans
[i
].type
>= F_MACRO
) {
820 if (trans
[i
].type
== F_COMMAND
) fprintf (fptrans
,"[RCVCOMMAND]\n");
821 if (trans
[i
].type
== F_VOLUMEMACRO
) fprintf (fptrans
,"[VOLUMEMACRO]\n");
822 if (trans
[i
].type
== F_VOLUMEMACROD
) fprintf (fptrans
,"[VOLUMEMACROD]\n");
823 if (trans
[i
].type
>= F_MACRO
) fprintf (fptrans
,"[MACRO %d]\n",trans
[i
].type
- F_MACRO
);
824 else if (trans
[i
].type
>= F_TOGGLE
) fprintf (fptrans
,"[TOGGLE %d]\n",trans
[i
].type
- F_TOGGLE
);
826 fprintf (fptrans
," [REMOTE]%s\n",trans
[i
].remote
);
827 fprintf (fptrans
," [COMMAND]%s\n",trans
[i
].command
);
828 fprintf (fptrans
," [SETTINGS]0x%x\n",trans
[i
].setup
);
829 fprintf (fptrans
," [SOURCEMASK]0x%x\n",trans
[i
].source_mask
);
830 fprintf (fptrans
," [ACC_TIMEOUT]%d\n",trans
[i
].accelerator_timeout
);
831 fprintf (fptrans
," [ACC_SETUP]0x%x\n",trans
[i
].accelerator_repeat
);
832 fprintf (fptrans
," [REMOTE_NUM]%d\n",trans
[i
].remote_num
);
833 fprintf (fptrans
," [GROUP_NUM]%d\n",trans
[i
].group_num
);
834 fprintf (fptrans
," [SHIFT_NUM]%d\n",trans
[i
].multi_num
);
835 fprintf (fptrans
," [INCLUDE_NAMES]%d\n",trans
[i
].include_names
);
836 fprintf (fptrans
,"[END]\n");
838 if (trans
[i
].type
== F_SEND
) {
839 fprintf (fptrans
,"[SEND]\n");
841 fprintf (fptrans
," [REMOTE]%s\n",trans
[i
].remote
);
842 fprintf (fptrans
," [COMMAND]%s\n",trans
[i
].command
);
843 fprintf (fptrans
," [TARGETMASK]0x%x\n",trans
[i
].target_mask
);
844 fprintf (fptrans
," [TIMEOUT]%d\n",trans
[i
].wait_timeout
);
845 fprintf (fptrans
," [REMOTE_NUM]%d\n",trans
[i
].remote_num
);
846 fprintf (fptrans
," [GROUP_NUM]%d\n",trans
[i
].group_num
);
847 fprintf (fptrans
," [SHIFT_NUM]%d\n",trans
[i
].multi_num
);
848 fprintf (fptrans
,"[END]\n");
850 if (trans
[i
].type
== F_REMOTE
) {
851 fprintf (fptrans
,"[REMOTE]\n [NAME]%s\n",trans
[i
].remote
);
852 fprintf (fptrans
," [SETTINGS]0x%x\n",trans
[i
].setup
);
853 fprintf (fptrans
," [SOURCEMASK]0x%x\n",trans
[i
].source_mask
);
854 fprintf (fptrans
," [TARGETMASK]0x%x\n",trans
[i
].target_mask
);
855 fprintf (fptrans
," [REMOTE_NUM]%d\n",trans
[i
].remote_num
);
856 fprintf (fptrans
,"[END]\n");
858 if (trans
[i
].type
== F_ENABLEGROUP
) {
859 fprintf (fptrans
,"[GROUP]\n");
860 fprintf (fptrans
," [REMOTE]%s\n",trans
[i
].remote
);
861 fprintf (fptrans
," [COMMAND]%s\n",trans
[i
].command
);
862 fprintf (fptrans
," [SETTINGS]0x%x\n",trans
[i
].setup
);
863 fprintf (fptrans
," [SOURCEMASK]0x%x\n",trans
[i
].source_mask
);
864 fprintf (fptrans
," [REMOTE_NUM]%d\n",trans
[i
].remote_num
);
865 fprintf (fptrans
," [GROUP_NUM]%d\n",trans
[i
].group_num
);
866 fprintf (fptrans
,"[END]\n");
868 if (trans
[i
].type
== F_PREKEY
) {
869 fprintf (fptrans
,"[SHIFT]\n");
870 fprintf (fptrans
," [REMOTE]%s\n",trans
[i
].remote
);
871 fprintf (fptrans
," [COMMAND]%s\n",trans
[i
].command
);
872 fprintf (fptrans
," [SETTINGS]0x%x\n",trans
[i
].setup
);
873 fprintf (fptrans
," [SOURCEMASK]0x%x\n",trans
[i
].source_mask
);
874 fprintf (fptrans
," [REMOTE_NUM]%d\n",trans
[i
].remote_num
);
875 fprintf (fptrans
," [GROUP_NUM]%d\n",trans
[i
].group_num
);
876 fprintf (fptrans
," [SHIFT_NUM]%d\n",trans
[i
].multi_num
);
877 fprintf (fptrans
,"[END]\n");
886 int LoadIRDB (IRDBBUFFER
*db
,char nm
[],word offset
)
892 IRDBHEADERBUFFER
*dbh
;
893 dbh
= (IRDBHEADERBUFFER
*)db
;
897 fptrans
= fopen (ln
,"r");
898 if (fptrans
== NULL
) return ERR_OPENTRANS
;
900 memset (&irdbheader
,0,sizeof(IRDBHEADER
));
901 while (st
= DBReadString (ln
,fptrans
,0)) {
906 memset (dbh
,0,sizeof (IRDBHEADERBUFFER
));
907 dbh
->statustype
= STATUS_IRDB
;
908 dbh
->statuslen
= sizeof (IRDBHEADERBUFFER
);
909 dbh
->offset
= offset
;
910 memcpy (&dbh
->header
,&irdbheader
,sizeof (IRDBHEADER
));
911 dbh
->count_buffer
= 1;
912 dbh
->count_total
= trans_num
;
913 dbh
->count_remaining
= (short)(trans_num
- offset
);
919 memset (db
,0,sizeof (IRDBBUFFER
));
920 db
->statustype
= STATUS_IRDB
;
921 db
->statuslen
= sizeof (IRDBBUFFER
);
924 while (i
< 12 && offset
< trans_num
) {
925 memcpy (&db
->dbdata
[i
],&irdb
[offset
],sizeof (IRDBCOMMAND
));
930 db
->count_buffer
= i
;
931 db
->count_total
= trans_num
;
932 if (i
== 12) db
->count_remaining
= (short)(trans_num
- offset
);
933 else db
->count_remaining
= 0;
937 int LoadTranslation (TRANSLATEBUFFER
*tb
,char nm
[],word offset
)
945 fptrans
= fopen (ln
,"r");
946 if (fptrans
== NULL
) return ERR_OPENTRANS
;
948 while (st
= DBReadString (ln
,fptrans
,0)) {
955 memset (tb
,0,sizeof (TRANSLATEBUFFER
));
956 tb
->statustype
= STATUS_TRANSLATE
;
957 tb
->statuslen
= sizeof (TRANSLATEBUFFER
);
960 while (i
< 30 && offset
< trans_num
) {
961 memcpy (&tb
->trdata
[i
],&trans
[offset
],sizeof (TRANSLATECOMMAND
));
966 tb
->count_buffer
= i
;
967 tb
->count_total
= trans_num
;
968 if (i
== 30) tb
->count_remaining
= (short)(trans_num
- offset
);
969 else tb
->count_remaining
= 0;
974 void ReadTraReceive (char tp
[])
979 memset (&trans
[trans_num
],0,sizeof (TRANSLATECOMMAND
));
980 memset (&irdb
[trans_num
],0,sizeof (IRDBCOMMAND
));
982 irdb
[trans_num
].number
= trans_num
;
983 trans
[trans_num
].number
= trans_num
;
986 if (!strncmp (tp
,"[DBREMOTE]",10)) {
987 irdb
[trans_num
].type
= IRDB_REM
;
988 memset (irdb
[trans_num
].remote
,' ',80);
989 memcpy (irdb
[trans_num
].remote
,tp
+ 10,strlen (tp
+ 10));
990 irdb
[trans_num
].action_type
= 1;
995 if (!strcmp (tp
,"[RCVCOMMAND]")) trans
[trans_num
].type
= F_COMMAND
;
996 if (!strcmp (tp
,"[VOLUMEMACRO]")) trans
[trans_num
].type
= F_VOLUMEMACRO
;
997 if (!strcmp (tp
,"[VOLUMEMACROD]")) trans
[trans_num
].type
= F_VOLUMEMACROD
;
998 if (!strncmp (tp
,"[MACRO ",7)) trans
[trans_num
].type
= F_MACRO
+ (byte
)strtoul (tp
+ 7,0,0);
999 if (!strncmp (tp
,"[TOGGLE ",8)) trans
[trans_num
].type
= F_TOGGLE
+ (byte
)strtoul (tp
+ 8,0,0);
1000 if (!strcmp (tp
,"[SEND]")) trans
[trans_num
].type
= F_SEND
;
1001 if (!strcmp (tp
,"[CONFIG]")) trans
[trans_num
].type
= F_CONFIG
;
1002 if (!strcmp (tp
,"[REMOTE]")) trans
[trans_num
].type
= F_REMOTE
;
1003 if (!strcmp (tp
,"[GROUP]")) trans
[trans_num
].type
= F_ENABLEGROUP
;
1004 if (!strcmp (tp
,"[SHIFT]")) trans
[trans_num
].type
= F_PREKEY
;
1005 if (!strcmp (tp
,"[COMACTION]")) irdb
[trans_num
].type
= IRDB_TYPEACTION
;
1006 if (!strcmp (tp
,"[COMACTION_0]")) irdb
[trans_num
].type
= IRDB_TYPEACTION
;
1007 if (!strcmp (tp
,"[COMACTION_1]")) irdb
[trans_num
].type
= IRDB_TYPEACTION_1
;
1008 if (!strcmp (tp
,"[COMACTION_2]")) irdb
[trans_num
].type
= IRDB_TYPEACTION_2
;
1009 if (!strncmp (tp
,"[DBREMOTE2]",11)) {
1010 irdb
[trans_num
].type
= IRDB_REM
;
1011 memset (irdb
[trans_num
].remote
,' ',80);
1012 memcpy (irdb
[trans_num
].remote
,tp
+ 11,strlen (tp
+ 11));
1014 if (!strncmp (tp
,"[DEFAULTACTION]",15)) {
1015 irdb
[trans_num
].type
= IRDB_TYPEHEADER
;
1016 irdbheader
.type
= IRDB_TYPEHEADER
;
1017 memset (irdbheader
.default_action
,' ',100);
1019 memcpy (irdbheader
.default_action
,tp
+ 15,strlen (tp
+ 15));
1021 pos
= ftell (fptrans
);
1022 while ((st
= DBReadString (ln
,fptrans
,0)) && strcmp (st
,"[END]")) {
1023 if (!strncmp (st
,"[NAME]",6)) {
1024 memset (trans
[trans_num
].remote
,' ',80);
1025 memcpy (trans
[trans_num
].remote
,st
+ 6,strlen (st
+ 6));
1027 if (!strncmp (st
,"[REMOTE]",8)) {
1028 memset (trans
[trans_num
].remote
,' ',80);
1029 memcpy (trans
[trans_num
].remote
,st
+ 8,strlen (st
+ 8));
1031 if (!strncmp (st
,"[PORT]",6)) irdb
[trans_num
].port
= (word
)strtoul (st
+ 6,0,0);
1032 if (!strncmp (st
,"[FLAGS]",7)) irdb
[trans_num
].action_type
= (byte
)strtoul (st
+ 7,0,0);
1033 if (!strncmp (st
,"[IP]",4)) {
1035 irdb
[trans_num
].ip
= (byte
)strtoul (st
+ 4,0,10) << 24;
1037 irdb
[trans_num
].ip
|= (byte
)strtoul (st
+ 8,0,10) << 16;
1039 irdb
[trans_num
].ip
|= (byte
)strtoul (st
+ 12,0,10) << 8;
1041 irdb
[trans_num
].ip
|= (byte
)strtoul (st
+ 16,0,10);
1043 if (!strncmp (st
,"[RACTION]",9)) {
1044 memset (irdb
[trans_num
].action
,' ',256);
1046 memcpy (irdb
[trans_num
].action
,st
+ 9,strlen (st
+ 9));
1049 if (!strncmp (st
,"[COMMAND]",9)) {
1050 memset (trans
[trans_num
].command
,' ',20);
1051 memcpy (trans
[trans_num
].command
,st
+ 9,strlen (st
+ 9));
1053 if (!strncmp (st
,"[RESULT_ERR]",12)) {
1054 strcpy (irdbheader
.err_status
,st
+ 12);
1056 if (!strncmp (st
,"[RESULT_OK]",11)) {
1057 strcpy (irdbheader
.ok_status
,st
+ 11);
1059 if (!strncmp (st
,"[ACREMOTE]",10)) {
1060 memset (irdb
[trans_num
].remote
,' ',80);
1061 memcpy (irdb
[trans_num
].remote
,st
+ 10,strlen (st
+ 10));
1063 if (!strncmp (st
,"[ACCOMMAND]",11)) {
1064 memset (irdb
[trans_num
].command
,' ',20);
1065 memcpy (irdb
[trans_num
].command
,st
+ 11,strlen (st
+ 11));
1067 if (!strncmp (st
,"[ACTION]",8)) {
1068 fseek (fptrans
,pos
+10,SEEK_SET
);
1069 fread (irdb
[trans_num
].action
,1,irdb
[trans_num
].action_len
,fptrans
);
1071 if (!strncmp (st
,"[RELAIS]",8)) irdb
[trans_num
].relais
= st
[8] + ((st
[9] & 2) << 6) + ((st
[9] & 1) << 1);
1072 if (!strncmp (st
,"[ACTYPE]",8)) {
1073 if (st
[8] == 'A') irdb
[trans_num
].action_type
= 130;
1074 if (st
[8] == 'B') irdb
[trans_num
].action_type
= 131;
1076 if (!strncmp (st
,"[ACFLAGS]",9)) irdb
[trans_num
].action_type
= atoi (st
+9);
1077 if (!strncmp (st
,"[ACLEN]",7)) irdb
[trans_num
].action_len
= (byte
)strtoul (st
+ 7,0,0);
1079 if (!strncmp (st
,"[INPUTMODE_0]",13)) irdbheader
.inputmode
[0] = (byte
)strtoul (st
+ 13,0,0);
1080 if (!strncmp (st
,"[INPUTMODE_1]",13)) irdbheader
.inputmode
[1] = (byte
)strtoul (st
+ 13,0,0);
1081 if (!strncmp (st
,"[INPUTMODE_2]",13)) irdbheader
.inputmode
[2] = (byte
)strtoul (st
+ 13,0,0);
1082 if (!strncmp (st
,"[INPUTMODE_3]",13)) irdbheader
.inputmode
[3] = (byte
)strtoul (st
+ 13,0,0);
1083 if (!strncmp (st
,"[MIN_0]",7)) irdbheader
.min
[0] = (byte
)strtoul (st
+ 7,0,0);
1084 if (!strncmp (st
,"[MIN_1]",7)) irdbheader
.min
[1] = (byte
)strtoul (st
+ 7,0,0);
1085 if (!strncmp (st
,"[MIN_2]",7)) irdbheader
.min
[2] = (byte
)strtoul (st
+ 7,0,0);
1086 if (!strncmp (st
,"[MIN_3]",7)) irdbheader
.min
[3] = (byte
)strtoul (st
+ 7,0,0);
1087 if (!strncmp (st
,"[MAX_0]",7)) irdbheader
.max
[0] = (byte
)strtoul (st
+ 7,0,0);
1088 if (!strncmp (st
,"[MAX_1]",7)) irdbheader
.max
[1] = (byte
)strtoul (st
+ 7,0,0);
1089 if (!strncmp (st
,"[MAX_2]",7)) irdbheader
.max
[2] = (byte
)strtoul (st
+ 7,0,0);
1090 if (!strncmp (st
,"[MAX_3]",7)) irdbheader
.max
[3] = (byte
)strtoul (st
+ 7,0,0);
1091 if (!strncmp (st
,"[HYST_0]",8)) irdbheader
.hyst
[0] = (byte
)strtoul (st
+ 8,0,0);
1092 if (!strncmp (st
,"[HYST_1]",8)) irdbheader
.hyst
[1] = (byte
)strtoul (st
+ 8,0,0);
1093 if (!strncmp (st
,"[HYST_2]",8)) irdbheader
.hyst
[2] = (byte
)strtoul (st
+ 8,0,0);
1094 if (!strncmp (st
,"[HYST_3]",8)) irdbheader
.hyst
[3] = (byte
)strtoul (st
+ 8,0,0);
1095 if (!strncmp (st
,"[MINLED_0]",10)) irdbheader
.minledsel
[0] = (byte
)strtoul (st
+ 10,0,0);
1096 if (!strncmp (st
,"[MINLED_1]",10)) irdbheader
.minledsel
[1] = (byte
)strtoul (st
+ 10,0,0);
1097 if (!strncmp (st
,"[MINLED_2]",10)) irdbheader
.minledsel
[2] = (byte
)strtoul (st
+ 10,0,0);
1098 if (!strncmp (st
,"[MINLED_3]",10)) irdbheader
.minledsel
[3] = (byte
)strtoul (st
+ 10,0,0);
1099 if (!strncmp (st
,"[MAXLED_0]",10)) irdbheader
.maxledsel
[0] = (byte
)strtoul (st
+ 10,0,0);
1100 if (!strncmp (st
,"[MAXLED_1]",10)) irdbheader
.maxledsel
[1] = (byte
)strtoul (st
+ 10,0,0);
1101 if (!strncmp (st
,"[MAXLED_2]",10)) irdbheader
.maxledsel
[2] = (byte
)strtoul (st
+ 10,0,0);
1102 if (!strncmp (st
,"[MAXLED_3]",10)) irdbheader
.maxledsel
[3] = (byte
)strtoul (st
+ 10,0,0);
1103 if (!strncmp (st
,"[MINMASK_0]",11)) irdbheader
.minmask
[0] = strtoul (st
+ 11,0,0);
1104 if (!strncmp (st
,"[MINMASK_1]",11)) irdbheader
.minmask
[1] = strtoul (st
+ 11,0,0);
1105 if (!strncmp (st
,"[MINMASK_2]",11)) irdbheader
.minmask
[2] = strtoul (st
+ 11,0,0);
1106 if (!strncmp (st
,"[MINMASK_3]",11)) irdbheader
.minmask
[3] = strtoul (st
+ 11,0,0);
1107 if (!strncmp (st
,"[MAXMASK_0]",11)) irdbheader
.maxmask
[0] = strtoul (st
+ 11,0,0);
1108 if (!strncmp (st
,"[MAXMASK_1]",11)) irdbheader
.maxmask
[1] = strtoul (st
+ 11,0,0);
1109 if (!strncmp (st
,"[MAXMASK_2]",11)) irdbheader
.maxmask
[2] = strtoul (st
+ 11,0,0);
1110 if (!strncmp (st
,"[MAXMASK_3]",11)) irdbheader
.maxmask
[3] = strtoul (st
+ 11,0,0);
1111 if (!strncmp (st
,"[MINREMOTE_",11)) {
1113 memset (irdbheader
.minremote
[st
[11] - '0'],' ',80);
1114 memcpy (irdbheader
.minremote
[st
[11] - '0'],st
+ 13,strlen (st
+ 13));
1116 if (!strncmp (st
,"[MAXREMOTE_",11)) {
1118 memset (irdbheader
.maxremote
[st
[11] - '0'],' ',80);
1119 memcpy (irdbheader
.maxremote
[st
[11] - '0'],st
+ 13,strlen (st
+ 13));
1121 if (!strncmp (st
,"[MINCOMMAND_",12)) {
1123 memset (irdbheader
.mincommand
[st
[12] - '0'],' ',50);
1124 memcpy (irdbheader
.mincommand
[st
[12] - '0'],st
+ 14,strlen (st
+ 14));
1126 if (!strncmp (st
,"[MAXCOMMAND_",11)) {
1128 memset (irdbheader
.maxcommand
[st
[12] - '0'],' ',50);
1129 memcpy (irdbheader
.maxcommand
[st
[12] - '0'],st
+ 14,strlen (st
+ 14));
1131 if (!strncmp (st
,"[ACTIVE]",8)) irdbheader
.active
= (byte
)strtoul (st
+ 8,0,0);
1132 if (!strncmp (st
,"[SETTINGS]",10)) trans
[trans_num
].setup
= (byte
)strtoul (st
+ 10,0,0);
1133 if (!strncmp (st
,"[SOURCEMASK]",12)) trans
[trans_num
].source_mask
= strtoul (st
+ 12,0,0);
1134 if (!strncmp (st
,"[TARGETMASK]",12)) trans
[trans_num
].target_mask
= strtoul (st
+ 12,0,0);
1135 if (!strncmp (st
,"[REMOTE_NUM]",12)) trans
[trans_num
].remote_num
= (byte
)strtoul (st
+ 12,0,0);
1136 if (!strncmp (st
,"[GROUP_NUM]",11)) trans
[trans_num
].group_num
= (byte
)strtoul (st
+ 11,0,0);
1137 if (!strncmp (st
,"[SHIFT_NUM]",11)) trans
[trans_num
].multi_num
= (byte
)strtoul (st
+ 11,0,0);
1138 if (!strncmp (st
,"[ACC_TIMEOUT]",13)) trans
[trans_num
].accelerator_timeout
= (byte
)strtoul (st
+ 13,0,0);
1139 if (!strncmp (st
,"[ACC_SETUP]",11)) trans
[trans_num
].accelerator_repeat
= (byte
)strtoul (st
+ 11,0,0);
1140 if (!strncmp (st
,"[TIMEOUT]",9)) trans
[trans_num
].wait_timeout
= (word
)strtoul (st
+ 9,0,0);
1141 if (!strncmp (st
,"[INCLUDE_NAMES]",15)) trans
[trans_num
].include_names
= (byte
)strtoul (st
+ 15,0,0);
1142 pos
= ftell (fptrans
);
1147 int SetFlashdataEx (byte bus
,int iradr
)
1151 int adr
,i
,j
,flashwordsize
,nrem
;
1158 cal
= (IRDevices
[bus
].fw_capabilities
& FN_CALIBRATE
) != 0;
1160 for (i
=0;i
<= trans_num
;i
++) if ((trans
[i
].type
>= F_COMMAND
&& trans
[i
].type
<= F_VOLUMEMACROD
) ||
1161 (trans
[i
].type
>= F_TOGGLE
&& trans
[i
].type
< (F_TOGGLE
+ 6*4)) ||
1162 trans
[i
].type
>= F_MACRO
|| trans
[i
].type
== F_ENABLEGROUP
|| trans
[i
].type
== F_PREKEY
) {
1163 if (DBFindRemoteCommandEx (trans
[i
].remote
,trans
[i
].command
,&ird
,cal
)) trans
[i
].type
= F_ERROR
;
1167 memset (flash_data
,0,sizeof (flash_data
));
1168 pnt
= (FLASH_CONTENT
*)flash_data
;
1169 pnt
->dir_cnt
= cmd_count
;
1170 pnt
->magic
= F_MAGIC
;
1174 for (i
=0;i
< REMOTE_CNT
;i
++) pnt
->group_flags
[i
] = 1;
1175 pnt
->trans_setup
[0] = trans
[0].setup
;
1176 pnt
->source_mask
[0] = (word
)trans
[0].source_mask
;
1177 pnt
->target_mask
[0] = (word
)trans
[0].target_mask
;
1178 pnt
->end_pnt
= pnt
->data_pnt
= CONTENT_LEN
;
1181 for (i
=0;i
<= trans_num
;i
++) if ((trans
[i
].type
>= F_COMMAND
&& trans
[i
].type
<= F_VOLUMEMACROD
) ||
1182 (trans
[i
].type
>= F_TOGGLE
&& trans
[i
].type
< (F_TOGGLE
+ 6*4)) ||
1183 trans
[i
].type
>= F_MACRO
|| trans
[i
].type
== F_ENABLEGROUP
|| trans
[i
].type
== F_PREKEY
) {
1184 memset (remname
,0,sizeof(remname
));
1185 strcpy (remname
,trans
[i
].remote
);
1186 nrem
= DBFindRemote (remname
);
1187 if (nrem
>= 0) if (rem_pnt
[nrem
].rcv_len
&& (!pnt
->rcv_len
|| rem_pnt
[nrem
].rcv_len
< pnt
->rcv_len
)) pnt
->rcv_len
= rem_pnt
[nrem
].rcv_len
;
1191 for (i
=0;i
<= trans_num
;i
++) if ((trans
[i
].type
>= F_COMMAND
&& trans
[i
].type
<= F_VOLUMEMACROD
) ||
1192 (trans
[i
].type
>= F_TOGGLE
&& trans
[i
].type
< (F_TOGGLE
+ 6*4)) ||
1193 trans
[i
].type
>= F_MACRO
|| trans
[i
].type
== F_ENABLEGROUP
|| trans
[i
].type
== F_PREKEY
) {
1194 DBFindRemoteCommandEx (trans
[i
].remote
,trans
[i
].command
,&ird
,cal
);
1195 ird
.data
[ird
.ir_length
] = 0;
1196 set_entry (ird
.data
,cmd_num
,pnt
,trans
[i
].type
,trans
[i
].remote_num
,trans
[i
].group_num
,trans
[i
].multi_num
,trans
[i
].setup
,
1197 (word
)trans
[i
].source_mask
,trans
[i
].accelerator_timeout
,trans
[i
].accelerator_repeat
,remote_statusex
[bus
].stat
[iradr
].version
+1,trans
[i
].include_names
,trans
[i
].remote
,trans
[i
].command
,pnt
->rcv_len
);
1202 for (i
=0;i
<= trans_num
;i
++) {
1203 if (trans
[i
].type
== F_REMOTE
) {
1204 pnt
->trans_setup
[trans
[i
].remote_num
] = trans
[i
].setup
;
1205 pnt
->target_mask
[trans
[i
].remote_num
] = (word
)trans
[i
].target_mask
;
1206 pnt
->source_mask
[trans
[i
].remote_num
] = (word
)trans
[i
].source_mask
;
1208 if (trans
[i
].type
== F_ENABLEGROUP
) cmd_num
++;
1210 if (trans
[i
].type
== F_PREKEY
) cmd_num
++;
1212 if (trans
[i
].type
>= F_COMMAND
&& trans
[i
].type
<= F_VOLUMEMACROD
) {
1213 if (trans
[i
+1].type
== F_SEND
) {
1214 DBFindRemoteCommandEx (trans
[i
+1].remote
,trans
[i
+1].command
,&ird
,cal
);
1215 ird
.target_mask
= (word
)trans
[i
+1].target_mask
;
1216 set_commanddata (cmd_num
,&ird
);
1217 if (trans
[i
].type
== F_VOLUMEMACROD
) {
1218 if (trans
[i
+2].type
== F_SEND
) {
1219 DBFindRemoteCommandEx (trans
[i
+2].remote
,trans
[i
+2].command
,&ird
,cal
);
1220 ird
.target_mask
= (word
)trans
[i
+2].target_mask
;
1221 set_commanddata (-1,&ird
);
1227 if (trans
[i
].type
>= F_MACRO
) {
1228 for (j
=0;j
< trans
[i
].type
- F_MACRO
&& trans
[i
+j
+1].type
== F_SEND
;j
++) {
1229 DBFindRemoteCommandEx (trans
[i
+j
+1].remote
,trans
[i
+j
+1].command
,&ird
,cal
);
1230 ird
.target_mask
= (word
)trans
[i
+j
+1].target_mask
;
1231 ird
.address
= trans
[i
+j
+1].wait_timeout
/ 16;
1232 if (j
) set_commanddata (-1,&ird
);
1233 else set_commanddata (cmd_num
,&ird
);
1237 if (trans
[i
].type
>= F_TOGGLE
&& trans
[i
].type
< (F_TOGGLE
+ 6*4)) {
1238 for (j
=0;j
< ((trans
[i
].type
- F_TOGGLE
) % 6) && trans
[i
+j
+1].type
== F_SEND
;j
++) {
1239 DBFindRemoteCommandEx (trans
[i
+j
+1].remote
,trans
[i
+j
+1].command
,&ird
,cal
);
1240 ird
.target_mask
= (word
)trans
[i
+j
+1].target_mask
;
1241 ird
.address
= trans
[i
+j
+1].wait_timeout
/ 16;
1242 if (j
) set_commanddata (-1,&ird
);
1243 else set_commanddata (cmd_num
,&ird
);
1251 while (adr
< pnt
->end_pnt
) val
+= flash_data
[adr
++];
1252 pnt
->checksum
= val
;
1254 // cap = iradr >> 8;
1255 // if (!(cap & FN_TRANSL)) flashwordsize = 64;
1258 flashwordsize
= 128;
1261 while (adr
< pnt
->end_pnt
) {
1262 if ((adr
+ flashwordsize
/2) < pnt
->end_pnt
) TransferFlashdataEx (bus
,flash_data
+ adr
,adr
,flashwordsize
,0,iradr
);
1263 else TransferFlashdataEx (bus
,flash_data
+ adr
,adr
,flashwordsize
,1,iradr
);
1264 adr
+= flashwordsize
/ 2;
1271 void set_commanddata (int pos
,IRDATA
*irpnt
)
1273 HASH_ENTRY
*hash_table
;
1274 FLASH_ENTRY_ORG
*fentry
;
1275 FLASH_CONTENT
*content
;
1277 content
= (FLASH_CONTENT
*)flash_data
;
1278 hash_table
= (HASH_ENTRY
*)(flash_data
+ CONTENT_LEN
);
1279 fentry
= (FLASH_ENTRY_ORG
*)(flash_data
+ hash_table
[pos
].adr
);
1281 irpnt
-> command
= HOST_SEND
;
1282 if (irpnt
-> mode
& RAW_DATA
)
1283 irpnt
-> len
= (sizeof (IRDATA
) - (CODE_LEN
+ (RAW_EXTRA
))) + irpnt
-> ir_length
;
1285 irpnt
-> len
= (sizeof (IRDATA
) - CODE_LEN
) + irpnt
-> ir_length
;
1287 if (time_len
!= TIME_LEN
) {
1288 if (irpnt
->mode
& RAW_DATA
) {
1289 if (irpnt
->ir_length
> OLD_LENRAW
) return;
1292 if (irpnt
->time_cnt
> 6) return;
1293 ConvertToIRTRANS3 (irpnt
);
1298 // irpnt->target_mask = 0xffff;
1300 if (pos
>= 0) fentry
->flash_adr
= content
->end_pnt
;
1302 memcpy ((void *)(flash_data
+ content
->end_pnt
),(void *)irpnt
,irpnt
->len
);
1303 content
->end_pnt
+= (irpnt
->len
+ 1) / 2;
1307 void set_entry (char entry
[],int pos
,FLASH_CONTENT
*content
,byte type
,byte remote
,byte group
,byte shift
,byte setup
,word sourcemask
,word acc_timeout
,word acc_repeat
,char *version
,byte nmflag
,char *remname
,char *comname
,byte rcv_len
)
1309 HASH_ENTRY
*hash_table
;
1310 FLASH_ENTRY_ORG
*fentry
;
1312 hash_table
= (HASH_ENTRY
*)(flash_data
+ CONTENT_LEN
);
1314 if (!pos
) content
->data_pnt
= CONTENT_LEN
+ content
->dir_cnt
* (sizeof (HASH_ENTRY
) / 2);
1316 if (rcv_len
) entry
[rcv_len
] = 0;
1319 hash_table
[pos
].hashcode
= get_hashcode (entry
,(byte
)strlen (entry
));
1320 hash_table
[pos
].adr
= content
->data_pnt
;
1322 fentry
= (FLASH_ENTRY_ORG
*)(flash_data
+ content
->data_pnt
);
1323 fentry
->type
= type
;
1324 fentry
->flash_adr
= 0;
1325 if (group
) fentry
->group
= group
- 1;
1326 else fentry
->group
= 0;
1327 fentry
->remote
= remote
;
1328 fentry
->source_mask
= sourcemask
;
1329 fentry
->accelerator_timeout
= (byte
)acc_timeout
;
1330 fentry
->accelerator_repeat
= (byte
)acc_repeat
;
1331 fentry
->trans_setup
= setup
;
1332 fentry
->len
= (byte
)strlen (entry
);
1334 if (strcmp (version
,"5.04.05") >= 0) {
1338 sprintf (nmstr
,"%s,%s\r\n",remname
,comname
);
1339 stlen
= (byte
)strlen (nmstr
);
1341 fentry
->cdata
[0] = shift
;
1342 fentry
->cdata
[1] = stlen
;
1343 strcpy (fentry
->cdata
+2,entry
);
1344 strcpy (fentry
->cdata
+2+fentry
->len
,nmstr
);
1346 content
->end_pnt
= content
->data_pnt
= (13 + fentry
->len
+ stlen
+ 1) / 2 + hash_table
[pos
].adr
;
1348 else if (strcmp (version
,"4.04.27") >= 0) {
1349 fentry
->cdata
[0] = shift
;
1350 strcpy (fentry
->cdata
+1,entry
);
1351 content
->end_pnt
= content
->data_pnt
= (12 + fentry
->len
+ 1) / 2 + hash_table
[pos
].adr
;
1354 strcpy (fentry
->cdata
,entry
);
1355 content
->end_pnt
= content
->data_pnt
= (11 + fentry
->len
+ 1) / 2 + hash_table
[pos
].adr
;
1362 void read_flashdata (byte
*pnt
,word adr
,word cnt
)
1365 read_nextflashdata (pnt
,cnt
);
1370 void set_flashadr (word adr
)
1375 void read_nextflashdata (byte
*pnt
,word cnt
)
1377 memcpy (pnt
,flash_data
+ last_adr
,cnt
);
1378 last_adr
+= cnt
/ 2;
1383 word
get_hashcode (byte data
[],byte len
)
1388 for (i
=0;i
< len
;i
++) h
+= (data
[i
] & 7) << ((i
* 2) & 15);
1394 /*crc-16 standard root*/
1395 #define POLYNOMIAL 0x8005
1411 void PutCRC(byte b
,CRC_BUFFER
*crcb
)
1414 crcb
->Part
.Data
= b
;
1417 crcb
->Whole
= crcb
->Whole
<< 1;
1418 if (crcb
->Part
.Head
& 0x01)
1419 crcb
->Part
.Remainder
^= POLYNOMIAL
;
1424 word
CRC (byte
*Data
, int Length
,word init
)
1426 CRC_BUFFER CRC_buffer
;
1428 CRC_buffer
.Part
.Remainder
= init
;
1429 while (Length
-- > 0)
1430 PutCRC(*Data
++,&CRC_buffer
);
1431 PutCRC(0,&CRC_buffer
);
1432 PutCRC(0,&CRC_buffer
);
1433 return CRC_buffer
.Part
.Remainder
;