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.
35 #include <sys/types.h>
37 #include <sys/timeb.h>
39 #define MSG_NOSIGNAL 0
52 #include <sys/types.h>
53 #include <sys/socket.h>
54 #include <netinet/in.h>
56 #include <arpa/inet.h>
68 #define closesocket close
84 BOOL WINAPI
ShutdownHandler (DWORD type
);
85 extern WSAEVENT IrtLanEvent
;
88 #define RESEND_WAIT_SER 5
89 #define RESEND_WAIT_USB 10
93 extern STATUS_BUFFER remote_statusex
[MAX_IR_DEVICES
];
94 extern byte new_lcd_flag
;
95 extern int display_bus
;
96 extern SOCKET irtlan_socket
;
97 int OpenIRTransLANSocket (void);
98 int OpenIRTransBroadcastSockets (void);
99 void DecodeFunctions (DEVICEINFO
*dev
);
100 extern SOCKET irtlan_outbound
;
101 extern int protocol_version
;
102 extern char pidfile
[256];
104 byte DispConvTable
[TABLE_CNT
][256];
110 #define FN_POWERON 16
113 #define FN_SOFTID 128
114 #define FN_EEPROM 256
115 #define FN_TRANSL 512
116 #define FN_HWCARR 1024
117 #define FN_DUALRCV 2048
119 int IRTransLanFlash (DEVICEINFO
*dev
,IRDATA_LAN_FLASH
*ird
,int len
,uint32_t ip
);
120 void SwapWordN (word
*pnt
);
121 void SwapIntN (int32_t *pnt
);
125 int SendSerialBlock (int bus
,byte data
[],byte len
)
127 IRDATA_LAN_FLASH irdf
;
129 if (IRDevices
[bus
].io
.if_type
!= IF_LAN
|| !(IRDevices
[bus
].fw_capabilities
& FN_SER
)) return (ERR_NO_RS232
);
133 SwapWordN (&irdf
.len
);
135 memcpy (irdf
.data
,data
,len
);
136 irdf
.netcommand
= COMMAND_SEND_RS232
;
138 IRTransLanFlash (IRDevices
+bus
,&irdf
,len
,IRDevices
[bus
].io
.IPAddr
[0].sin_addr
.S_un
.S_addr
);
140 IRTransLanFlash (IRDevices
+bus
,&irdf
,len
,IRDevices
[bus
].io
.IPAddr
[0].sin_addr
.s_addr
);
148 void GetBusList (REMOTEBUFFER
*buf
,int offset
)
151 memset (buf
,0,sizeof (REMOTEBUFFER
));
152 buf
->statustype
= STATUS_BUSLIST
;
153 buf
->statuslen
= sizeof (REMOTEBUFFER
);
154 buf
->offset
= (short)offset
;
157 while (i
< 40 && offset
< device_cnt
) {
158 memset (buf
->remotes
[i
].name
,0,80);
159 sprintf (buf
->remotes
[i
].name
,"%3d: %s [%s]",offset
,IRDevices
[offset
].name
,IRDevices
[offset
].device_node
);
160 buf
->remotes
[i
].source_mask
= 0;
161 buf
->remotes
[i
].target_mask
= 0;
166 buf
->count_buffer
= i
;
167 buf
->count_total
= (word
)device_cnt
;
168 if (i
== 40) buf
->count_remaining
= (short)(device_cnt
- offset
);
169 else buf
->count_remaining
= 0;
175 int SetTransceiverModusEx2 (int bus
,byte addr
,char *hotcode
,int hotlen
)
179 md
.sbus_command
= HOST_SET_MODE2
;
181 if (addr
<= 15) md
.sbus_address
|= addr
;
182 if (addr
== 'L') md
.sbus_address
|= ADRESS_LOCAL
;
183 if (addr
== '*') md
.sbus_address
|= ADRESS_ALL
;
185 md
.hotcode_len
= hotlen
;
186 memcpy (md
.hotcode
,hotcode
,hotlen
);
188 md
.sbus_len
= sizeof (MODE_BUFFER
) + md
.hotcode_len
- CODE_LENRAW
;
190 res
= WriteTransceiverEx (IRDevices
+ bus
,(IRDATA
*)&md
);
191 if (res
) return (res
);
196 int SetPowerLED (int bus
,byte mode
,byte val
)
201 ird
.command
= SET_POWER_LED
;
204 ird
.target_mask
= val
;
206 res
= WriteTransceiverEx (IRDevices
+ bus
,&ird
);
207 if (res
) return (res
);
213 int SetTransceiverModusEx (int bus
,byte mode
,word send_mask
,byte addr
,char *hotcode
,int hotlen
,byte extended_mode
,byte extended_mode2
,byte extended_mode3
,byte extended_mode4
,byte
*mac
)
217 md
.sbus_command
= HOST_SETMODE
;
219 if (addr
<= 15) md
.sbus_address
|= addr
;
220 if (addr
== 'L') md
.sbus_address
|= ADRESS_LOCAL
;
221 if (addr
== '*') md
.sbus_address
|= ADRESS_ALL
;
223 md
.hotcode_len
= hotlen
;
224 memcpy (md
.hotcode
,hotcode
,hotlen
);
226 md
.hotcode
[hotlen
] = extended_mode
;
227 md
.hotcode
[hotlen
+1] = extended_mode2
;
228 md
.hotcode
[hotlen
+2] = extended_mode3
;
229 md
.hotcode
[hotlen
+3] = extended_mode4
;
231 md
.sbus_len
= sizeof (MODE_BUFFER
) + md
.hotcode_len
- (CODE_LENRAW
- 4);
233 if (mac
&& (mac
[0] || mac
[1] || mac
[2] || mac
[3] || mac
[4] || mac
[5])) {
234 memcpy (md
.hotcode
+hotlen
+4,mac
,6);
239 md
.target_mask
= send_mask
;
241 res
= WriteTransceiverEx (IRDevices
+ bus
,(IRDATA
*)&md
);
242 if (res
) return (res
);
247 int rcv_status_timeout (int timeout
,uint32_t ip
);
249 int TransferFlashdataEx (int bus
,word data
[],int adr
,int len
,byte active
,int iradr
)
256 if (bus
> MAX_IR_DEVICES
) bus
= 0; // Fix für Kompatibilität mit Clients < V5.0
257 if (iradr
== IRDevices
[bus
].my_addr
) cap
= IRDevices
[bus
].fw_capabilities
;
258 else cap
= remote_statusex
[bus
].stat
[iradr
].capabilities
;
260 if ((cap
& FN_EEPROM
) == 0) {
261 fprintf (stderr
,"No IRTrans with EEPROM connected\n\n");
266 fprintf (stderr
,"Maximum Transfer length is 128 Bytes [%d]\n\n",len
);
270 md
.command
= SET_TRANSLATE_DATA
;
271 md
.address
= (byte
)(iradr
& 0xff);
272 md
.target_mask
= adr
;
275 md
.len
= (sizeof (IRDATA
) - CODE_LEN
) + md
.ir_length
;
277 memcpy (md
.data
,data
,len
);
279 if (time_len
!= TIME_LEN
) ConvertToIRTRANS3 (&md
);
281 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) {
283 while (res
!= COMMAND_FLASH_ACK
&& res
!= COMMAND_FLASH_ACK_1
&& res
!= COMMAND_FLASH_ACK_2
&& cnt
< 10) {
284 res
= WriteTransceiverEx (IRDevices
+ bus
,&md
);
285 if (res
) return (res
);
287 res
= rcv_status_timeout (500,IRDevices
[bus
].io
.IPAddr
[0].sin_addr
.S_un
.S_addr
);
289 res
= rcv_status_timeout (500,IRDevices
[bus
].io
.IPAddr
[0].sin_addr
.s_addr
);
293 if (cnt
== 10) fprintf (stderr
,"Flash Error !\n");
297 res
= WriteTransceiverEx (IRDevices
+ bus
,&md
);
298 if (res
) return (res
);
300 if ((iradr
& 0xff) != IRDevices
[bus
].my_addr
) {
301 if (remote_statusex
[bus
].stat
[iradr
& 0xff].extended_mode
& SBUS_UART
) {
303 if ((remote_statusex
[bus
].stat
[iradr
& 0xff].extended_mode2
& SBUS_BAUD_MASK
) == 0) sl
= 400;
304 else if ((remote_statusex
[bus
].stat
[iradr
& 0xff].extended_mode2
& SBUS_BAUD_MASK
) == 16) sl
= 150;
305 else if ((remote_statusex
[bus
].stat
[iradr
& 0xff].extended_mode2
& SBUS_BAUD_MASK
) == 24) sl
= 80;
317 int ReadFlashdataEx (int bus
,int adr
)
321 int offset
= 0,len
= 128;
322 byte databuffer
[132];
325 if ((IRDevices
[bus
].fw_capabilities
& FN_EEPROM
) == 0) {
326 fprintf (stderr
,"No IRTrans with EEPROM connected\n\n");
333 md
.target_mask
= adr
/ 2;
337 res
= WriteTransceiverEx (IRDevices
+ bus
,&md
);
338 if (res
) return (res
);
342 len
= recv (irtlan_socket
,databuffer
,129,0);
343 // res = ReadIRStringEx (IRDevices+bus,databuffer,len,2000);
344 // if (res != len) return (-1);
347 for (res
=0;res
< len
;res
++) {
348 printf ("%02x ",databuffer
[res
+offset
]);
349 if (!((res
+ 1) % 16)) {
351 if ((res
+ 1) < len
) printf ("%04x ",res
+1+adr
);
361 int ReadAnalogInputs (int bus
,byte mask
,ANALOG_INPUTS
*inputs
)
365 GET_ANALOG_INPUTS ai
;
366 struct sockaddr_in send_adr
;
374 md
.command
= READ_ANALOG_INPUTS
;
380 res
= WriteTransceiverEx (IRDevices
+ bus
,&md
);
381 if (res
) return (res
);
384 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) {
386 res
= WaitForSingleObject (IrtLanEvent
,2000);
387 if (res
== WAIT_TIMEOUT
) return (ERR_TIMEOUT
);
393 FD_SET (irtlan_socket
,&events
);
394 maxfd
= irtlan_socket
+ 1;
399 wait
= select (maxfd
,&events
,NULL
,NULL
,&tv
);
400 if (!wait
) return (ERR_TIMEOUT
);
402 i
= sizeof (send_adr
);
403 res
= recvfrom(irtlan_socket
,(byte
*)&ai
,sizeof (GET_ANALOG_INPUTS
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
404 if (res
<= 0 || res
!= ai
.ai
.len
+ 1 || ai
.netcommand
!= RESULT_ANALOG_INPUT
) return (ERR_TIMEOUT
);
409 res
= ReadIRStringEx (IRDevices
,(byte
*)&(ai
.ai
),sizeof (ANALOG_INPUTS
),500);
410 if (res
!= sizeof (ANALOG_INPUTS
)) return (ERR_TIMEOUT
);
413 memcpy (inputs
,&(ai
.ai
),sizeof (ANALOG_INPUTS
));
419 int SetRelaisEx (int bus
,byte val
,byte rel
)
428 md
.target_mask
= rel
;
429 md
.transmit_freq
= val
;
434 res
= WriteTransceiverEx (IRDevices
+ bus
,&md
);
435 if (res
) return (res
);
442 int SetTransceiverIDEx (int bus
,byte id
)
448 if ((IRDevices
[bus
].fw_capabilities
& FN_SOFTID
) == 0) {
449 fprintf (stderr
,"No SoftID IRTrans connected. Cannot set ID\n\n");
456 md
.transmit_freq
= id
* 37;
462 res
= WriteTransceiverEx (IRDevices
+ bus
,&md
);
463 if (res
) return (res
);
469 int ResetTransceiverEx (int bus
)
475 md
.command
= SBUS_RESET
;
478 res
= WriteTransceiverEx (IRDevices
+ bus
,&md
);
479 if (res
) return (res
);
485 int GetBusInfoEx (STATUS_BUFFER
*sb
,int bus
)
490 ir
.command
= HOST_NETWORK_STATUS
;
494 for (i
=0;i
<device_cnt
;i
++) {
495 res
= WriteTransceiverEx (IRDevices
+ i
,&ir
);
496 if (res
) return (res
);
497 if (IRDevices
[i
].io
.if_type
== IF_LAN
) {
498 res
= GetBusInfoDetail (sb
+ i
,(byte
)i
);
499 if (res
) return (res
);
502 for (i
=0;i
<device_cnt
;i
++) {
503 if (IRDevices
[i
].io
.if_type
!= IF_LAN
) res
= GetBusInfoDetail (sb
+ i
,(byte
)i
);
504 if (res
) return (res
);
508 res
= WriteTransceiverEx (IRDevices
+ bus
,&ir
);
509 if (res
) return (res
);
510 res
= GetBusInfoDetail (sb
,bus
);
511 if (res
) return (res
);
518 int GetBusInfoDetail (STATUS_BUFFER
*sb
,int bus
)
526 struct sockaddr_in send_adr
;
534 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) {
537 if (IRDevices
[bus
].fw_capabilities
& FN_SBUS
) for (j
=0;j
< 16;j
++) while (1) {
538 res
= WaitForSingleObject (IrtLanEvent
,2000);
540 if (res
== WAIT_TIMEOUT
) return (ERR_TIMEOUT
);
542 ResetEvent (IrtLanEvent
);
543 i
= sizeof (send_adr
);
544 memset (&sl
,0,sizeof (sl
));
545 res
= recvfrom(irtlan_socket
,(byte
*)&sl
,sizeof (sl
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
546 if (res
<= 0 || res
!= sl
.stat
.sbus_len
+ 1) return (ERR_TIMEOUT
);
547 if (sl
.netcommand
== RESULT_DEVSTATUS
&& send_adr
.sin_addr
.S_un
.S_addr
== IRDevices
[bus
].io
.IPAddr
[0].sin_addr
.S_un
.S_addr
) {
548 IRDevices
[bus
].my_addr
= 0;
549 memcpy (&sb
->stat
[j
],&sl
.stat
,sizeof (STATUS_LINE
));
554 res
= WaitForSingleObject (IrtLanEvent
,2000);
555 if (res
== WAIT_TIMEOUT
) return (ERR_TIMEOUT
);
557 ResetEvent (IrtLanEvent
);
558 i
= sizeof (send_adr
);
559 memset (&sl
,0,sizeof (sl
));
560 res
= recvfrom(irtlan_socket
,(byte
*)&sl
,sizeof (sl
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
561 if (res
<= 0 || res
!= sl
.stat
.sbus_len
+ 1) return (ERR_TIMEOUT
);
562 if (sl
.netcommand
== RESULT_DEVSTATUS
&& send_adr
.sin_addr
.S_un
.S_addr
== IRDevices
[bus
].io
.IPAddr
[0].sin_addr
.S_un
.S_addr
) {
563 IRDevices
[bus
].my_addr
= 0;
564 memcpy (&sb
->stat
[0],&sl
.stat
,sizeof (STATUS_LINE
));
570 if (IRDevices
[bus
].fw_capabilities
& FN_SBUS
) for (j
=0;j
< 16;j
++) while (1) {
572 FD_SET (irtlan_socket
,&events
);
573 maxfd
= irtlan_socket
+ 1;
577 wait
= select (maxfd
,&events
,NULL
,NULL
,&tv
);
578 if (!wait
) return (ERR_TIMEOUT
);
579 i
= sizeof (send_adr
);
580 memset (&sl
,0,sizeof (sl
));
581 res
= recvfrom(irtlan_socket
,(byte
*)&sl
,sizeof (sl
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
582 if (res
<= 0 || res
!= sl
.stat
.sbus_len
+ 1) return (ERR_TIMEOUT
);
583 if (sl
.netcommand
== RESULT_DEVSTATUS
&& send_adr
.sin_addr
.s_addr
== IRDevices
[bus
].io
.IPAddr
[0].sin_addr
.s_addr
) {
584 IRDevices
[bus
].my_addr
= 0;
585 memcpy (&sb
->stat
[j
],&sl
.stat
,sizeof (STATUS_LINE
));
591 FD_SET (irtlan_socket
,&events
);
592 maxfd
= irtlan_socket
+ 1;
596 wait
= select (maxfd
,&events
,NULL
,NULL
,&tv
);
597 if (!wait
) return (ERR_TIMEOUT
);
598 i
= sizeof (send_adr
);
599 memset (&sl
,0,sizeof (sl
));
600 res
= recvfrom(irtlan_socket
,(byte
*)&sl
,sizeof (sl
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
601 if (res
<= 0 || res
!= sl
.stat
.sbus_len
+ 1) return (ERR_TIMEOUT
);
602 if (sl
.netcommand
== RESULT_DEVSTATUS
&& send_adr
.sin_addr
.s_addr
== IRDevices
[bus
].io
.IPAddr
[0].sin_addr
.s_addr
) {
603 IRDevices
[bus
].my_addr
= 0;
604 memcpy (&sb
->stat
[0],&sl
.stat
,sizeof (STATUS_LINE
));
612 res
= ReadIRStringEx (IRDevices
+bus
,(byte
*)sb
,sizeof (STATUS_BUFFER
),5000);
613 if (res
== sizeof (STATUS_BUFFER_1
)) {
614 memcpy (&sb1
,sb
,sizeof (STATUS_BUFFER_1
));
615 memset (sb
,0,sizeof (STATUS_BUFFER
));
616 sb
->my_adress
= sb1
.my_adress
;
618 for (i
=0;i
<= 15;i
++) {
619 sb
->stat
[i
].device_mode
= sb1
.stat
[i
].device_mode
;
620 sb
->stat
[i
].send_mask
= sb1
.stat
[i
].send_mask
;
621 memcpy (sb
->stat
[i
].version
,sb1
.stat
[i
].version
,10);
622 if (i
== sb
->my_adress
) sb
->stat
[i
].capabilities
= IRDevices
[bus
].fw_capabilities
;
626 if (res
== sizeof (STATUS_BUFFER_2
)) {
627 memcpy (&sb2
,sb
,sizeof (STATUS_BUFFER_2
));
628 memset (sb
,0,sizeof (STATUS_BUFFER
));
629 sb
->my_adress
= sb2
.my_adress
;
631 for (i
=0;i
<= 15;i
++) {
632 sb
->stat
[i
].device_mode
= sb2
.stat
[i
].device_mode
;
633 sb
->stat
[i
].extended_mode
= sb2
.stat
[i
].extended_mode
;
634 sb
->stat
[i
].send_mask
= sb2
.stat
[i
].send_mask
;
635 memcpy (sb
->stat
[i
].version
,sb2
.stat
[i
].version
,10);
636 if (i
== sb
->my_adress
) sb
->stat
[i
].capabilities
= IRDevices
[bus
].fw_capabilities
;
640 if (res
== sizeof (STATUS_BUFFER_3
)) {
641 memcpy (&sb3
,sb
,sizeof (STATUS_BUFFER_3
));
642 memset (sb
,0,sizeof (STATUS_BUFFER
));
643 sb
->my_adress
= sb3
.my_adress
;
645 for (i
=0;i
<= 15;i
++) {
646 sb
->stat
[i
].device_mode
= sb3
.stat
[i
].device_mode
;
647 sb
->stat
[i
].extended_mode
= sb3
.stat
[i
].extended_mode
;
648 sb
->stat
[i
].send_mask
= sb3
.stat
[i
].send_mask
;
649 memcpy (sb
->stat
[i
].version
,sb3
.stat
[i
].version
,10);
650 sb
->stat
[i
].capabilities
= sb3
.stat
[i
].capabilities
;
654 if (res
== sizeof (STATUS_BUFFER_4
)) {
655 memcpy (&sb4
,sb
,sizeof (STATUS_BUFFER_4
));
656 memset (sb
,0,sizeof (STATUS_BUFFER
));
657 sb
->my_adress
= sb4
.my_adress
;
659 for (i
=0;i
<= 15;i
++) {
660 sb
->stat
[i
].device_mode
= sb4
.stat
[i
].device_mode
;
661 sb
->stat
[i
].extended_mode
= sb4
.stat
[i
].extended_mode
;
662 sb
->stat
[i
].send_mask
= sb4
.stat
[i
].send_mask
;
663 memcpy (sb
->stat
[i
].version
,sb4
.stat
[i
].version
,10);
664 sb
->stat
[i
].capabilities
= sb4
.stat
[i
].capabilities
;
665 sb
->stat
[i
].extended_mode2
= sb4
.stat
[i
].extended_mode2
;
668 if (res
!= sizeof (STATUS_BUFFER
) && res
!= sizeof (STATUS_BUFFER_1
) && res
!= sizeof (STATUS_BUFFER_2
) && res
!= sizeof (STATUS_BUFFER_3
) && res
!= sizeof (STATUS_BUFFER_4
)) return (ERR_TIMEOUT
);
670 IRDevices
[bus
].my_addr
= sb
->my_adress
;
673 SwapStatusbuffer (sb
);
678 int ResendIREx (int bus
,IRDATA
*ir_data
)
682 ir_data
-> command
= HOST_RESEND
;
685 if (bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) res
= WriteTransceiverEx (&IRDevices
[i
],ir_data
);
686 else res
= (WriteTransceiverEx (&IRDevices
[bus
],ir_data
));
687 if (res
== ERR_RESEND
) {
688 ir_data
-> command
= HOST_SEND
;
689 if (ir_data
-> mode
& RAW_DATA
)
690 ir_data
-> len
= (sizeof (IRDATA
) - (CODE_LEN
+ (RAW_EXTRA
))) + ir_data
-> ir_length
;
692 ir_data
-> len
= (sizeof (IRDATA
) - CODE_LEN
) + ir_data
-> ir_length
;
693 if (bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) res
= WriteTransceiverEx (&IRDevices
[i
],ir_data
);
694 else res
= (WriteTransceiverEx (&IRDevices
[bus
],ir_data
));
700 int GetDeviceData (int cmd_num
,DATABUFFER
*dat
)
705 int mac_len
,mac_pause
,rpt_len
;
707 res
= DBGetIRCode (cmd_num
,&ird
,0,&mac_len
,&mac_pause
,&rpt_len
,0);
708 if (res
) return (res
);
709 if (mac_len
|| rpt_len
) return (ERR_ISMACRO
);
711 ird
.command
= HOST_SEND
;
712 if (ird
.mode
& RAW_DATA
) ird
.len
= (sizeof (IRDATA
) - (CODE_LEN
+ (RAW_EXTRA
))) + ird
.ir_length
;
714 ird
.len
= (sizeof (IRDATA
) - CODE_LEN
) + ird
.ir_length
;
715 if (ird
.mode
& RC6_DATA
) ird
.len
++;
718 swap_irdata (&ird
,&send
);
720 if (time_len
!= TIME_LEN
) {
721 if (ird
.mode
& RAW_DATA
) {
722 if (ird
.ir_length
> OLD_LENRAW
) return (ERR_LONGRAW
);
725 if (ird
.time_cnt
> 6) return (ERR_LONGDATA
);
726 ConvertToIRTRANS3 (&send
);
729 send
.checksumme
= get_checksumme (&send
);
730 dat
->statustype
= STATUS_DEVICEDATA
;
731 dat
->statuslen
= sizeof (DATABUFFER
);
732 memcpy (dat
->data
,&send
,sizeof (IRDATA
));
738 int SendIR (int cmd_num
,int address
)
741 int i
,res
,bus
= 0,rpt
;
743 int mac_len
,mac_pause
,rpt_len
;
745 if (protocol_version
>= 210) bus
= (address
>> 19) & (MAX_IR_DEVICES
- 1);
746 else bus
= (address
>> 20) & (MAX_IR_DEVICES
- 1);
747 if (address
& 0x40000000) {
749 cal
= (IRDevices
[0].fw_capabilities
& FN_CALIBRATE
) != 0;
751 else cal
= (IRDevices
[bus
].fw_capabilities
& FN_CALIBRATE
) != 0;
753 res
= DBGetIRCode (cmd_num
,&ird
,0,&mac_len
,&mac_pause
,&rpt_len
,cal
);
754 if (res
) return (res
);
756 rpt
= DBGetRepeatCode (cmd_num
,&ird_rpt
,cal
);
758 if (address
& 0x10000) {
759 ird
.target_mask
= (word
)address
& 0xffff;
761 if (address
& 0x60000) ird
.address
= (byte
)((address
>> 17) & 0x3);
763 if (address
& 0x80000000) ird
.address
|= ((address
>> 25) & 28) + 4;
766 if (!rpt
)res
= DoSendIR (&ird
,&ird_rpt
,rpt_len
,mac_pause
,bus
);
767 else res
= DoSendIR (&ird
,NULL
,rpt_len
,mac_pause
,bus
);
769 if (mac_len
) msSleep (mac_pause
);
771 for (i
=1;i
< mac_len
;i
++) {
772 res
= DBGetIRCode (cmd_num
,&ird
,i
,&mac_len
,&mac_pause
,&rpt_len
,cal
);
773 if (res
) return (res
);
775 if (address
& 0x10000) {
776 ird
.target_mask
= (word
)address
& 0xffff;
778 if (address
& 0x60000) ird
.address
= (byte
)((address
>> 17) & 0x3);
780 if (address
& 0x80000000) ird
.address
|= ((address
>> 25) & 28) + 4;
782 if (!rpt
)res
= DoSendIR (&ird
,&ird_rpt
,rpt_len
,mac_pause
,bus
);
783 else res
= DoSendIR (&ird
,NULL
,rpt_len
,mac_pause
,bus
);
785 if (mac_len
) msSleep (mac_pause
);
793 int DoSendIR (IRDATA
*ir_data
,IRDATA
*ir_rep
,int rpt_len
,int rpt_pause
,int bus
)
797 unsigned int end_time
;
799 ir_data
-> command
= HOST_SEND
;
800 if (ir_data
-> mode
& RAW_DATA
) {
801 ir_data
-> len
= (sizeof (IRDATA
) - (CODE_LEN
+ (RAW_EXTRA
))) + ir_data
-> ir_length
;
802 if (mode_flag
& CODEDUMP
) PrintRawData ((IRRAW
*)ir_data
);
805 ir_data
-> len
= (sizeof (IRDATA
) - CODE_LEN
) + ir_data
-> ir_length
;
806 if (ir_data
->mode
& RC6_DATA
) ir_data
->len
++;
807 if (mode_flag
& CODEDUMP
) PrintPulseData (ir_data
);
812 if (bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) {
813 ocarrier
= ir_data
->transmit_freq
;
814 if (!IRDevices
[i
].io
.ext_carrier
) ir_data
->transmit_freq
= Convert2OldCarrier (ocarrier
);
815 res
= WriteTransceiverEx (&IRDevices
[i
],ir_data
);
816 ir_data
->transmit_freq
= ocarrier
;
819 ocarrier
= ir_data
->transmit_freq
;
820 if (!IRDevices
[bus
].io
.ext_carrier
) ir_data
->transmit_freq
= Convert2OldCarrier (ocarrier
);
821 res
= (WriteTransceiverEx (&IRDevices
[bus
],ir_data
));
822 ir_data
->transmit_freq
= ocarrier
;
828 ir_rep
-> command
= HOST_SEND
;
829 if (ir_rep
-> mode
& RAW_DATA
) {
830 ir_rep
-> len
= (sizeof (IRDATA
) - (CODE_LEN
+ (RAW_EXTRA
))) + ir_rep
-> ir_length
;
831 if (mode_flag
& CODEDUMP
) PrintRawData ((IRRAW
*)ir_rep
);
834 ir_rep
-> len
= (sizeof (IRDATA
) - CODE_LEN
) + ir_rep
-> ir_length
;
835 if (ir_rep
->mode
& RC6_DATA
) ir_rep
->len
++;
836 if (mode_flag
& CODEDUMP
) PrintPulseData (ir_rep
);
841 end_time
= GetMsTime () + rpt_len
;
842 if (bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) {
843 ocarrier
= ir_data
->transmit_freq
;
844 if (!IRDevices
[i
].io
.ext_carrier
) ir_data
->transmit_freq
= Convert2OldCarrier (ocarrier
);
845 res
= WriteTransceiverEx (&IRDevices
[i
],ir_data
);
846 ir_data
->transmit_freq
= ocarrier
;
849 ocarrier
= ir_data
->transmit_freq
;
850 if (!IRDevices
[bus
].io
.ext_carrier
) ir_data
->transmit_freq
= Convert2OldCarrier (ocarrier
);
851 res
= (WriteTransceiverEx (&IRDevices
[bus
],ir_data
));
852 ir_data
->transmit_freq
= ocarrier
;
857 if (ir_rep
&& GetMsTime () < end_time
) {
858 if (bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) {
859 ocarrier
= ir_rep
->transmit_freq
;
860 if (!IRDevices
[i
].io
.ext_carrier
) ir_rep
->transmit_freq
= Convert2OldCarrier (ocarrier
);
861 res
= WriteTransceiverEx (&IRDevices
[i
],ir_rep
);
862 ir_rep
->transmit_freq
= ocarrier
;
865 ocarrier
= ir_rep
->transmit_freq
;
866 if (!IRDevices
[bus
].io
.ext_carrier
) ir_rep
->transmit_freq
= Convert2OldCarrier (ocarrier
);
867 res
= (WriteTransceiverEx (&IRDevices
[bus
],ir_rep
));
868 ir_rep
->transmit_freq
= ocarrier
;
873 while (GetMsTime () < end_time
) {
874 ir_data
-> command
= HOST_RESEND
;
877 if (bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) res
= WriteTransceiverEx (&IRDevices
[i
],ir_data
);
878 else res
= (WriteTransceiverEx (&IRDevices
[bus
],ir_data
));
879 if (res
== ERR_RESEND
) {
880 if (ir_rep
) memcpy (ir_data
,ir_rep
,sizeof (IRDATA
));
881 ir_data
-> command
= HOST_SEND
;
882 if (ir_data
-> mode
& RAW_DATA
) ir_data
-> len
= (sizeof (IRDATA
) - (CODE_LEN
+ (RAW_EXTRA
))) + ir_data
-> ir_length
;
884 ir_data
-> len
= (sizeof (IRDATA
) - CODE_LEN
) + ir_data
-> ir_length
;
885 if (ir_data
->mode
& RC6_DATA
) ir_data
->len
++;
887 if (bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) {
888 ocarrier
= ir_data
->transmit_freq
;
889 if (!IRDevices
[i
].io
.ext_carrier
) ir_data
->transmit_freq
= Convert2OldCarrier (ocarrier
);
890 res
= WriteTransceiverEx (&IRDevices
[i
],ir_data
);
891 ir_data
->transmit_freq
= ocarrier
;
894 ocarrier
= ir_data
->transmit_freq
;
895 if (!IRDevices
[bus
].io
.ext_carrier
) ir_data
->transmit_freq
= Convert2OldCarrier (ocarrier
);
896 res
= (WriteTransceiverEx (&IRDevices
[bus
],ir_data
));
897 ir_data
->transmit_freq
= ocarrier
;
906 byte
Convert2OldCarrier (byte carrier
)
909 if (carrier
== 255 || carrier
< 128) return (carrier
);
910 oc
= (carrier
& 127) << 2;
911 if (oc
> 255) oc
= 255;
916 int SendIRDataEx (IRDATA
*ir_data
,int address
)
920 if (address
& 0x10000) {
921 ir_data
->target_mask
= (word
)address
& 0xffff;
923 if (protocol_version
>= 210) bus
= (address
>> 19) & (MAX_IR_DEVICES
- 1);
924 else bus
= (address
>> 20) & (MAX_IR_DEVICES
- 1);
925 if (address
& 0x40000000) bus
= 0xffff;
927 if (address
& 0x60000) ir_data
-> address
= (byte
)((address
>> 17) & 0x3);
929 if (address
& 0x80000000) ir_data
-> address
|= ((address
>> 25) & 28) + 4;
931 ir_data
-> command
= HOST_SEND
;
932 if (ir_data
-> mode
& RAW_DATA
) {
933 ir_data
-> len
= (sizeof (IRDATA
) - (CODE_LEN
+ (RAW_EXTRA
))) + ir_data
-> ir_length
;
934 if (mode_flag
& CODEDUMP
) PrintRawData ((IRRAW
*)ir_data
);
937 ir_data
-> len
= (sizeof (IRDATA
) - CODE_LEN
) + ir_data
-> ir_length
;
938 if (ir_data
->mode
& RC6_DATA
) ir_data
->len
++;
939 if (mode_flag
& CODEDUMP
) PrintPulseData (ir_data
);
941 if (bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) {
942 ocarrier
= ir_data
->transmit_freq
;
943 if (!IRDevices
[i
].io
.ext_carrier
) ir_data
->transmit_freq
= Convert2OldCarrier (ocarrier
);
944 res
= WriteTransceiverEx (&IRDevices
[i
],ir_data
);
945 ir_data
->transmit_freq
= ocarrier
;
948 ocarrier
= ir_data
->transmit_freq
;
949 if (!IRDevices
[bus
].io
.ext_carrier
) ir_data
->transmit_freq
= Convert2OldCarrier (ocarrier
);
950 res
= (WriteTransceiverEx (&IRDevices
[bus
],ir_data
));
951 ir_data
->transmit_freq
= ocarrier
;
957 void LCDTimeCommand (byte mode
)
970 memset (&irw
,0,sizeof (IRRAW
));
972 irw
.command
= HOST_SEND
;
973 irw
.mode
= LCD_DATA
| mode
;
974 irw
.target_mask
= 0xffff;
978 if (tb
.dstflag
) i
= 3600;
980 *((unsigned int *)irw
.data
) = (unsigned int)(tb
.time
- 60 * tb
.timezone
+ i
);
981 irw
.data
[4] = tb
.millitm
/ 48;
985 i
= gettimeofday (&tb
,&tz
);
987 gettimeofday (&tb
,NULL
);
988 *((unsigned int *)irw
.data
) = tb
.tv_sec
;
990 else *((unsigned int *)irw
.data
) = tb
.tv_sec
- 60 * tz
.tz_minuteswest
;
991 irw
.data
[4] = tb
.tv_usec
/ 48000;
994 swap_int ((int *)irw
.data
);
995 irw
.len
= (sizeof (IRDATA
) - (CODE_LEN
+ (RAW_EXTRA
))) + 5;
996 for (i
=0;i
<device_cnt
;i
++) WriteTransceiverEx (&IRDevices
[i
],(IRDATA
*)&irw
);
1001 void LCDBrightness (int val
)
1006 AdvancedLCD (LCD_DATA
| LCD_BRIGHTNESS
,data
,1);
1009 int AdvancedLCD (byte mode
,byte data
[],int len
)
1014 if (display_bus
!= 0xffff && !IRDevices
[display_bus
].io
.advanced_lcd
) return (0);
1016 memset (&irr
,0,sizeof (IRRAW
));
1018 irr
.command
= HOST_SEND
;
1022 irr
.target_mask
= 0xffff;
1024 memcpy (irr
.data
,data
,len
);
1026 irr
.len
= (byte
)(sizeof (IRRAW
) - CODE_LENRAW
+ len
);
1028 if (display_bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) {
1029 res
= WriteTransceiverEx (&IRDevices
[i
],(IRDATA
*)&irr
);
1031 else res
= WriteTransceiverEx (&IRDevices
[display_bus
],(IRDATA
*)&irr
);
1038 int SendLCD (IRRAW
*ir_data
,int address
)
1042 ir_data
-> command
= HOST_SEND
;
1043 ir_data
-> ir_length
= 0;
1044 if (address
& 0x10000) {
1045 ir_data
->target_mask
= (word
)address
& 0xffff;
1049 ir_data
-> len
= sizeof (IRRAW
) - CODE_LENRAW
+ (byte
)strlen (ir_data
-> data
) + 1;
1050 if (bus
== 0xffff) for (i
=0;i
<device_cnt
;i
++) {
1051 res
= WriteTransceiverEx (&IRDevices
[i
],(IRDATA
*)ir_data
);
1053 else res
= WriteTransceiverEx (&IRDevices
[bus
],(IRDATA
*)ir_data
);
1057 int ReadLearndataLAN (DEVICEINFO
*dev
,byte
*ird
,int timeout
)
1060 byte buf
[sizeof (IRDATA
) + 10];
1061 struct sockaddr_in send_adr
;
1071 res
= WaitForSingleObject (IrtLanEvent
,timeout
);
1072 if (res
== WAIT_TIMEOUT
) {
1074 IRTransLanSend (dev
,(IRDATA
*)buf
);
1075 return (ERR_TIMEOUT
);
1082 FD_SET (irtlan_socket
,&events
);
1083 maxfd
= irtlan_socket
+ 1;
1085 tv
.tv_sec
= timeout
/ 1000;
1086 tv
.tv_usec
= (timeout
% 1000) * 1000;
1088 wait
= select (maxfd
,&events
,NULL
,NULL
,&tv
);
1089 if (!wait
) return (ERR_TIMEOUT
);
1092 i
= sizeof (send_adr
);
1093 res
= recvfrom(irtlan_socket
,buf
,sizeof (IRDATA
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
1094 if (res
<= 0 || res
!= buf
[1] + 1) return (ERR_TIMEOUT
);
1096 } while (buf
[0] != RESULT_LEARN
|| send_adr
.sin_addr
.s_addr
!= dev
->io
.IPAddr
[0].sin_addr
.s_addr
);
1098 memcpy (ird
,buf
+1,buf
[1]);
1105 int LearnNextIREx (IRDATA
*ir_data
,word addr
,word timeout
,word ir_timeout
,byte carrier
)
1112 ir_data
-> address
= 0;
1113 if ((addr
& 0xff) <= 15) ir_data
-> address
|= addr
;
1114 if ((addr
& 0xff) == 'L') ir_data
-> address
|= ADRESS_LOCAL
;
1115 if ((addr
& 0xff) == '*') ir_data
-> address
|= ADRESS_ALL
;
1117 bus
= (addr
>> 8) & (MAX_IR_DEVICES
- 1);
1119 ir_data
-> command
= HOST_LEARNIRQUICK
;
1120 ir_data
-> len
= sizeof (IRDATA
) - CODE_LEN
;
1122 res
= ir_timeout
& 15;
1123 if (strcmp (IRDevices
[bus
].version
+1,"4.04.35") < 0 && res
> 14) res
= 14;
1124 ir_data
-> target_mask
= res
;
1125 ir_data
->target_mask
|= (ir_timeout
/ 2) & (LONG_LEARN_MODE
| RECEIVER_SELECT_MASK
);
1127 res
= WriteTransceiverEx (IRDevices
+ bus
,ir_data
);
1128 if (res
) return (res
);
1130 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) len
= sizeof (IRDATA
);
1133 res
= ReadIRStringEx (IRDevices
+ bus
,&len
,1,timeout
);
1136 CancelLearnEx (IRDevices
+ bus
);
1137 return (ERR_TIMEOUT
);
1141 } while (len
<= sizeof (IRDATA
) - CODE_LEN
);
1143 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) {
1144 if (ReadLearndataLAN (IRDevices
+ bus
,(byte
*)&buffer
,timeout
)) return (ERR_TIMEOUT
);
1147 if (ReadIRStringEx (IRDevices
+ bus
,&buffer
.checksumme
,len
-1,200) != len
-1) return (ERR_TIMEOUT
);
1151 if (TIME_LEN
!= time_len
) ConvertToIRTRANS4 ((IRDATA3
*)&buffer
);
1153 swap_irdata (&buffer
,NULL
);
1155 memcpy (ir_data
-> data
,buffer
.data
,CODE_LEN
);
1156 ir_data
-> ir_length
= buffer
.ir_length
;
1157 ir_data
-> address
= buffer
.address
;
1158 ir_data
-> data
[ir_data
-> ir_length
] = 0;
1159 ir_data
-> time_cnt
= buffer
.time_cnt
;
1164 void ConvertToIRTRANS4 (IRDATA3
*ird
)
1168 memset (&irnew
,0,sizeof (IRDATA
));
1170 memcpy (&irnew
,ird
,21);
1171 memcpy (irnew
.pulse_len
,ird
->pulse_len
,12);
1172 memcpy (&irnew
.time_cnt
,&ird
->time_cnt
,CODE_LEN
+ 3);
1173 irnew
.len
= ird
->len
+ 8;
1174 memcpy (ird
,&irnew
,sizeof (IRDATA
));
1178 void CancelLearnEx (DEVICEINFO
*dev
)
1182 WriteIRStringEx (dev
,(byte
*)&res
,1);
1183 res
= ReadIRStringEx (dev
,st
,1,500);
1190 int LearnIREx (IRDATA
*ir_data
,word addr
,word timeout
,word ir_timeout
,byte carrier
)
1197 ir_data
-> address
= 0;
1198 if ((addr
& 0xff) <= 15) ir_data
-> address
|= addr
;
1199 if ((addr
& 0xff) == 'L') ir_data
-> address
|= ADRESS_LOCAL
;
1200 if ((addr
& 0xff) == '*') ir_data
-> address
|= ADRESS_ALL
;
1202 bus
= (addr
>> 8) & (MAX_IR_DEVICES
- 1);
1204 ir_data
-> command
= HOST_LEARNIR
;
1206 res
= ir_timeout
& 15;
1207 if (strcmp (IRDevices
[bus
].version
+1,"4.04.35") < 0 && res
> 14) res
= 14;
1208 ir_data
-> target_mask
= res
;
1209 ir_data
->target_mask
|= (ir_timeout
/ 2) & (LONG_LEARN_MODE
| RECEIVER_SELECT_MASK
);
1213 res
= WriteTransceiverEx (IRDevices
+ bus
,ir_data
);
1214 if (res
) return (res
);
1216 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) len
= sizeof (IRDATA
);
1219 res
= ReadIRStringEx (IRDevices
+ bus
,&len
,1,timeout
);
1222 CancelLearnEx (IRDevices
+ bus
);
1223 return (ERR_TIMEOUT
);
1227 } while (len
<= sizeof (IRDATA
) - CODE_LEN
);
1229 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) {
1230 if (ReadLearndataLAN (IRDevices
+ bus
,(byte
*)ir_data
,timeout
)) return (ERR_TIMEOUT
);
1233 if (ReadIRStringEx (IRDevices
+ bus
,&ir_data
->checksumme
,len
-1,200) != len
-1) return (ERR_TIMEOUT
);
1236 if (TIME_LEN
!= time_len
) ConvertToIRTRANS4 ((IRDATA3
*)ir_data
);
1238 ir_data
-> data
[ir_data
-> ir_length
] = 0;
1239 swap_irdata (ir_data
,NULL
);
1241 if (carrier
&& ir_data
->transmit_freq
!= 255) ir_data
->transmit_freq
= carrier
;
1242 CorrectIRTimings (ir_data
);
1244 PrintPulseData (ir_data
);
1250 int LearnRepeatIREx (IRDATA
*ir_data
,word addr
,word timeout
,word ir_timeout
,byte carrier
)
1257 ir_data
-> address
= 0;
1258 if ((addr
& 0xff) <= 15) ir_data
-> address
|= addr
;
1259 if ((addr
& 0xff) == 'L') ir_data
-> address
|= ADRESS_LOCAL
;
1260 if ((addr
& 0xff) == '*') ir_data
-> address
|= ADRESS_ALL
;
1262 bus
= (addr
>> 8) & (MAX_IR_DEVICES
- 1);
1264 ir_data
-> command
= HOST_LEARNIRREPEAT
;
1266 res
= ir_timeout
& 15;
1267 if (strcmp (IRDevices
[bus
].version
+1,"4.04.35") < 0 && res
> 14) res
= 14;
1268 ir_data
-> target_mask
= res
;
1269 ir_data
->target_mask
|= (ir_timeout
/ 2) & (LONG_LEARN_MODE
| RECEIVER_SELECT_MASK
);
1273 res
= WriteTransceiverEx (IRDevices
+ bus
,(IRDATA
*)ir_data
);
1274 if (res
) return (res
);
1275 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) len
= sizeof (IRDATA
);
1278 res
= ReadIRStringEx (IRDevices
+ bus
,&len
,1,timeout
);
1281 CancelLearnEx (IRDevices
+ bus
);
1282 return (ERR_TIMEOUT
);
1286 } while (len
<= sizeof (IRDATA
) - CODE_LEN
);
1288 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) {
1289 if (ReadLearndataLAN (IRDevices
+ bus
,(byte
*)ir_data
,timeout
)) return (ERR_TIMEOUT
);
1292 if (ReadIRStringEx (IRDevices
+ bus
,&ir_data
->checksumme
,len
-1,200) != len
-1) return (ERR_TIMEOUT
);
1295 if (TIME_LEN
!= time_len
) ConvertToIRTRANS4 ((IRDATA3
*)ir_data
);
1297 ir_data
-> data
[ir_data
-> ir_length
] = 0;
1299 swap_irdata (ir_data
,NULL
);
1300 if (carrier
&& ir_data
->transmit_freq
!= 255) ir_data
->transmit_freq
= carrier
;
1301 CorrectIRTimings (ir_data
);
1307 int LearnRawIREx (IRRAW
*ir_data
,word addr
,word timeout
,word ir_timeout
,byte carrier
)
1314 ir_data
-> address
= 0;
1315 if ((addr
& 0xff) <= 15) ir_data
-> address
|= addr
;
1316 if ((addr
& 0xff) == 'L') ir_data
-> address
|= ADRESS_LOCAL
;
1317 if ((addr
& 0xff) == '*') ir_data
-> address
|= ADRESS_ALL
;
1319 bus
= (addr
>> 8) & (MAX_IR_DEVICES
- 1);
1321 ir_data
-> command
= HOST_LEARNIRRAW
;
1324 res
= ir_timeout
& 15;
1325 if (strcmp (IRDevices
[bus
].version
+1,"4.04.35") < 0 && res
> 14) res
= 14;
1326 ir_data
-> target_mask
= res
;
1327 ir_data
->target_mask
|= (ir_timeout
/ 2) & (RECEIVER_SELECT_MASK
);
1331 res
= WriteTransceiverEx (IRDevices
+ bus
,(IRDATA
*)ir_data
);
1333 if (res
) return (res
);
1334 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) len
= sizeof (IRDATA
);
1337 res
= ReadIRStringEx (IRDevices
+ bus
,&len
,1,timeout
);
1340 CancelLearnEx (IRDevices
+ bus
);
1341 return (ERR_TIMEOUT
);
1345 } while (len
<= sizeof (IRRAW
) - CODE_LENRAW
);
1347 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) {
1348 if (ReadLearndataLAN (IRDevices
+ bus
,(byte
*)ir_data
,timeout
)) return (ERR_TIMEOUT
);
1351 if (ReadIRStringEx (IRDevices
+ bus
,&ir_data
->checksumme
,len
-1,200) != len
-1) return (ERR_TIMEOUT
);
1353 ir_data
-> data
[ir_data
-> ir_length
] = 0;
1355 swap_irdata ((IRDATA
*)ir_data
,NULL
);
1357 if (carrier
&& ir_data
->transmit_freq
!= 255) ir_data
->transmit_freq
= carrier
;
1358 CorrectIRTimingsRAW (ir_data
);
1363 int LearnRawIRRepeatEx (IRRAW
*ir_data
,word addr
,word timeout
,word ir_timeout
,byte carrier
)
1370 ir_data
-> address
= 0;
1371 if ((addr
& 0xff) <= 15) ir_data
-> address
|= addr
;
1372 if ((addr
& 0xff) == 'L') ir_data
-> address
|= ADRESS_LOCAL
;
1373 if ((addr
& 0xff) == '*') ir_data
-> address
|= ADRESS_ALL
;
1375 bus
= (addr
>> 8) & (MAX_IR_DEVICES
- 1);
1377 ir_data
-> command
= HOST_LEARNIRRAWREPEAT
;
1379 res
= ir_timeout
& 15;
1380 if (strcmp (IRDevices
[bus
].version
+1,"4.04.35") < 0 && res
> 14) res
= 14;
1381 ir_data
-> target_mask
= res
;
1382 ir_data
->target_mask
|= (ir_timeout
/ 2) & (RECEIVER_SELECT_MASK
);
1386 res
= WriteTransceiverEx (IRDevices
+ bus
,(IRDATA
*)ir_data
);
1387 if (res
) return (res
);
1388 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) len
= sizeof (IRDATA
);
1391 res
= ReadIRStringEx (IRDevices
+ bus
,&len
,1,timeout
);
1394 CancelLearnEx (IRDevices
+ bus
);
1395 return (ERR_TIMEOUT
);
1399 } while (len
<= sizeof (IRRAW
) - CODE_LENRAW
);
1401 if (IRDevices
[bus
].io
.if_type
== IF_LAN
) {
1402 if (ReadLearndataLAN (IRDevices
+ bus
,(byte
*)ir_data
,timeout
)) return (ERR_TIMEOUT
);
1405 if (ReadIRStringEx (IRDevices
+ bus
,&ir_data
->checksumme
,len
-1,200) != len
-1) return (ERR_TIMEOUT
);
1407 ir_data
-> data
[ir_data
-> ir_length
] = 0;
1409 swap_irdata ((IRDATA
*)ir_data
,NULL
);
1411 if (carrier
&& ir_data
->transmit_freq
!= 255) ir_data
->transmit_freq
= carrier
;
1412 CorrectIRTimingsRAW (ir_data
);
1417 void CorrectIRTimings (IRDATA
*ir_data
)
1421 if (ir_data
->transmit_freq
>= 48 && ir_data
->transmit_freq
<= 100) {
1422 for (i
=0;i
< ir_data
->time_cnt
;i
++) {
1423 ir_data
->pulse_len
[i
] += 4;
1424 ir_data
->pause_len
[i
] -= 4;
1429 void CorrectIRTimingsRAW (IRRAW
*ir_data
)
1434 if (ir_data
->transmit_freq
>= 48 && ir_data
->transmit_freq
<= 100) {
1436 while (i
< ir_data
-> ir_length
) {
1437 pulse
= ir_data
->data
[i
++];
1438 if (pulse
) ir_data
->data
[i
-1] += 4;
1440 pulse
= ir_data
->data
[i
++] << 8;
1441 pulse
|= ir_data
->data
[i
++];
1443 ir_data
->data
[i
-2] = (pulse
>> 8);
1444 ir_data
->data
[i
-1] = pulse
& 0xff;
1446 pause
= ir_data
->data
[i
++];
1447 if (pause
) ir_data
->data
[i
-1] -= 4;
1449 pause
= ir_data
->data
[i
++] << 8;
1450 pause
|= ir_data
->data
[i
++];
1452 ir_data
->data
[i
-2] = (pause
>> 8);
1453 ir_data
->data
[i
-1] = pause
& 0xff;
1459 void PrintPulseData (IRDATA
*ir_data
)
1464 frq
= ir_data
->transmit_freq
;
1466 if (frq
== 255) frq
= 1000;
1467 else if (frq
& 128) frq
= (frq
& 127) * 4;
1468 for (i
=0;i
< TIME_LEN
;i
++) {
1469 sprintf (msg
,"TIME : %d %4d %4d\n",i
,ir_data
-> pulse_len
[i
] * 8,ir_data
-> pause_len
[i
] * 8);
1470 log_print (msg
,LOG_INFO
);
1472 sprintf (msg
,"T.REP : %4d\n",ir_data
->repeat_pause
);
1473 log_print (msg
,LOG_INFO
);
1474 sprintf (msg
,"REP/MODE: %4d %d\n",ir_data
->ir_repeat
,ir_data
-> mode
);
1475 log_print (msg
,LOG_INFO
);
1476 sprintf (msg
,"FREQ : %4d\n",frq
);
1477 log_print (msg
,LOG_INFO
);
1478 sprintf (msg
,"DATA : %s\n",ir_data
->data
);
1479 log_print (msg
,LOG_INFO
);
1480 sprintf (msg
,"LEN : %4d\n",ir_data
->ir_length
);
1481 log_print (msg
,LOG_INFO
);
1482 sprintf (msg
,"ADR : %d\n",ir_data
-> address
);
1483 log_print (msg
,LOG_INFO
);
1484 sprintf (msg
,"MASK : %d\n",ir_data
-> target_mask
);
1485 log_print (msg
,LOG_INFO
);
1490 void PrintRawData (IRRAW
*ir_data
)
1496 frq
= ir_data
->transmit_freq
;
1498 if (frq
== 255) frq
= 455;
1499 else if (frq
& 128) frq
= (frq
& 127) * 4;
1500 sprintf (msg
,"MODE : %d\n",ir_data
-> mode
& 0xf0);
1501 log_print (msg
,LOG_INFO
);
1502 sprintf (msg
,"Repeat : %d\n",ir_data
-> mode
& 0xf);
1503 log_print (msg
,LOG_INFO
);
1504 sprintf (msg
,"FREQ : %4d\n",frq
);
1505 log_print (msg
,LOG_INFO
);
1506 sprintf (msg
,"LEN : %4d\n",ir_data
->ir_length
);
1507 log_print (msg
,LOG_INFO
);
1508 sprintf (msg
,"ADR : %d\n",ir_data
-> address
);
1509 log_print (msg
,LOG_INFO
);
1513 while (i
< ir_data
-> ir_length
) {
1514 pulse
= ir_data
->data
[i
++];
1516 pulse
= ir_data
->data
[i
++] << 8;
1517 pulse
|= ir_data
->data
[i
++];
1519 pause
= ir_data
->data
[i
++];
1521 pause
= ir_data
->data
[i
++] << 8;
1522 pause
|= ir_data
->data
[i
++];
1524 sprintf (msg
,"%5d %5d\n",pulse
* 8,pause
* 8);
1525 log_print (msg
,LOG_INFO
);
1531 void PrintCommand (IRDATA
*ir_data
)
1535 sprintf (msg
,"DATA : %s\n",ir_data
->data
);
1536 log_print (msg
,LOG_INFO
);
1542 typedef void (*sighandler_t
)(int);
1544 void ShutdownHandler (void)
1546 mode_flag
|= NO_RECONNECT
;
1548 if (!(mode_flag
& NO_CLOCK
)) LCDTimeCommand (LCD_DISPLAYTIME
);
1550 if (pidfile
[0]) unlink (pidfile
);
1558 DEVICEINFO IRDevices
[MAX_IR_DEVICES
];
1561 int InitCommunicationEx (char devicesel
[])
1566 byteorder
= GetByteorder ();
1568 res
= get_devices (devicesel
,0);
1570 if (res
) return (res
);
1573 if (device_cnt
) time_len
= IRDevices
[0].io
.time_len
;
1574 else time_len
= TIME_LEN
;
1576 for (i
=0;i
<device_cnt
;i
++) {
1577 sprintf (msg
,"Name : %s\n",IRDevices
[i
].name
);
1578 log_print (msg
,LOG_INFO
);
1579 sprintf (msg
,"Version: %s\n",IRDevices
[i
].version
);
1580 log_print (msg
,LOG_INFO
);
1581 sprintf (msg
,"FW SNo : %d\n",IRDevices
[i
].fw_serno
);
1582 log_print (msg
,LOG_INFO
);
1583 sprintf (msg
,"Capab : %s\n",IRDevices
[i
].cap_string
);
1584 log_print (msg
,LOG_INFO
);
1585 sprintf (msg
,"FW Cap : %d\n",IRDevices
[i
].fw_capabilities
);
1586 log_print (msg
,LOG_INFO
);
1587 sprintf (msg
,"USB SNo: %s\n",IRDevices
[i
].usb_serno
);
1588 log_print (msg
,LOG_INFO
);
1589 sprintf (msg
,"Node : %s\n\n",IRDevices
[i
].device_node
);
1590 log_print (msg
,LOG_INFO
);
1593 for (i
=0;i
<device_cnt
;i
++) {
1594 raw_repeat
&= IRDevices
[i
].io
.raw_repeat
;
1595 if (IRDevices
[i
].io
.time_len
!= time_len
) {
1596 sprintf (msg
,"Devices < Version 4.xx.xx and Devices > 4.xx.xx can not be mixed.\nExiting now\n\n");
1597 log_print (msg
,LOG_FATAL
);
1602 if (new_lcd_flag
) display_bus
= 0xffff;
1604 for (i
=0;i
< device_cnt
;i
++) if (IRDevices
[i
].version
[0] == 'D' || (IRDevices
[i
].fw_capabilities
& FN_DISPMASK
)) {
1610 SetConsoleCtrlHandler (ShutdownHandler
,TRUE
);
1614 signal (SIGINT
,(sighandler_t
)ShutdownHandler
);
1623 BOOL WINAPI
ShutdownHandler (DWORD type
)
1625 mode_flag
|= NO_RECONNECT
;
1627 if (!(mode_flag
& NO_CLOCK
)) LCDTimeCommand (LCD_DISPLAYTIME
);
1630 if (pidfile
[0]) _unlink (pidfile
);
1635 int GetAvailableDataEx (DEVICEINFO
*dev
)
1637 if (dev
->io
.if_type
== IF_USB
) return GetUSBAvailableEx (dev
);
1638 if (dev
->io
.if_type
== IF_RS232
|| dev
->io
.if_type
== IF_SERUSB
) return GetSerialAvailableEx (dev
);
1645 int ReadInstantReceive (DEVICEINFO
*dev
,byte pnt
[],int len
)
1650 if (dev
->io
.if_type
== IF_USB
) to
= 5;
1658 cnt
= ReadIRStringEx (dev
,pnt
,len
,to
);
1660 if (!cnt
) return (0);
1662 if (dev
->io
.inst_receive_mode
& 1) {
1664 cnt
+= ReadIRStringEx (dev
,pnt
+cnt
,len
-cnt
,100);
1674 extern SOCKET irt_bcast
[32];
1675 extern int if_count
;
1680 int get_devices (char sel
[],byte testflag
) // Errflag = Continue bei USB Error
1684 int res
,i
,p
,q
,autoflag
= 0;
1688 struct sockaddr_in target
,send_adr
;
1698 WORD wVersionRequired
;
1700 enum FT_STATUS stat
;
1702 char buf_value
[256][64];
1710 st
[strlen (st
) + 1] = 0;
1714 printf ("Probing IRTrans Devices ..");
1722 while (st
[p
] && sel
[p
] != ' ' && st
[p
] != ';') p
++; st
[p
] = 0;
1724 if ((!strncmp (st
+ q
,"usb",3) || !strncmp (st
+ q
,"USB",3)) && !autoflag
) {
1725 res
= LoadUSBLibrary ();
1731 return (ERR_OPENUSB
);
1735 for (i
=0;i
<256;i
++) buf_pnt
[i
] = buf_value
[i
];
1738 stat
= F_ListDevices(buf_pnt
,&numDevs
,FT_LIST_ALL
|FT_OPEN_BY_SERIAL_NUMBER
);
1740 if (FT_SUCCESS(stat
)) {
1741 for (i
=0;i
<numDevs
&& device_cnt
< MAX_IR_DEVICES
;i
++) get_detail_deviceinfo (buf_pnt
[i
],"USB",IF_USB
);
1749 return (ERR_OPENUSB
);
1751 if (st
[q
+ 3] == ':') sort_ir_devices (st
+ q
+ 4);
1753 else if (!strncmp (st
+ q
,"com",3) || !strncmp (st
+ q
,"COM",3)) {
1754 res
= get_detail_deviceinfo ("",st
+q
,IF_RS232
);
1756 else if (!strcmp (st
+ q
,"dummy")) res
= 0;
1759 //LINUX Autofind USB devices
1760 if ((!strncmp (st
+ q
,"usb",3) || !strncmp (st
+ q
,"USB",3)) && !autoflag
) {
1763 for (i
=0;i
< 16;i
++) {
1764 sprintf (dst
,"/dev/usb/ttyUSB%d",i
);
1765 if (get_detail_deviceinfo ("",dst
,IF_USB
)) {
1766 sprintf (dst
,"/dev/tts/USB%d",i
);
1767 if (get_detail_deviceinfo ("",dst
,IF_USB
)) {
1768 sprintf (dst
,"/dev/usb/tts/%d",i
);
1769 get_detail_deviceinfo ("",dst
,IF_USB
);
1775 else if ((!strncmp (st
+ q
,"/dev/usb/tty",12) || !strncmp (st
+ q
,"/dev/ttyUSB",11) || !strncmp (st
+ q
,"/dev/usb/tts",12) ||
1776 !strncmp (st
+ q
,"/dev/ttyusb",11) || !strncmp (st
+ q
,"/dev/tts/USB",12)) && !autoflag
) {
1777 if (st
[q
+ strlen (st
+q
) - 1] == ']') {
1781 i
= q
+ strlen (st
+q
) - 1;
1782 while (i
>= q
&& st
[i
] != '[') i
--;
1783 if (st
[i
] != '[') return (0);
1786 while (st
[i
] >= '0' && st
[i
] <= '9') i
++;
1790 memset (base
,0,sizeof (base
));
1791 memcpy (base
,st
+q
,j
-q
-1);
1794 for (i
=beg
;i
<=end
;i
++) {
1795 sprintf (dst
,"%s%d",base
,i
);
1796 get_detail_deviceinfo ("",dst
,IF_USB
);
1800 else res
= get_detail_deviceinfo ("",st
+q
,IF_USB
);
1802 else if (!strncmp (st
+ q
,"/dev/tty",8)) res
= get_detail_deviceinfo ("",st
+q
,IF_RS232
);
1803 else if (!strcmp (st
+ q
,"dummy")) res
= 0;
1805 else if (st
[q
] >= '1' && st
[q
] <= '9') {
1807 dev
= IRDevices
+ device_cnt
;
1808 strcpy (dev
->device_node
,st
+q
);
1809 dev
->io
.if_type
= IF_LAN
;
1810 dev
->usb_serno
[0] = 0;
1812 dev
->io
.comport
= NULL
;
1813 dev
->io
.event
= NULL
;
1817 dev
->io
.comport
= (int)NULL
;
1818 dev
->io
.event
= (int)NULL
;
1821 memset (&dev
->io
.IPAddr
,0,sizeof (dev
->io
.IPAddr
));
1822 dev
->io
.IPAddr
[0].sin_family
= AF_INET
;
1824 adr
= inet_addr(dev
->device_node
);
1825 // Hier Erweiterung auf Devicenamen
1827 haddr = gethostbyaddr ((char *)&adr,4,AF_INET);
1828 if (haddr == NULL) {
1829 sprintf (msg,"\nCan not open device %s.\nAborting ...\n\n",st+q);
1830 log_print (msg,LOG_FATAL);
1834 dev
->io
.IPAddr
[0].sin_addr
.s_addr
= adr
;
1835 dev
->io
.IPAddr
[0].sin_port
= htons ((word
)IRTRANS_PORT
);
1837 res
= GetTransceiverVersionEx (dev
);
1838 if (res
) return (ERR_OPEN
);
1842 else if ((!strncmp (st
+ q
,"lan",3) || !strncmp (st
+ q
,"LAN",3))) {
1843 // Find LAN Devices ...
1847 wVersionRequired
= MAKEWORD(2,2);
1848 err
= WSAStartup(wVersionRequired
, &wsaData
);
1849 if (err
!= 0) exit(1);
1851 OpenIRTransLANSocket ();
1853 OpenIRTransBroadcastSockets ();
1857 memset (&irdlan
,0,sizeof (irdlan
));
1858 irdlan
.netcommand
= COMMAND_LAN
;
1859 irdlan
.ir_data
.command
= HOST_VERSION
;
1860 irdlan
.ir_data
.len
= 3;
1861 irdlan
.ir_data
.checksumme
= get_checksumme (&irdlan
.ir_data
);
1863 memset (&target
,0,sizeof (struct sockaddr
));
1864 target
.sin_family
= AF_INET
;
1865 target
.sin_addr
.s_addr
= INADDR_BROADCAST
;
1866 target
.sin_port
= htons ((word
)IRTRANS_PORT
);
1869 for (i
=0;i
< if_count
;i
++) {
1870 res
= send (irt_bcast
[i
],(char *)&irdlan
,irdlan
.ir_data
.len
+ sizeof (IRDATA_LAN
) - sizeof (IRDATA
),MSG_NOSIGNAL
);
1873 if (res
= connect (irtlan_outbound
,(struct sockaddr
*)&target
,sizeof (struct sockaddr_in
)) < 0) return (ERR_BINDSOCKET
);
1874 res
= send (irtlan_outbound
,(char *)&irdlan
,irdlan
.ir_data
.len
+ sizeof (IRDATA_LAN
) - sizeof (IRDATA
),MSG_NOSIGNAL
);
1878 IrtLanEvent
= WSACreateEvent ();
1879 WSAEventSelect (irtlan_socket
, IrtLanEvent
,FD_READ
);
1883 res
= WaitForSingleObject (IrtLanEvent
,1000);
1884 if (res
== WAIT_TIMEOUT
) break;
1885 ResetEvent (IrtLanEvent
);
1892 FD_SET (irtlan_socket
,&events
);
1893 maxfd
= irtlan_socket
+ 1;
1898 wait
= select (maxfd
,&events
,NULL
,NULL
,&tv
);
1902 i
= sizeof (send_adr
);
1903 res
= recvfrom(irtlan_socket
,(byte
*)&ver
,sizeof (GETVERSION_LAN
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
1904 if (res
== ver
.len
+ 1 && ver
.netcommand
== RESULT_GETVERSION
) {
1905 dev
= IRDevices
+ device_cnt
;
1907 dev
->io
.if_type
= IF_LAN
;
1908 strcpy (dev
->name
,"IRTrans Ethernet");
1909 memcpy (dev
->version
,ver
.ir_version
,8);
1910 memcpy (dev
->lan_version
,ver
.lan_version
,8);
1911 dev
->fw_capabilities
= ver
.ir_capabilities
;
1912 dev
->fw_serno
= ver
.ir_serno
;
1913 memcpy (dev
->mac_adr
,ver
.mac_adr
,6);
1914 dev
->cap_string
[0] = 0;
1917 dev
->io
.comport
= NULL
;
1918 dev
->io
.event
= NULL
;
1922 dev
->io
.comport
= (int)NULL
;
1923 dev
->io
.event
= (int)NULL
;
1926 memset (&dev
->io
.IPAddr
,0,sizeof (dev
->io
.IPAddr
));
1927 dev
->io
.IPAddr
[0].sin_family
= AF_INET
;
1929 dev
->io
.IPAddr
[0].sin_addr
.s_addr
= send_adr
.sin_addr
.s_addr
;
1930 dev
->io
.IPAddr
[0].sin_port
= htons ((word
)IRTRANS_PORT
);
1932 DecodeFunctions (dev
);
1939 else if (st
[q
] == ':') sort_ir_devices (st
+ q
+ 1);
1940 if (res
&& !testflag
) {
1949 sprintf (st
,"No IRTrans Devices found.\nAborting ...\n\n");
1950 log_print (st
,LOG_FATAL
);
1954 for (i
=0;i
<device_cnt
;i
++) {
1955 sprintf (st
,"Name : %s\n",IRDevices
[i
].name
);
1956 log_print (st
,LOG_INFO
);
1957 sprintf (st
,"Version: %s\n",IRDevices
[i
].version
);
1958 log_print (st
,LOG_INFO
);
1959 sprintf (st
,"FW SNo : %d\n",IRDevices
[i
].fw_serno
);
1960 log_print (st
,LOG_INFO
);
1961 sprintf (st
,"Capab : %s\n",IRDevices
[i
].cap_string
);
1962 log_print (st
,LOG_INFO
);
1963 sprintf (st
,"FW Cap : %d\n",IRDevices
[i
].fw_capabilities
);
1964 log_print (st
,LOG_INFO
);
1965 if (IRDevices
[i
].io
.if_type
== IF_USB
) {
1966 sprintf (st
,"USB SNo: %s\n",IRDevices
[i
].usb_serno
);
1967 log_print (st
,LOG_INFO
);
1968 sprintf (st
,"Node : %s\n\n",IRDevices
[i
].device_node
);
1969 log_print (st
,LOG_INFO
);
1971 if (IRDevices
[i
].io
.if_type
== IF_LAN
) {
1972 sprintf (st
,"LAN Ver: %s\n",IRDevices
[i
].lan_version
);
1973 log_print (st
,LOG_INFO
);
1974 sprintf (st
,"Mac Adr: %s\n",IRDevices
[i
].usb_serno
);
1975 log_print (st
,LOG_INFO
);
1976 sprintf (st
,"IP Adr : %s\n\n",IRDevices
[i
].device_node
);
1977 log_print (st
,LOG_INFO
);
1986 void sort_ir_devices (char selstring
[])
1988 int i
,cnt
,start
,p
,q
;
1989 DEVICEINFO di
[MAX_IR_DEVICES
];
1991 memcpy (di
,IRDevices
,sizeof (DEVICEINFO
) * MAX_IR_DEVICES
);
1994 while ((di
[i
].io
.if_type
== IF_RS232
|| di
[i
].io
.if_type
== IF_SERUSB
) && i
< device_cnt
) i
++;
1997 while (selstring
[p
]) {
1998 while (selstring
[p
] && selstring
[p
] != ' ' && selstring
[p
] != ',') p
++;
2000 for (i
= start
;i
< device_cnt
;i
++) {
2001 if (!strcmp (selstring
+q
,di
[i
].usb_serno
) || (atoi (selstring
+q
) && (word
)atoi (selstring
+q
) == di
[i
].fw_serno
)) {
2002 memcpy(&IRDevices
[cnt
++],&di
[i
],sizeof (DEVICEINFO
));
2011 int get_detail_deviceinfo (char serno
[],char devnode
[],byte if_type
)
2016 char SerialNumber
[16];
2017 char Description
[64];
2024 dev
= IRDevices
+ device_cnt
;
2025 strcpy (dev
->device_node
,devnode
);
2026 dev
->io
.if_type
= if_type
;
2027 if (if_type
== IF_USB
) {
2028 if (memcmp (serno
,"MM",2) && memcmp (serno
,"IR",2)) return (ERR_OPEN
);
2031 strcpy (dev
->usb_serno
,serno
);
2032 stat
= F_OpenEx(dev
->usb_serno
,FT_OPEN_BY_SERIAL_NUMBER
,&(dev
->io
.usbport
));
2034 if (!FT_SUCCESS(stat
)) return (ERR_OPEN
);
2036 ftStatus
= F_GetDeviceInfo(dev
->io
.usbport
,&ftDevice
,&deviceID
,SerialNumber
,Description
,NULL
);
2038 if (!strcmp (Description
,"IRTrans USB A")) return (ERR_OPEN
);
2042 if (if_type
== IF_SERUSB
) res
= OpenSerialPortEx (devnode
,&(dev
->io
.comport
),250);
2043 else res
= OpenSerialPortEx (devnode
,&(dev
->io
.comport
),1000);
2044 if (res
) return (ERR_OPEN
);
2046 dev
->io
.event
= CreateEvent (NULL
,TRUE
,FALSE
,NULL
);
2050 dev
= IRDevices
+ device_cnt
;
2051 dev
->usb_serno
[0] = 0;
2052 strcpy (dev
->device_node
,devnode
);
2053 dev
->io
.if_type
= if_type
;
2055 res
= OpenSerialPortEx (devnode
,&(dev
->io
.comport
),0);
2056 if (res
) return (ERR_OPEN
);
2059 res
= GetTransceiverVersionEx (dev
);
2062 if (dev
->io
.if_type
== IF_USB
) F_Close (dev
->io
.usbport
);
2063 CloseHandle (dev
->io
.comport
);
2065 close (dev
->io
.comport
);
2075 int GetTransceiverVersionEx (DEVICEINFO
*dev
)
2081 struct sockaddr_in send_adr
;
2089 ir
.command
= HOST_VERSION
;
2094 dev
->version
[0] = 0;
2095 res
= WriteTransceiverEx (dev
,&ir
);
2097 dev
->version
[8] = 0;
2099 if (dev
->io
.if_type
== IF_LAN
) {
2100 dev
->usb_serno
[0] = 0;
2103 res
= WaitForSingleObject (IrtLanEvent
,2000);
2104 if (res
== WAIT_TIMEOUT
) {
2110 FD_SET (irtlan_socket
,&events
);
2111 maxfd
= irtlan_socket
+ 1;
2116 wait
= select (maxfd
,&events
,NULL
,NULL
,&tv
);
2119 if (!(mode_flag
& NO_INIT_LAN
) || dev
== IRDevices
) return (ERR_VERSION
);
2120 memcpy (dev
->version
,IRDevices
[0].version
,8);
2121 memcpy (dev
->lan_version
,IRDevices
[0].lan_version
,8);
2122 dev
->fw_capabilities
= IRDevices
[0].fw_capabilities
;
2124 memset (dev
->mac_adr
,0,6);
2128 i
= sizeof (send_adr
);
2129 res
= recvfrom(irtlan_socket
,(byte
*)&ver
,sizeof (GETVERSION_LAN
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
2130 if (res
<= 0 || res
!= ver
.len
+ 1 || ver
.netcommand
!= RESULT_GETVERSION
) {
2131 if (!(mode_flag
& NO_INIT_LAN
) || dev
== IRDevices
) return (ERR_VERSION
);
2132 memcpy (dev
->version
,IRDevices
[0].version
,8);
2133 memcpy (dev
->lan_version
,IRDevices
[0].lan_version
,8);
2134 dev
->fw_capabilities
= IRDevices
[0].fw_capabilities
;
2136 memset (dev
->mac_adr
,0,6);
2139 memcpy (dev
->version
,ver
.ir_version
,8);
2140 memcpy (dev
->lan_version
,ver
.lan_version
,8);
2141 dev
->fw_capabilities
= ver
.ir_capabilities
;
2142 dev
->fw_serno
= ver
.ir_serno
;
2143 memcpy (dev
->mac_adr
,ver
.mac_adr
,6);
2149 res
= ReadIRStringEx (dev
,dev
->version
,8,500);
2150 if (res
!= 8) return (ERR_READVERSION
);
2152 if (strcmp (dev
->version
+1,MINIMUM_SW_VERSION
) < 0) return (ERR_VERSION
);
2154 if (strcmp (dev
->version
+1,"2.24.01") >= 0) {
2155 res
= ReadIRStringEx (dev
,data
,8,500);
2156 if (res
!= 8) return (ERR_READVERSION
);
2158 if (strcmp (dev
->version
+1,"4.04.01") >= 0) {
2159 memcpy (&dev
->fw_capabilities
,data
,4);
2160 swap_int (&dev
->fw_capabilities
);
2161 memcpy (&dev
->fw_serno
,data
+ 4,4);
2162 swap_int (&dev
->fw_serno
);
2165 memcpy (&dev
->fw_capabilities
,data
+ 1,2);
2166 swap_int (&dev
->fw_capabilities
);
2167 memcpy (&dev
->fw_serno
,data
+ 3,4);
2168 swap_int (&dev
->fw_serno
);
2170 if (dev
->fw_serno
== 2802 || dev
->fw_serno
== 0x11223344) dev
->fw_serno
= 0;
2175 DecodeFunctions (dev
);
2180 void DecodeFunctions (DEVICEINFO
*dev
)
2182 dev
->io
.raw_repeat
= 0;
2183 dev
->io
.ext_carrier
= 0;
2184 dev
->io
.inst_receive_mode
= 0;
2185 dev
->io
.advanced_lcd
= 0;
2186 if (strcmp (dev
->version
+1,"4.00.00") >= 0) dev
->io
.time_len
= 8; // Version 4.0 with TIME_LEN = 8
2187 else dev
->io
.time_len
= 6;
2188 if (strcmp (dev
->version
+1,"4.02.00") >= 0) dev
->io
.raw_repeat
= 1; // Version 4.2 with RAW_REPEAT feature
2189 if (strcmp (dev
->version
+1,"4.03.00") >= 0) dev
->io
.ext_carrier
= 1; // Version 4.3 mit erweitertem Carrier
2190 if (strcmp (dev
->version
+1,"4.04.06") >= 0) dev
->io
.inst_receive_mode
|= 1; // Version 4.4.6 mit geändertem Instant Rcv
2191 if (strcmp (dev
->version
+1,"4.04.07") >= 0 &&
2192 (dev
->version
[0] == 'D')) dev
->io
.inst_receive_mode
|= 2; // Version 4.4.7 mit geändertem Instant Rcv
2193 if (strcmp (dev
->version
+1,"4.04.17") >= 0 &&
2194 (dev
->version
[0] == 'D')) dev
->io
.advanced_lcd
|= 1; // Version 4.4.17 mit zusätzlichen LCD Funktionen
2195 if (strcmp (dev
->version
+1,"4.04.23") >= 0 &&
2196 (dev
->version
[0] == 'D')) dev
->io
.advanced_lcd
|= 2; // Version 4.4.23 mit neuem LCD Protokoll
2198 if (dev
->version
[0] == 'F') dev
->io
.advanced_lcd
= 7; // Uneed V2
2200 if (dev
->fw_capabilities
& FN_DEBOUNCE
) dev
->io
.inst_receive_mode
|= 2;
2202 if (strcmp (dev
->version
+1,"5.05.15") >= 0 && (dev
->io
.if_type
== IF_USB
|| (
2203 dev
->io
.if_type
== IF_SERUSB
&& (dev
->version
[0] == 'U' || dev
->version
[0] == 'X' || dev
->version
[0] == 'D')))) dev
->io
.io_seq_mode
= 1; // IO Sequence Mode
2205 switch (dev
->version
[0]) {
2207 strcpy (dev
->name
,"IRTrans Translator");
2210 strcpy (dev
->name
,"IRTrans USB");
2213 strcpy (dev
->name
,"IRTrans USB 455kHz");
2216 strcpy (dev
->name
,"IRTrans RS232");
2219 strcpy (dev
->name
,"IRTrans RS232 455kHz");
2222 strcpy (dev
->name
,"IRTrans LAN");
2225 strcpy (dev
->name
,"IRTrans LAN 455kHz");
2228 dev
->cap_string
[0] = 0;
2230 if (dev
->fw_capabilities
& FN_POWERON
) strcat (dev
->cap_string
,"Power On; ");
2231 if (dev
->fw_capabilities
& FN_SOFTID
) strcat (dev
->cap_string
,"Soft ID; ");
2232 if (dev
->fw_capabilities
& FN_DUALSND
) strcat (dev
->cap_string
,"Dual Transmitter Drivers; ");
2233 if (dev
->fw_capabilities
& FN_IRDB
) strcat (dev
->cap_string
,"IR Database; ");
2235 if (dev
->io
.if_type
== IF_LAN
) {
2236 sprintf (dev
->usb_serno
,"%02x-%02x-%02x-%02x-%02x-%02x",dev
->mac_adr
[0],dev
->mac_adr
[1],dev
->mac_adr
[2],dev
->mac_adr
[3],dev
->mac_adr
[4],dev
->mac_adr
[5]);
2237 sprintf (dev
->device_node
,"%d.%d.%d.%d",dev
->io
.IPAddr
[0].sin_addr
.s_addr
& 0xff,(dev
->io
.IPAddr
[0].sin_addr
.s_addr
>> 8) & 0xff,(dev
->io
.IPAddr
[0].sin_addr
.s_addr
>> 16) & 0xff,(dev
->io
.IPAddr
[0].sin_addr
.s_addr
>> 24) & 0xff);
2242 void FlushIoEx (DEVICEINFO
*dev
)
2245 if (dev
->io
.if_type
== IF_USB
) FlushUSBEx (dev
->io
.usbport
);
2246 else FlushComEx (dev
->io
.comport
);
2250 FlushComEx (dev
->io
.comport
);
2255 void Hexdump_File (IRDATA
*ird
)
2261 for (i
=0;i
< ird
->len
;i
++) {
2262 fprintf (hexfp
,"0x%02x ",pnt
[i
]);
2263 if (((i
+1)%16) == 0) fprintf (hexfp
,"\n");
2265 fprintf (hexfp
,"\n\n");
2270 void Hexdump_IO (IRDATA
*ird
)
2273 char st
[2048],nm
[100];
2276 strcpy (st
,"IODUMP: ");
2278 for (i
=0;i
< ird
->len
;i
++) {
2279 sprintf (nm
,"0x%x ",pnt
[i
]);
2284 log_print (st
,LOG_DEBUG
);
2287 void Hexdump_Medialon (IRDATA
*ird
)
2290 char st
[2048],nm
[100];
2295 for (i
=0;i
< ird
->len
;i
++) {
2296 sprintf (nm
,"!%02x",pnt
[i
]);
2301 log_print (st
,LOG_DEBUG
);
2306 int WriteTransceiverEx (DEVICEINFO
*dev
,IRDATA
*src
)
2309 int count
= 0,max
,timeo
;
2311 byte buffer
[1024],sbuffer
[1024];
2313 dev
->io
.io_sequence
++;
2315 if (dev
->version
[0] == 0 && src
->command
!= HOST_VERSION
) return (ERR_WRONGBUS
);
2317 swap_irdata (src
,&send
);
2319 if (time_len
!= TIME_LEN
&& ((src
->command
== HOST_SEND
&& !(src
->mode
& NON_IRMODE
)) || src
->command
== HOST_LEARNIRQUICK
)) {
2320 if (src
->mode
& RAW_DATA
) {
2321 if (src
->ir_length
> OLD_LENRAW
) return (ERR_LONGRAW
);
2324 if (src
->time_cnt
> 6) return (ERR_LONGDATA
);
2325 ConvertToIRTRANS3 (&send
);
2329 if (dev
->io
.io_seq_mode
|| (src
->command
== HOST_VERSION
&& (dev
->io
.if_type
== IF_USB
|| dev
->io
.if_type
== IF_SERUSB
))) {
2330 if (dev
->version
[0]) max
= 10;
2335 if (dev
->version
[0]) max
= 5;
2340 send
.checksumme
= get_checksumme (&send
);
2342 if (mode_flag
& HEXDUMP
) Hexdump_IO (&send
);
2343 if (mode_flag
& MEDIALON
) Hexdump_Medialon (&send
);
2344 if (hexflag
) Hexdump_File (&send
);
2346 if (dev
->io
.if_type
== IF_LAN
) return (IRTransLanSend (dev
,&send
));
2348 if (dev
->io
.io_seq_mode
|| (src
->command
== HOST_VERSION
&& (dev
->io
.if_type
== IF_USB
|| dev
->io
.if_type
== IF_SERUSB
))) {
2349 memcpy (sbuffer
,&send
,send
.len
);
2350 sbuffer
[send
.len
] = dev
->io
.io_sequence
;
2351 res
= WriteIRStringEx (dev
,sbuffer
,send
.len
+ 1);
2352 if (dev
->version
[0]) max
= 10;
2356 if (dev
->version
[0]) max
= 10;
2358 res
= WriteIRStringEx (dev
,(byte
*)&send
,send
.len
);
2361 if (res
) return (ERR_TIMEOUT
);
2364 res
= ReadIRStringEx (dev
,buffer
,1,(word
)timeo
);
2366 if (res
!= 1 || *buffer
!= 'O') {
2367 sprintf (sbuffer
,"IRTRans Send status: %d - %d\n",res
,*buffer
);
2368 log_print (sbuffer
,LOG_DEBUG
);
2370 res
= ReadIRStringEx (dev
,buffer
+1,250,20);
2372 if (*buffer
== 'R') return (ERR_RESEND
);
2378 if (dev
->io
.receive_buffer_cnt
== 4) {
2380 while (buffer
[pos
+i
] && buffer
[pos
+i
] != 'E' && buffer
[pos
+i
] != 'O' && buffer
[pos
+i
] != 'E' && (pos
+i
) < res
) i
++;
2383 dev
->io
.receive_buffer
[dev
->io
.receive_buffer_cnt
][0] = buffer
[pos
];
2385 while (buffer
[pos
+i
] && buffer
[pos
+i
] != 'E' && buffer
[pos
+i
] != 'O' && buffer
[pos
+i
] != 'E' && (pos
+i
) < res
) {
2386 dev
->io
.receive_buffer
[dev
->io
.receive_buffer_cnt
][i
] = buffer
[pos
+i
];
2389 dev
->io
.receive_buffer
[dev
->io
.receive_buffer_cnt
][i
] = 0;
2390 dev
->io
.receive_cnt
[dev
->io
.receive_buffer_cnt
] = i
;
2393 dev
->io
.receive_buffer_cnt
++;
2394 if (dev
->io
.inst_receive_mode
& 1 && buffer
[pos
] == 0) pos
++;
2396 if (buffer
[res
-1] == 'O') return (0);
2397 res
= ReadIRStringEx (dev
,buffer
,1,500);
2398 if (*buffer
== 'O') return (0);
2404 if (count
> 5) msSleep (timeo
* 2);
2407 } while (res
== 0 && count
< max
&& !(mode_flag
& NO_RECONNECT
));
2409 sprintf (sbuffer
,"IRTRans Send Done: %d\n",count
);
2410 log_print (sbuffer
,LOG_DEBUG
);
2412 if (count
== 10) return (ERR_TIMEOUT
);
2417 void ConvertToIRTRANS3 (IRDATA
*ird
)
2421 memcpy (&irold
,ird
,21);
2422 memcpy (irold
.pulse_len
,ird
->pulse_len
,12);
2423 memcpy (&irold
.time_cnt
,&ird
->time_cnt
,CODE_LEN
+ 3);
2424 irold
.len
= ird
->len
- 8;
2425 memcpy (ird
,&irold
,irold
.len
);
2429 void SwapStatusbuffer (STATUS_BUFFER
*sb
)
2433 if (!byteorder
) return;
2435 for (i
=0;i
<16;i
++) {
2436 swap_word (&sb
->stat
[i
].send_mask
);
2437 swap_int ((int32_t *)&sb
->stat
[i
].capabilities
);
2442 void swap_irdata (IRDATA
*src
,IRDATA
*tar
)
2448 memcpy (tar
,src
,sizeof (IRDATA
));
2453 if (!byteorder
) return;
2455 swap_word (&ir
->target_mask
);
2457 if (!(ir
-> mode
& (RAW_DATA
| LCD_DATA
))) {
2459 for (i
=0;i
< TIME_LEN
;i
++) {
2460 swap_word (ir
->pause_len
+ i
);
2461 swap_word (ir
->pulse_len
+ i
);
2467 void swap_word (word
*pnt
)
2471 if (!byteorder
) return;
2480 void swap_int (int32_t *pnt
)
2484 if (!byteorder
) return;
2497 byte
get_checksumme (IRDATA
*ir
)
2501 while (i
< ir
->len
) cs
+= ((byte
*)ir
)[i
++];
2518 int WriteIRStringEx (DEVICEINFO
*dev
,byte pnt
[],int len
)
2521 if (dev
->io
.if_type
== IF_USB
) {
2522 WriteUSBStringEx (dev
,pnt
,len
);
2526 return (WriteSerialStringEx (dev
,pnt
,len
));
2530 return WriteSerialStringEx (dev
,pnt
,len
);
2534 int ReadIRStringEx (DEVICEINFO
*dev
,byte pnt
[],int len
,word timeout
)
2538 if (dev
->io
.if_type
== IF_USB
) return (ReadUSBStringEx (dev
,pnt
,len
,timeout
));
2539 else return (ReadSerialStringEx (dev
,pnt
,len
,timeout
));
2543 return (ReadSerialStringEx (dev
,pnt
,len
,timeout
));
2547 void ConvertLCDCharset (byte
*pnt
)
2550 if (new_lcd_flag
) t
= 1;
2552 for (i
=0;i
< 200;i
++) pnt
[i
] = DispConvTable
[1][pnt
[i
]];
2556 void InitConversionTables ()
2562 memset (DispConvTable
[num
],' ',256); // Initialize Table
2564 for (i
=0;i
<= 127;i
++) DispConvTable
[num
][i
] = i
; // Set lower 7 Bits
2566 DispConvTable
[num
][192] = 65;
2567 DispConvTable
[num
][193] = 65;
2568 DispConvTable
[num
][194] = 65;
2569 DispConvTable
[num
][195] = 65;
2570 DispConvTable
[num
][197] = 0x81;
2571 DispConvTable
[num
][198] = 0x90;
2572 DispConvTable
[num
][199] = 0x99;
2573 DispConvTable
[num
][200] = 69;
2574 DispConvTable
[num
][201] = 69;
2575 DispConvTable
[num
][202] = 69;
2576 DispConvTable
[num
][203] = 69;
2577 DispConvTable
[num
][204] = 73;
2578 DispConvTable
[num
][205] = 73;
2579 DispConvTable
[num
][206] = 73;
2580 DispConvTable
[num
][207] = 73;
2581 DispConvTable
[num
][208] = 68;
2582 DispConvTable
[num
][209] = 78;
2583 DispConvTable
[num
][210] = 79;
2584 DispConvTable
[num
][211] = 79;
2585 DispConvTable
[num
][212] = 79;
2586 DispConvTable
[num
][213] = 79;
2587 DispConvTable
[num
][216] = 0x88;
2588 DispConvTable
[num
][217] = 85;
2589 DispConvTable
[num
][218] = 85;
2590 DispConvTable
[num
][219] = 85;
2591 DispConvTable
[num
][221] = 89;
2592 DispConvTable
[num
][224] = 97;
2593 DispConvTable
[num
][225] = 0x83;
2594 DispConvTable
[num
][226] = 97;
2595 DispConvTable
[num
][227] = 97;
2596 DispConvTable
[num
][229] = 0x84;
2597 DispConvTable
[num
][230] = 0x91;
2598 DispConvTable
[num
][231] = 0x99;
2599 DispConvTable
[num
][232] = 101;
2600 DispConvTable
[num
][233] = 101;
2601 DispConvTable
[num
][234] = 101;
2602 DispConvTable
[num
][235] = 101;
2603 DispConvTable
[num
][236] = 105;
2604 DispConvTable
[num
][237] = 105;
2605 DispConvTable
[num
][238] = 105;
2606 DispConvTable
[num
][239] = 105;
2607 DispConvTable
[num
][241] = 0xee;
2608 DispConvTable
[num
][242] = 111;
2609 DispConvTable
[num
][243] = 111;
2610 DispConvTable
[num
][244] = 111;
2611 DispConvTable
[num
][245] = 111;
2612 DispConvTable
[num
][248] = 0x88;
2613 DispConvTable
[num
][249] = 117;
2614 DispConvTable
[num
][250] = 117;
2615 DispConvTable
[num
][251] = 117;
2616 DispConvTable
[num
][253] = 121;
2617 DispConvTable
[num
][255] = 121;
2621 DispConvTable
[num
][0xC4] = 0x80; // Set Conversion (Upper 8 Bits)
2622 DispConvTable
[num
][0xC5] = 0x82;
2623 DispConvTable
[num
][0xE1] = 0x83;
2624 DispConvTable
[num
][0xE5] = 0x84;
2625 DispConvTable
[num
][0xD6] = 0x86;
2626 DispConvTable
[num
][0xF6] = 0x87;
2627 DispConvTable
[num
][0xD8] = 0x88;
2628 DispConvTable
[num
][0xF8] = 0x89;
2629 DispConvTable
[num
][0xDC] = 0x8A;
2630 DispConvTable
[num
][0xFC] = 0x8B;
2631 DispConvTable
[num
][0x5C] = 0x8C;
2632 DispConvTable
[num
][0xA5] = 0x5C;
2633 DispConvTable
[num
][0xA7] = 0x8F;
2634 DispConvTable
[num
][0xC6] = 0x90;
2635 DispConvTable
[num
][0xE6] = 0x91;
2636 DispConvTable
[num
][0xA3] = 0x92;
2637 DispConvTable
[num
][0xA6] = 0x98;
2638 DispConvTable
[num
][0xC7] = 0x99;
2639 DispConvTable
[num
][0xB0] = 0xDF;
2640 DispConvTable
[num
][0xE4] = 0xE1;
2641 DispConvTable
[num
][0xDF] = 0xE2;
2642 DispConvTable
[num
][0xB5] = 0xE4;
2643 DispConvTable
[num
][0xA4] = 0xEB;
2644 DispConvTable
[num
][0xA2] = 0xEC;
2645 DispConvTable
[num
][0xF1] = 0xEE;
2646 DispConvTable
[num
][0xF7] = 0xFD;
2647 DispConvTable
[num
][0x94] = 0x94;
2648 DispConvTable
[num
][0x95] = 0x95;
2649 DispConvTable
[num
][0x96] = 0x96;
2650 DispConvTable
[num
][0x97] = 0x97;
2651 DispConvTable
[num
][0x9b] = 0x9b;
2652 DispConvTable
[num
][0x9c] = 0x9c;
2653 DispConvTable
[num
][0x9d] = 0x9d;
2654 DispConvTable
[num
][0x9e] = 0x9e;
2655 DispConvTable
[num
][0x9f] = 0x9f;
2658 memset (DispConvTable
[num
],' ',256); // Initialize Table
2660 for (i
=0;i
<= 127;i
++) DispConvTable
[num
][i
] = i
; // Set lower 7 Bits
2661 DispConvTable
[num
][192] = 65;
2662 DispConvTable
[num
][193] = 65;
2663 DispConvTable
[num
][194] = 65;
2664 DispConvTable
[num
][195] = 65;
2665 DispConvTable
[num
][197] = 0x81;
2666 DispConvTable
[num
][198] = 0x90;
2667 DispConvTable
[num
][199] = 0x99;
2668 DispConvTable
[num
][200] = 69;
2669 DispConvTable
[num
][201] = 69;
2670 DispConvTable
[num
][202] = 69;
2671 DispConvTable
[num
][203] = 69;
2672 DispConvTable
[num
][204] = 73;
2673 DispConvTable
[num
][205] = 73;
2674 DispConvTable
[num
][206] = 73;
2675 DispConvTable
[num
][207] = 73;
2676 DispConvTable
[num
][208] = 68;
2677 DispConvTable
[num
][209] = 78;
2678 DispConvTable
[num
][210] = 79;
2679 DispConvTable
[num
][211] = 79;
2680 DispConvTable
[num
][212] = 79;
2681 DispConvTable
[num
][213] = 79;
2682 DispConvTable
[num
][216] = 0x88;
2683 DispConvTable
[num
][217] = 85;
2684 DispConvTable
[num
][218] = 85;
2685 DispConvTable
[num
][219] = 85;
2686 DispConvTable
[num
][221] = 89;
2687 DispConvTable
[num
][224] = 97;
2688 DispConvTable
[num
][225] = 0x83;
2689 DispConvTable
[num
][226] = 97;
2690 DispConvTable
[num
][227] = 97;
2691 DispConvTable
[num
][229] = 0x84;
2692 DispConvTable
[num
][230] = 0x91;
2693 DispConvTable
[num
][231] = 0x99;
2694 DispConvTable
[num
][232] = 101;
2695 DispConvTable
[num
][233] = 101;
2696 DispConvTable
[num
][234] = 101;
2697 DispConvTable
[num
][235] = 101;
2698 DispConvTable
[num
][236] = 105;
2699 DispConvTable
[num
][237] = 105;
2700 DispConvTable
[num
][238] = 105;
2701 DispConvTable
[num
][239] = 105;
2702 DispConvTable
[num
][241] = 0xee;
2703 DispConvTable
[num
][242] = 111;
2704 DispConvTable
[num
][243] = 111;
2705 DispConvTable
[num
][244] = 111;
2706 DispConvTable
[num
][245] = 111;
2707 DispConvTable
[num
][248] = 0x88;
2708 DispConvTable
[num
][249] = 117;
2709 DispConvTable
[num
][250] = 117;
2710 DispConvTable
[num
][251] = 117;
2711 DispConvTable
[num
][253] = 121;
2712 DispConvTable
[num
][255] = 255;
2716 DispConvTable
[num
][0xC4] = 0x80; // Set Conversion (Upper 8 Bits)
2717 DispConvTable
[num
][0xC5] = 0x82;
2718 DispConvTable
[num
][0xE1] = 0x83;
2719 DispConvTable
[num
][0xE5] = 0x84;
2720 DispConvTable
[num
][0xD6] = 0x86;
2721 DispConvTable
[num
][0xF6] = 0x87;
2722 DispConvTable
[num
][0xD8] = 0x88;
2723 DispConvTable
[num
][0xF8] = 0x89;
2724 DispConvTable
[num
][0xDC] = 0x8A;
2725 DispConvTable
[num
][0xFC] = 0x8B;
2726 DispConvTable
[num
][0x5C] = 0x8C;
2727 DispConvTable
[num
][0xA5] = 0x5C;
2728 DispConvTable
[num
][0xA7] = 0x8F;
2729 DispConvTable
[num
][0xC6] = 0x90;
2730 DispConvTable
[num
][0xE6] = 0x91;
2731 DispConvTable
[num
][0xA3] = 0x92;
2732 DispConvTable
[num
][0xA6] = 0x98;
2733 DispConvTable
[num
][0xC7] = 0x99;
2734 DispConvTable
[num
][0xB0] = 0xDF;
2735 DispConvTable
[num
][0xE4] = 0xE1;
2736 DispConvTable
[num
][0xDF] = 0xE2;
2737 DispConvTable
[num
][0xB5] = 0xE4;
2738 DispConvTable
[num
][0xA4] = 0xEB;
2739 DispConvTable
[num
][0xA2] = 0xEC;
2740 DispConvTable
[num
][0xF1] = 0xEE;
2741 DispConvTable
[num
][0xF7] = 0xFD;
2742 DispConvTable
[num
][0x94] = 0x94;
2743 DispConvTable
[num
][0x95] = 0x95;
2744 DispConvTable
[num
][0x96] = 0x96;
2745 DispConvTable
[num
][0x97] = 0x97;
2746 DispConvTable
[num
][0x9b] = 0x9b;
2747 DispConvTable
[num
][0x9c] = 0x9c;
2748 DispConvTable
[num
][0x9d] = 0x9d;
2749 DispConvTable
[num
][0x9e] = 0x9e;
2750 DispConvTable
[num
][0x9f] = 0x9f;
2753 void SetLCDProcCharsV (byte dat
[])
2760 dat
[i
] = (i
/ 9) + 1;
2771 dat
[i
] = (i
/ 9) + 1;
2782 dat
[i
] = (i
/ 9) + 1;
2793 dat
[i
] = (i
/ 9) + 1;
2805 void SetSpecialChars (byte dat
[])
2812 dat
[i
] = (i
/ 9) + 1; // Play
2823 dat
[i
] = (i
/ 9) + 1; // Pause
2834 dat
[i
] = (i
/ 9) + 1; // Stop
2845 dat
[i
] = (i
/ 9) + 1; // Next
2856 dat
[i
] = (i
/ 9) + 1; // Prev
2867 dat
[i
] = (i
/ 9) + 1; // Rew
2879 int SetTransceiverModus (byte mode
,word send_mask
,byte addr
,char *hotcode
,int hotlen
,byte extended_mode
,byte extended_mode2
,byte usb_mode
)
2883 md
.sbus_command
= HOST_SETMODE
;
2884 md
.sbus_address
= 0;
2885 if (addr
<= 15) md
.sbus_address
|= addr
;
2886 if (addr
== 'L') md
.sbus_address
|= ADRESS_LOCAL
;
2887 if (addr
== '*') md
.sbus_address
|= ADRESS_ALL
;
2889 md
.hotcode_len
= hotlen
;
2890 memcpy (md
.hotcode
,hotcode
,hotlen
);
2892 md
.hotcode
[hotlen
] = extended_mode
;
2893 md
.hotcode
[hotlen
+1] = extended_mode2
;
2895 md
.sbus_len
= sizeof (MODE_BUFFER
) + md
.hotcode_len
- 98;
2899 md
.target_mask
= send_mask
;
2901 res
= WriteTransceiver ((IRDATA
*)&md
,usb_mode
);
2902 if (res
) return (res
);
2908 int GetTransceiverVersion (char version
[],unsigned int *cap
,unsigned int *serno
,char mac_adr
[],byte usbmode
)
2914 struct sockaddr_in send_adr
;
2922 ir
.command
= HOST_VERSION
;
2923 ir
.checksumme
= HOST_VERSION
;
2931 memset (mac_adr
,0,6);
2935 IRTransLanSend (NULL
,&ir
);
2938 res
= WaitForSingleObject (IrtLanEvent
,2000);
2939 if (res
== WAIT_TIMEOUT
) return (ERR_READVERSION
);
2940 WSAResetEvent (IrtLanEvent
);
2946 FD_SET (irtlan_socket
,&events
);
2947 maxfd
= irtlan_socket
+ 1;
2952 wait
= select (maxfd
,&events
,NULL
,NULL
,&tv
);
2953 if (!wait
) return (ERR_READVERSION
);
2957 i
= sizeof (send_adr
);
2958 res
= recvfrom(irtlan_socket
,(byte
*)&ver
,sizeof (GETVERSION_LAN
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
2959 if (res
<= 0 || res
!= ver
.len
+ 1 || ver
.netcommand
!= RESULT_GETVERSION
) return (ERR_READVERSION
);
2962 memcpy (version
,ver
.ir_version
,8);
2963 // memcpy (dev->lan_version,ver.lan_version,8);
2964 *cap
= ver
.ir_capabilities
;
2965 *serno
= ver
.ir_serno
;
2966 memcpy (mac_adr
,ver
.mac_adr
,6);
2970 res
= WriteTransceiver (&ir
,usbmode
);
2973 res
= ReadIRString (version
,8,500,usbmode
);
2974 if (res
!= 8) return (ERR_READVERSION
);
2976 if (strcmp (version
+1,"2.24.01") >= 0) {
2977 res
= ReadIRString (data
,8,500,usbmode
);
2978 if (res
!= 8) return (ERR_READVERSION
);
2980 if (strcmp (version
+1,"4.04.01") >= 0) {
2981 memcpy (cap
,data
,4);
2983 memcpy (serno
,data
+ 4,4);
2984 swap_int ((int32_t *)serno
);
2987 memcpy (cap
,data
+ 1,2);
2989 memcpy (serno
,data
+ 3,4);
2990 swap_int ((int32_t *)serno
);
2992 if (*serno
== 2802 || *serno
== 0x11223344) *serno
= 0;
3000 int WriteTransceiverL (IRDATA
*src
,byte usb_mode
);
3002 int GetTransceiverVersionL (char version
[],unsigned int *cap
,unsigned int *serno
,char mac_adr
[],byte usbmode
)
3008 struct sockaddr_in send_adr
;
3016 ir
.command
= HOST_VERSION
;
3017 ir
.checksumme
= HOST_VERSION
;
3025 memset (mac_adr
,0,6);
3029 IRTransLanSend (NULL
,&ir
);
3032 res
= WaitForSingleObject (IrtLanEvent
,2000);
3033 if (res
== WAIT_TIMEOUT
) return (ERR_READVERSION
);
3034 WSAResetEvent (IrtLanEvent
);
3040 FD_SET (irtlan_socket
,&events
);
3041 maxfd
= irtlan_socket
+ 1;
3046 wait
= select (maxfd
,&events
,NULL
,NULL
,&tv
);
3047 if (!wait
) return (ERR_READVERSION
);
3051 i
= sizeof (send_adr
);
3052 res
= recvfrom(irtlan_socket
,(byte
*)&ver
,sizeof (GETVERSION_LAN
),MSG_NOSIGNAL
,(struct sockaddr
*)&send_adr
,&i
);
3053 if (res
<= 0 || res
!= ver
.len
+ 1 || ver
.netcommand
!= RESULT_GETVERSION
) return (ERR_READVERSION
);
3056 memcpy (version
,ver
.ir_version
,8);
3057 // memcpy (dev->lan_version,ver.lan_version,8);
3058 *cap
= ver
.ir_capabilities
;
3059 *serno
= ver
.ir_serno
;
3060 memcpy (mac_adr
,ver
.mac_adr
,6);
3064 res
= WriteTransceiverL (&ir
,usbmode
);
3067 res
= ReadIRString (version
,8,500,usbmode
);
3068 if (res
!= 8) return (ERR_READVERSION
);
3070 if (strcmp (version
+1,"2.24.01") >= 0) {
3071 res
= ReadIRString (data
,8,500,usbmode
);
3072 if (res
!= 8) return (ERR_READVERSION
);
3074 if (strcmp (version
+1,"4.04.01") >= 0) {
3075 memcpy (cap
,data
,4);
3077 memcpy (serno
,data
+ 4,4);
3078 swap_int ((int32_t *)serno
);
3081 memcpy (cap
,data
+ 1,2);
3083 memcpy (serno
,data
+ 3,4);
3084 swap_int ((int32_t *)serno
);
3086 if (*serno
== 2802 || *serno
== 0x11223344) *serno
= 0;
3097 int WriteTransceiver (IRDATA
*src
,byte usb_mode
)
3104 swap_irdata (src
,&send
);
3106 send
.checksumme
= get_checksumme (&send
);
3108 if (usb_mode
== 1) FlushUSB ();
3109 else if (!usb_mode
) FlushCom ();
3110 if (mode_flag
& HEXDUMP
) Hexdump_IO (&send
);
3111 if (hexflag
) Hexdump_File (&send
);
3112 WriteIRString ((byte
*)&send
,send
.len
,usb_mode
);
3113 res
= ReadIRString (st
,1,500,usb_mode
);
3115 if (res
!= 1 || *st
!= 'O') {
3116 if (res
&& *st
== 'R') return (ERR_RESEND
);
3117 if (usb_mode
) FlushUSB ();
3120 if (count
> 2) msSleep (1000);
3123 } while (res
== 0 && count
< 5);
3125 if (count
== 5) return (ERR_TIMEOUT
);
3131 int WriteTransceiverL (IRDATA
*src
,byte usb_mode
)
3139 swap_irdata (src
,&send
);
3141 send
.checksumme
= get_checksumme (&send
);
3143 ((byte
*)&send
)[send
.len
] = seq
++;
3146 if (usb_mode
== 1) FlushUSB ();
3147 else if (!usb_mode
) FlushCom ();
3148 if (mode_flag
& HEXDUMP
) Hexdump_IO (&send
);
3149 if (hexflag
) Hexdump_File (&send
);
3150 if (usb_mode
) WriteIRString ((byte
*)&send
,send
.len
+1,usb_mode
);
3151 else WriteIRString ((byte
*)&send
,send
.len
,usb_mode
);
3152 res
= ReadIRString (st
,1,500,usb_mode
);
3154 if (res
!= 1 || *st
!= 'O') {
3155 if (res
&& *st
== 'R') return (ERR_RESEND
);
3156 if (usb_mode
) FlushUSB ();
3159 if (count
> 2) msSleep (1000);
3162 } while (res
== 0 && count
< 5);
3164 if (count
== 5) return (ERR_TIMEOUT
);
3170 void WriteIRString (byte pnt
[],int len
,byte usb_mode
)
3173 if (usb_mode
) WriteUSBString (pnt
,len
);
3174 else WriteSerialString (pnt
,len
);
3178 WriteSerialString (pnt
,len
);
3182 int ReadIRString (byte pnt
[],int len
,word timeout
,byte usb_mode
)
3185 if (usb_mode
) return (ReadUSBString (pnt
,len
,timeout
));
3186 else return (ReadSerialString (pnt
,len
,timeout
));
3190 return (ReadSerialString (pnt
,len
,timeout
));
3196 void FlushUSB (void)
3202 void FlushIoEx (DEVICEINFO *dev)
3205 if (dev->io.if_type == IF_USB) FlushUSBEx (dev->io.usbport);
3206 else FlushComEx (dev->io.comport);
3210 FlushComEx (dev->io.comport);
3215 void SwapWordN (word
*pnt
)
3219 if (byteorder
) return;
3228 void SwapIntN (int32_t *pnt
)
3232 if (byteorder
) return;