9 #include <sys/socket.h>
10 #include <netinet/in.h>
12 #include <arpa/inet.h>
18 typedef void* WSAEVENT
;
19 #define closesocket close
28 int InitClientSocket (char host
[],SOCKET
*sock
,unsigned long id
);
29 void PrintStatError (NETWORKSTATUS
*stat
);
31 void ReceiveIR (void);
32 char *trim (char st
[],int i
);
34 void BuildMainMenu ();
35 void BuildSendMenu ();
36 void BuildLearnMenu ();
37 int SendRemoteCommand (char rem
[],char com
[],char mask
[],char bus
[],char led
[]);
38 int SendCommand (NETWORKCOMMAND
*com
,NETWORKSTATUS
*stat
);
39 int NetworkCommand (int netcommand
,char remote
[],char command
[],word timeout
,int adr
,NETWORKSTATUS
*stat
);
40 int ShutdownServer (void);
41 int ReloadServer (void);
42 int SetSwitch (char sw
[],char value
[]);
43 int SendSerial (char data
[]);
44 int SetLED (char mode
[],char value
[]);
45 int SendUDP (char ip
[],char cmdstr
[]);
52 char send_remote
[100];
53 char learn_remote
[100];
55 main (int argc
,char *argv
[])
58 // unsigned char st[256];
59 // NETWORKSTATUS stat;
61 if (argc
!= 2 && argc
!= 3 && argc
!= 4 && argc
!= 5 && argc
!= 6 && argc
!= 7) {
62 fprintf(stderr
, "usage : %s <ip>\n", argv
[0]);
63 fprintf(stderr
, "send : %s <ip> <remote> <command>\n",argv
[0]);
64 fprintf(stderr
, "send : %s <ip> <remote> <command> <sendmask> <bus>\n",argv
[0]);
65 fprintf(stderr
, "send : %s <ip> <remote> <command> <sendmask> <bus> <led>\n",argv
[0]);
66 fprintf(stderr
, "shutdown : %s <ip> -shutdown\n", argv
[0]);
67 fprintf(stderr
, "reload IRDB: %s <ip> -reload\n", argv
[0]);
68 fprintf(stderr
, "receive : %s <ip> -receive\n", argv
[0]);
69 fprintf(stderr
, "Send RS232 : %s <ip> -rs232send <data>\n", argv
[0]);
70 fprintf(stderr
, "switch : %s <ip> -switch <switch> <value>\n", argv
[0]);
71 fprintf(stderr
, "LED : %s <ip> -led <mode> <value>\n", argv
[0]);
75 if (argc
== 4 && !strcmp (argv
[2],"-udp")) return (SendUDP (argv
[1],argv
[3]));
77 if (argc
== 2 && !strcmp (argv
[1],"-receiveudp")) return (RcvUDP());
79 res
= InitClientSocket (argv
[1],&serv
,0);
81 fprintf (stderr
,"Error connecting to host %s\n",argv
[1]);
85 if (argc
== 3 && !strcmp (argv
[2],"-shutdown")) return (ShutdownServer ());
86 if (argc
== 3 && !strcmp (argv
[2],"-reload")) return (ReloadServer ());
87 if (argc
== 3 && !strcmp (argv
[2],"-receive")) ReceiveIR ();
88 if (argc
== 4 && !strcmp (argv
[2],"-rs232send")) return (SendSerial (argv
[3]));
89 if (argc
== 5 && !strcmp (argv
[2],"-switch")) return (SetSwitch (argv
[3],argv
[4]));
90 if (argc
== 5 && !strcmp (argv
[2],"-led")) return (SetLED (argv
[3],argv
[4]));
91 if (argc
== 4) return (SendRemoteCommand (argv
[2],argv
[3],NULL
,NULL
,NULL
));
92 if (argc
== 5) return (SendRemoteCommand (argv
[2],argv
[3],argv
[4],NULL
,NULL
));
93 if (argc
== 6) return (SendRemoteCommand (argv
[2],argv
[3],argv
[4],argv
[5],NULL
));
94 if (argc
== 7) return (SendRemoteCommand (argv
[2],argv
[3],argv
[4],argv
[5],argv
[6]));
98 // NetworkCommand (COMMAND_MCE_CHARS,"",0,0,'L',&stat);
100 strcpy (st," -123456");
101 // strcpy (st,"-1234567890abcdefghijklmnop");
115 sprintf (st,"%-40s%-40s%-40s%-40s","12345678901234567","XP Mediacenter."," "," ");
116 // strcpy (st,"123456789012 ");
117 NetworkCommand (COMMAND_LCD,st,0,LCD_TEXT | LCD_BACKLIGHT,'L',&stat);
120 NetworkCommand (COMMAND_STARTCLOCK,"",0,0,'L',&stat);
123 sprintf (st,"Test Nr %d",res++);
124 NetworkCommand (COMMAND_LCD,st,0,LCD_TEXT | LCD_BACKLIGHT,'L',&stat);
140 struct sockaddr_in serv_addr
;
144 WORD wVersionRequired
;
146 wVersionRequired
= MAKEWORD(2,2);
147 err
= WSAStartup(wVersionRequired
, &wsaData
);
148 if (err
!= 0) exit(1);
153 irtlan_socket
= socket (PF_INET
,SOCK_DGRAM
,0);
154 if (irtlan_socket
< 0) return (ERR_OPENSOCKET
);
156 memset (&serv_addr
,0,sizeof (serv_addr
));
157 serv_addr
.sin_family
= AF_INET
;
159 serv_addr
.sin_addr
.s_addr
= htonl (INADDR_ANY
);
160 serv_addr
.sin_port
= htons (437);
162 if (bind (irtlan_socket
,(struct sockaddr
*)&serv_addr
,sizeof (serv_addr
)) < 0) {
163 printf ("Error Bind\n");
164 return (ERR_BINDSOCKET
);
169 res
= recv (irtlan_socket
,mem
,100,0);
171 printf ("RECV: %s\n",mem
);
179 int SendUDP (char ip
[],char cmdstr
[])
183 int irtlan_outbound
,irtlan_in
;
184 struct sockaddr_in iadr
;
185 struct sockaddr_in serv_addr
;
189 WORD wVersionRequired
;
191 wVersionRequired
= MAKEWORD(2,2);
192 err
= WSAStartup(wVersionRequired
, &wsaData
);
193 if (err
!= 0) exit(1);
196 irtlan_outbound
= socket (PF_INET
,SOCK_DGRAM
,0);
197 if (irtlan_outbound
< 0) return (ERR_OPENSOCKET
);
199 irtlan_in
= socket (PF_INET
,SOCK_DGRAM
,0);
200 memset (&serv_addr
,0,sizeof (serv_addr
));
201 serv_addr
.sin_family
= AF_INET
;
203 serv_addr
.sin_addr
.s_addr
= htonl (INADDR_ANY
);
204 serv_addr
.sin_port
= htons (IRTRANS_PORT
);
205 // serv_addr.sin_port = htons (50000);
207 rcv
= bind (irtlan_in
,(struct sockaddr
*)&serv_addr
,sizeof (serv_addr
));
209 memset (&iadr
,0,sizeof (struct sockaddr
));
210 iadr
.sin_family
= AF_INET
;
211 iadr
.sin_addr
.s_addr
= inet_addr(ip
);
212 iadr
.sin_port
= htons ((word
)IRTRANS_PORT
);
213 // iadr.sin_port = htons ((word)8010);
215 if (connect (irtlan_outbound
,(struct sockaddr
*)&iadr
,sizeof (struct sockaddr_in
)) < 0) {
216 printf ("Error Connect\n");
217 return (ERR_BINDSOCKET
);
220 res
= send (irtlan_outbound
,cmdstr
,strlen (cmdstr
),0);
222 if (res
!= (int)strlen (cmdstr
)) {
223 printf ("Error Sending\n");
224 return (ERR_BINDSOCKET
);
228 if (rcv
< 0) printf ("ACK Rcv Socket busy (same machine ?)\n");
231 recv (irtlan_in
,stat
,50,0);
232 printf ("RCV STAT: %s\n",stat
);
238 int SendSerial (char data
[])
242 NetworkCommand (COMMAND_RS232_SEND
,data
,0,0,'L',&stat
);
248 int SetSwitch (char sw
[],char value
[])
254 st
[1] = atoi (value
);
255 NetworkCommand (COMMAND_SETSWITCH
,st
,st
+1,0,'L',&stat
);
260 int SetLED (char mode
[],char value
[])
266 st
[1] = atoi (value
);
267 NetworkCommand (COMMAND_LED
,st
,st
+1,0,'L',&stat
);
278 printf ("Waiting for IR commands ...\n");
279 memset (&stat
,0,sizeof (NETWORKSTATUS
));
280 rcv
= (NETWORKRECV
*)&stat
;
282 res
= recv (serv
,(char *)&stat
,8,0);
283 if (stat
.statuslen
> 8) {
284 res
= recv (serv
,((char *)&stat
) + 8,stat
.statuslen
-8,0);
285 if (stat
.statustype
== STATUS_RECEIVE
) {
286 printf ("RCV: %s.%s - %d [%d: %s]\n",trim (rcv
->remote
,80),trim (rcv
->command
,20),rcv
->adress
,rcv
->clientid
,trim (rcv
->data
,200));
293 char *trim (char st
[],int i
)
296 while (i
&& st
[i
] == ' ') i
--;
302 int SendRemoteCommand (char rem
[],char com
[],char mask
[],char bus
[],char led
[])
304 int adr
= 0,res
,wait
= 0,ibus
= 0,iled
= 0;
308 if (!strcmp (rem
,"wait") || !strcmp (rem
,"Wait") || !strcmp (rem
,"WAIT")) {
316 if (!strcmp (mask
,"wait") || !strcmp (mask
,"Wait") || !strcmp (mask
,"WAIT")) wait
= atoi (mask
+4);
317 else if (!strcmp (mask
,"int") || !strcmp (mask
,"Int") || !strcmp (mask
,"INT")) adr
|= 1 << 17;
318 else if (!strcmp (mask
,"ext") || !strcmp (mask
,"Ext") || !strcmp (mask
,"EXT")) adr
|= 2 << 17;
319 else if (!strcmp (mask
,"all") || !strcmp (mask
,"All") || !strcmp (mask
,"ALL")) adr
|= 3 << 17;
321 if (mask
[0] == '0' && mask
[1] == 'x') sscanf (mask
,"%x",&adr
);
322 else sscanf (mask
,"%d",&adr
);
323 if (adr
) adr
= (adr
& 0xffff) | 0x10000;
328 if (ibus
== 255) adr
|= 0x40000000;
330 ibus
= abs (ibus
) & (MAX_IR_DEVICES
- 1);
335 iled
= atoi (led
) & 3;
338 res
= NetworkCommand (COMMAND_SEND
,rem
,com
,0,adr
,&stat
);
346 int ShutdownServer (void)
351 com
.netcommand
= COMMAND_SHUTDOWN
;
352 strcpy (com
.remote
,"XXXshutdownXXX");
354 SendCommand (&com
,&stat
);
363 int ReloadServer (void)
368 com
.netcommand
= COMMAND_RELOAD
;
370 SendCommand (&com
,&stat
);
377 char st
[255],l2
[255];
389 printf ("\nEnter Remote Name: ");
391 scanf ("%s",send_remote
);
395 printf ("\nCommand Name: ");
399 NetworkCommand (COMMAND_SEND
,send_remote
,st
,0,0,&stat
);
402 printf ("\nLCD Text: ");
404 fgets (st
,sizeof (st
),stdin
);
405 NetworkCommand (COMMAND_LCD
,st
,0,LCD_TEXT
| LCD_BACKLIGHT
,'L',&stat
);
408 printf ("\nLCD Init Text Line 1: ");
410 fgets (st
,sizeof (st
),stdin
);
411 printf ("\nLCD Init Text Line 2: ");
413 fgets (l2
,sizeof (l2
),stdin
);
415 NetworkCommand (COMMAND_LCDINIT
,st
,0,LCD_TEXT
,'L',&stat
);
418 printf ("\nSwitch Number: ");
422 printf ("\nSwitch Value: ");
428 NetworkCommand (COMMAND_SETSWITCH
,st
,st
+1,0,'L',&stat
);
451 if (*learn_remote
) NetworkCommand (COMMAND_CLOSE
,learn_remote
,st
,0,'L',&stat
);
452 printf ("\nEnter Remote Name: ");
454 scanf ("%s",learn_remote
);
456 NetworkCommand (COMMAND_LRNREM
,learn_remote
,st
,0,'L',&stat
);
459 printf ("\nPress Remote Button to record timing ....");
461 NetworkCommand (COMMAND_LRNTIM
,learn_remote
,st
,TIMEOUT
,'*',&stat
);
466 printf ("\nCommand Name: ");
470 printf ("\nPress Remote Button to learn ....");
472 NetworkCommand (COMMAND_LRNCOM
,learn_remote
,st
,TIMEOUT
,'*',&stat
);
477 printf ("\nCommand Name: ");
481 printf ("\nPress Remote Button to learn ....");
483 NetworkCommand (COMMAND_LRNLONG
,learn_remote
,st
,TIMEOUT
,'*',&stat
);
488 printf ("\nCommand Name: ");
492 printf ("\nPress Remote Button to learn ....");
494 NetworkCommand (COMMAND_LRNRAW
,learn_remote
,st
,TIMEOUT
,'*',&stat
);
499 if (*learn_remote
) NetworkCommand (COMMAND_CLOSE
,learn_remote
,st
,0,'L',&stat
);
508 void ShowSetStatus (int adr
,int bus
,NETWORKMODEEXN
*status
)
511 status
->stat
[bus
][adr
].version
[8] = 0;
513 printf ("Device [%d]: %s\n\n",adr
,status
->stat
[bus
][adr
].version
);
515 printf ("Repeat Mask: ");
517 printf ("%c ",(status
->stat
[bus
][adr
].send_mask
& (1 << i
) ? 'x':'o'));
519 printf ("\n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\n");
522 printf (" Device Mode Send [20]: %c\n",(status
->stat
[bus
][adr
].device_mode
& DEVMODE_SEND
? 'x':'o'));
523 printf (" IR [21]: %c\n",(status
->stat
[bus
][adr
].device_mode
& DEVMODE_IR
? 'x':'o'));
524 printf (" SBUS [22]: %c\n",(status
->stat
[bus
][adr
].device_mode
& DEVMODE_SBUS
? 'x':'o'));
525 // printf (" IR RemoteCtrl [23]: %c\n",(status->stat[bus][adr].device_mode & DEVMODE_IRCODE ? 'x':'o'));
526 printf (" SBUS RemoteCtrl [24]: %c\n",(status
->stat
[bus
][adr
].device_mode
& DEVMODE_SBUSCODE
? 'x':'o'));
527 printf (" RAW [25]: %c\n",(status
->stat
[bus
][adr
].device_mode
& DEVMODE_RAW
? 'x':'o'));
528 if (strcmp (status
->stat
[bus
][adr
].version
+1,"4.05.01") < 0) printf (" Fast Mode [26]: %c\n",(status
->stat
[bus
][adr
].device_mode
& DEVMODE_RAWFAST
? 'x':'o'));
529 printf (" SBUS send Repeat [27]: %c\n",(status
->stat
[bus
][adr
].device_mode
& DEVMODE_REPEAT
? 'x':'o'));
531 if (status
->stat
[bus
][adr
].features
& FN_DUALSND
) {
532 printf ("\n Internal LEDs [30]: %c\n",(status
->stat
[bus
][adr
].extended_mode
& INTERNAL_LEDS
? 'x':'o'));
533 printf (" External LEDs [31]: %c\n",(status
->stat
[bus
][adr
].extended_mode
& EXTERNAL_LEDS
? 'x':'o'));
535 if (status
->stat
[bus
][adr
].features
& FN_DUALRCV
) {
536 printf ("\n Standard Receivr.[33]: %c\n",(status
->stat
[bus
][adr
].extended_mode
& STANDARD_RCV
? 'x':'o'));
537 printf (" 455 kHz Receiver [34]: %c\n",(status
->stat
[bus
][adr
].extended_mode
& BO_RCV
? 'x':'o'));
540 if (status
->stat
[bus
][adr
].version
[0] == 'V' || status
->stat
[bus
][adr
].version
[0] == 'T' || status
->stat
[bus
][adr
].version
[0] == 'C' || status
->stat
[bus
][adr
].version
[0] == 'X' ) { // 455kHz
541 printf ("\n Receive B&O [35]: %c\n",(status
->stat
[bus
][adr
].extended_mode
& BO_MODE
? 'x':'o'));
544 if (strcmp (status
->stat
[bus
][adr
].version
+1,"3.02.10") >= 0) {
545 printf ("\n Self Repeat [36]: %c\n",(status
->stat
[bus
][adr
].extended_mode
& SELF_REPEAT
? 'x':'o'));
546 if (status
->stat
[bus
][adr
].features
& FN_DUALSND
) {
547 printf (" via Internal LEDs [32]: %c\n",(status
->stat
[bus
][adr
].extended_mode
& INTERNAL_REPEAT
? 'x':'o'));
550 if (strcmp (status
->stat
[bus
][adr
].version
+1,"4.04.01") >= 0) {
551 printf ("\n Learn Timeout 5ms [37]: %c\n",(((status
->stat
[bus
][adr
].extended_mode2
& LRN_TIMEOUT_MASK
) == 0) ? 'x':'o'));
552 printf (" Learn Timeout 15ms [38]: %c\n",(((status
->stat
[bus
][adr
].extended_mode2
& LRN_TIMEOUT_MASK
) == 1) ? 'x':'o'));
553 printf (" Learn Timeout 30ms [39]: %c\n",(((status
->stat
[bus
][adr
].extended_mode2
& LRN_TIMEOUT_MASK
) == 2) ? 'x':'o'));
554 printf (" Learn Timeout 60ms [40]: %c\n",(((status
->stat
[bus
][adr
].extended_mode2
& LRN_TIMEOUT_MASK
) == 3) ? 'x':'o'));
555 printf (" Learn Timeout 90ms [41]: %c\n",(((status
->stat
[bus
][adr
].extended_mode2
& LRN_TIMEOUT_MASK
) == 4) ? 'x':'o'));
556 printf (" Learn Timeout 120ms [42]: %c\n",(((status
->stat
[bus
][adr
].extended_mode2
& LRN_TIMEOUT_MASK
) == 5) ? 'x':'o'));
557 printf (" Learn Timeout 150ms [43]: %c\n",(((status
->stat
[bus
][adr
].extended_mode2
& LRN_TIMEOUT_MASK
) == 6) ? 'x':'o'));
558 if (strcmp (status
->stat
[bus
][adr
].version
+1,"4.04.35") >= 0)
559 printf (" Learn Timeout 250ms [44]: %c\n",(((status
->stat
[bus
][adr
].extended_mode2
& LRN_TIMEOUT_MASK
) == 7) ? 'x':'o'));
562 if (strcmp (status
->stat
[bus
][adr
].version
+1,"4.05.01") >= 0) {
563 printf ("\n Repeat Timeout 5ms [45]: %c\n",(status
->stat
[bus
][adr
].device_mode
& DEVMODE_RAWFAST
? 'o':'x'));
564 printf (" Repeat Timeout 25ms [46]: %c\n",(status
->stat
[bus
][adr
].device_mode
& DEVMODE_RAWFAST
? 'x':'o'));
567 if (status
->stat
[bus
][adr
].features
& FN_SBUS_UART
) {
568 printf ("\n SBUS Classic [47]: %c\n",(status
->stat
[bus
][adr
].extended_mode
& SBUS_UART
? 'o':'x'));
569 printf (" SBUS 4800 Baud [48]: %c\n",((status
->stat
[bus
][adr
].extended_mode
& SBUS_UART
&& (status
->stat
[bus
][adr
].extended_mode2
& SBUS_BAUD_MASK
) == 0) ? 'x':'o'));
570 printf (" SBUS 9600 Baud [49]: %c\n",((status
->stat
[bus
][adr
].extended_mode
& SBUS_UART
&& (status
->stat
[bus
][adr
].extended_mode2
& SBUS_BAUD_MASK
) == 8) ? 'x':'o'));
571 printf (" SBUS 19200 Baud [50]: %c\n",((status
->stat
[bus
][adr
].extended_mode
& SBUS_UART
&& (status
->stat
[bus
][adr
].extended_mode2
& SBUS_BAUD_MASK
) == 16) ? 'x':'o'));
572 printf (" SBUS 38400 Baud [51]: %c\n",((status
->stat
[bus
][adr
].extended_mode
& SBUS_UART
&& (status
->stat
[bus
][adr
].extended_mode2
& SBUS_BAUD_MASK
) == 24) ? 'x':'o'));
575 if (!(status
->stat
[bus
][adr
].features
& FN_SOFTID
) || (status
->stat
[bus
][adr
].features
& FN_POWERON
) || (status
->stat
[bus
][adr
].features
& FN_USBWAKEUP
)) {
576 printf ("\nPowerOn Remote [52]: %s\n",status
->stat
[bus
][adr
].remote
);
577 printf ("PowerOn Command [53]: %s\n",status
->stat
[bus
][adr
].command
);
580 if (status
->stat
[bus
][adr
].features
& FN_DUALPOWERON
) {
581 printf ("\nPowerOff Remote [54]: %s\n",status
->stat
[bus
][adr
].remote2
);
582 printf ("PowerOff Command [55]: %s\n",status
->stat
[bus
][adr
].command2
);
585 printf ("\nCancel [88]\n");
586 printf ("Save & Exit [99]\n");
588 printf ("\nSelect command ");
592 void SetDeviceStatus (int adr
,NETWORKMODEEXN
*status
)
598 NETWORKCOMMAND command
;
601 while (choice
< 56) {
602 ShowSetStatus (adr
,bus
,status
);
608 if (choice
< 20) status
->stat
[bus
][adr
].send_mask
^= 1 << choice
;
610 else if (choice
< 30) status
->stat
[bus
][adr
].device_mode
^= 1 << (choice
- 20);
611 else if (choice
<= 44) {
612 if (choice
>= 37 && choice
<= 44) status
->stat
[bus
][adr
].extended_mode2
= choice
- 37;
614 if (choice
== 32) choice
= 36;
615 else if (choice
> 32) choice
--;
616 status
->stat
[bus
][adr
].extended_mode
^= 1 << (choice
- 30);
619 if (choice
== 45) status
->stat
[bus
][adr
].device_mode
&= ~DEVMODE_RAWFAST
;
620 if (choice
== 46) status
->stat
[bus
][adr
].device_mode
|= DEVMODE_RAWFAST
;
621 if (choice
>= 47 && choice
<= 51) {
622 if (choice
== 47) status
->stat
[bus
][adr
].extended_mode
&= ~SBUS_UART
;
624 status
->stat
[bus
][adr
].extended_mode2
&= ~SBUS_BAUD_MASK
;
625 status
->stat
[bus
][adr
].extended_mode2
|= (choice
- 48) * 8;
626 status
->stat
[bus
][adr
].extended_mode
|= SBUS_UART
;
631 printf ("\nEnter PowerOn Remote: ");
633 scanf ("%s",status
->stat
[bus
][adr
].remote
);
637 printf ("\nEnter PowerOn Command: ");
639 scanf ("%s",status
->stat
[bus
][adr
].command
);
643 printf ("\nEnter PowerOff Remote: ");
645 scanf ("%s",status
->stat
[bus
][adr
].remote2
);
649 printf ("\nEnter PowerOff Command: ");
651 scanf ("%s",status
->stat
[bus
][adr
].command2
);
655 command
.netcommand
= COMMAND_SETSTAT
;
656 strcpy (command
.command
,status
->stat
[bus
][adr
].command
);
657 strcpy (command
.remote
,status
->stat
[bus
][adr
].remote
);
658 command
.timeout
= adr
;
659 command
.mode
= status
->stat
[bus
][adr
].device_mode
;
660 command
.adress
= status
->stat
[bus
][adr
].send_mask
| (status
->stat
[bus
][adr
].extended_mode
<< 16);
661 command
.trasmit_freq
= status
->stat
[bus
][adr
].extended_mode2
;
662 memset (&stat
,0,sizeof (stat
));
663 res
= SendCommand (&command
,&stat
);
667 if (stat
.statustype
== STATUS_MESSAGE
) {
668 PrintStatError (&stat
);
671 if (status
->stat
[bus
][adr
].features
& FN_DUALPOWERON
) {
672 command
.netcommand
= COMMAND_SETSTAT2
;
673 strcpy (command
.command
,status
->stat
[bus
][adr
].command2
);
674 strcpy (command
.remote
,status
->stat
[bus
][adr
].remote2
);
675 memset (&stat
,0,sizeof (stat
));
676 res
= SendCommand (&command
,&stat
);
680 if (stat
.statustype
== STATUS_MESSAGE
) {
681 PrintStatError (&stat
);
692 int StatusMenu (void)
697 NETWORKMODEEXN status
;
701 printf ("Getting Device Status ...");
704 com
.netcommand
= COMMAND_STATUSEXN
;
706 memset (&status
,0,sizeof (status
));
707 res
= SendCommand (&com
,(NETWORKSTATUS
*)&status
);
708 printf ("SEND RES: %d - %d\n",res
,status
.statustype
);
711 if (status
.statustype
!= STATUS_DEVICEMODEEXN
) {
712 PrintStatError ((NETWORKSTATUS
*)&status
);
717 for (i
=0;i
< 16;i
++) {
718 if (status
.stat
[0][i
].version
[0]) cnt
++;
719 status
.stat
[0][i
].version
[8] = 0;
722 printf ("%c \n%d Device(s) Found:\n\n",13,cnt
);
723 for (i
=0;i
< 16;i
++) {
724 if (status
.stat
[0][i
].version
[0]) printf ("%2d: - %s\n",i
,status
.stat
[0][i
].version
);
727 printf ("\n99 - Exit\n");
728 printf ("\nSelect command ");
734 if (choice
== 99) return (0);
736 SetDeviceStatus (choice
,&status
);
756 while (LearnMenu ());
759 while (StatusMenu ());
770 void BuildMainMenu ()
772 printf ("\n\n 1 - Send\n");
773 printf (" 2 - Learn\n");
774 printf (" 3 - Status\n");
775 printf ("\n 99 - Exit\n");
776 printf ("\nSelect command ");
781 void BuildSendMenu ()
783 printf ("\n\n**Selected Remote: [%s]\n\n",send_remote
);
784 printf (" 1 - Select remote\n");
785 printf (" 2 - Send command\n");
786 printf (" 3 - Send LCD\n");
787 printf (" 4 - Set LCD Init String\n");
788 printf (" 5 - Set Switch\n");
789 printf ("\n 99 - Exit\n");
790 printf ("\nSelect command ");
794 void BuildLearnMenu ()
796 printf ("\n\n**Selected Remote: [%s]\n\n",learn_remote
);
797 printf (" 1 - Select remote\n");
798 printf (" 2 - Learn Timing\n");
799 printf (" 3 - Learn Command [Based on timing]\n");
800 printf (" 4 - Learn Command [Command with timing]\n");
801 printf (" 5 - Learn Command [RAW Data]\n");
802 printf ("\n 99 - Exit\n");
803 printf ("\nSelect command ");
807 void PrintStatError (NETWORKSTATUS
*stat
)
809 printf ("%s\n",stat
->message
);
813 int NetworkCommand (int netcommand
,char remote
[],char command
[],word timeout
,int adr
,NETWORKSTATUS
*stat
)
820 memset (&ser
,0,sizeof (ser
));
822 com
= (NETWORKCOMMAND
*)&ser
;
823 lcd
= (LCDCOMMAND
*)&ser
;
825 com
->netcommand
= netcommand
;
826 if (netcommand
== COMMAND_LCD
|| netcommand
== COMMAND_LCDINIT
) {
827 strcpy (lcd
->framebuffer
,remote
);
830 lcd
->lcdcommand
= (byte
)timeout
;
832 else if (netcommand
== COMMAND_SETSWITCH
) {
833 com
->remote
[0] = remote
[0];
834 com
->command
[0] = command
[0];
836 else if (netcommand
== COMMAND_RS232_SEND
) {
837 ser
.len
= strlen (remote
);
838 strcpy (ser
.data
,remote
);
841 strcpy (com
->remote
,remote
);
842 if (command
) strcpy (com
->command
,command
);
843 com
->timeout
= timeout
;
845 res
= SendCommand (com
,stat
);
847 if (stat
->netstatus
) {
848 PrintStatError (stat
);
849 if (stat
-> statuslevel
== FATAL
) exit (res
);
851 return (stat
->netstatus
);
855 int SendCommand (NETWORKCOMMAND
*com
,NETWORKSTATUS
*stat
)
862 com
->protocol_version
= 200;
863 size
= sizeof (NETWORKCOMMAND
);
864 if (com
->netcommand
== COMMAND_LCD
) size
= sizeof (LCDCOMMAND
);
865 if (com
->netcommand
== COMMAND_RS232_SEND
) size
= sizeof (SERCOMMAND
);
867 res
= send (serv
,(char *)com
,size
,0);
874 memset (stat
,0,sizeof (NETWORKSTATUS
));
879 FD_SET (serv
,&events
);
880 res
= select (serv
+1,&events
,NULL
,NULL
,&tv
);
882 if (res
<= 0) return (ERR_SEND
);
885 res
= recv (serv
,(char *)&buf
,32768,0);
887 if (res
&& (buf
.statustype
== STATUS_MESSAGE
|| buf
.statustype
== STATUS_DEVICEMODEEXN
)) memcpy (stat
,&buf
,res
);
888 if (res
== 8) return (0);
890 } while (buf
.statustype
== STATUS_RECEIVE
);
898 int InitClientSocket (char host
[],SOCKET
*sock
,unsigned long id
)
900 struct sockaddr_in serv_addr
;
908 WORD wVersionRequired
;
910 wVersionRequired
= MAKEWORD(2,2);
911 err
= WSAStartup(wVersionRequired
, &wsaData
);
912 if (err
!= 0) exit(1);
916 adr
= inet_addr (host
);
917 if (adr
== INADDR_NONE
) {
918 he
= (struct hostent
*)gethostbyname (host
);
919 if (he
== NULL
) return (ERR_FINDHOST
);
920 memcpy(&addr
, he
->h_addr_list
[0], sizeof(struct in_addr
));
926 *sock
= socket (PF_INET
,SOCK_STREAM
,0);
927 if (*sock
< 0) return (ERR_OPENSOCKET
);
929 memset (&serv_addr
,0,sizeof (serv_addr
));
930 serv_addr
.sin_family
= AF_INET
;
931 serv_addr
.sin_addr
.s_addr
= adr
;
932 serv_addr
.sin_port
= htons (TCP_PORT
);
934 if (connect (*sock
,(struct sockaddr
*)&serv_addr
,sizeof (serv_addr
)) < 0) return (ERR_CONNECT
);
936 send (*sock
,(char *)&id
,4,0);