Rev 555 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 555 | Rev 800 | ||
|---|---|---|---|
| 1 | #!/usr/bin/perl -w |
1 | #!/usr/bin/perl -w |
| 2 | use IO::Socket; |
2 | use IO::Socket; |
| 3 | use integer; |
3 | use integer; |
| 4 | use threads; |
4 | use threads; |
| 5 | 5 | ||
| 6 | @input = (); |
6 | @input = (); |
| 7 | @output = (); |
7 | @output = (); |
| 8 | 8 | ||
| 9 | #define makros, when an input sting is sent on can this perl-script will send the corresponding output string |
9 | #define makros, when an input sting is sent on can this perl-script will send the corresponding output string |
| 10 | 10 | ||
| 11 | # Remote button 1 => desktoplamp toggle |
11 | # Remote button 1 => desktoplamp toggle |
| 12 | push(@input , "PKT 04000003 1 0 00 00 1e 14"); |
12 | push(@input , "PKT 04000003 1 0 00 00 1e 14"); |
| 13 | push(@output, "key up\n"); |
13 | push(@output, "key up\n"); |
| 14 | 14 | ||
| 15 | push(@input , "PKT 04000003 1 0 00 00 1e 15"); |
15 | push(@input , "PKT 04000003 1 0 00 00 1e 15"); |
| 16 | push(@output, "key down\n"); |
16 | push(@output, "key down\n"); |
| 17 | 17 | ||
| 18 | push(@input , "PKT 04000003 1 0 00 00 1e 16"); |
18 | push(@input , "PKT 04000003 1 0 00 00 1e 16"); |
| 19 | push(@output, "key left\n"); |
19 | push(@output, "key left\n"); |
| 20 | 20 | ||
| 21 | push(@input , "PKT 04000003 1 0 00 00 1e 17"); |
21 | push(@input , "PKT 04000003 1 0 00 00 1e 17"); |
| 22 | push(@output, "key right\n"); |
22 | push(@output, "key right\n"); |
| 23 | 23 | ||
| 24 | push(@input , "PKT 04000003 1 0 00 00 1e 25"); |
24 | push(@input , "PKT 04000003 1 0 00 00 1e 25"); |
| 25 | push(@output, "key enter\n"); |
25 | push(@output, "key enter\n"); |
| 26 | 26 | ||
| 27 | push(@input , "PKT 04000003 1 0 00 00 1e 12"); |
27 | push(@input , "PKT 04000003 1 0 00 00 1e 12"); |
| 28 | push(@output, "key return\n"); |
28 | push(@output, "key return\n"); |
| 29 | 29 | ||
| 30 | print "---------------------------------\n"; |
30 | print "---------------------------------\n"; |
| 31 | print "MythTV Link 0.1\n"; |
31 | print "MythTV Link 0.1\n"; |
| 32 | print "Link between MythTV and canDeamon\n"; |
32 | print "Link between MythTV and canDeamon\n"; |
| 33 | print "---------------------------------\n"; |
33 | print "---------------------------------\n"; |
| 34 | 34 | ||
| 35 | print "Initiating sockets to MythTv and canDaemon..."; |
35 | print "Initiating sockets to MythTv and canDaemon..."; |
| 36 | $remoteMyth = IO::Socket::INET->new( |
36 | $remoteMyth = IO::Socket::INET->new( |
| 37 | Proto => "tcp", |
37 | Proto => "tcp", |
| 38 | PeerAddr => "localhost", |
38 | PeerAddr => "localhost", |
| 39 | PeerPort => "6546", |
39 | PeerPort => "6546", |
| 40 | ) |
40 | ) |
| 41 | or die " FAIL: cannot connect to port 6546 at localhost"; |
41 | or die " FAIL: cannot connect to port 6546 at localhost"; |
| 42 | 42 | ||
| 43 | $remote = IO::Socket::INET->new( |
43 | $remote = IO::Socket::INET->new( |
| 44 | Proto => "tcp", |
44 | Proto => "tcp", |
| 45 | PeerAddr => "localhost", |
45 | PeerAddr => "localhost", |
| 46 | PeerPort => "1200", |
46 | PeerPort => "1200", |
| 47 | ) |
47 | ) |
| 48 | or die " FAIL: cannot connect to port 1200 at localhost"; |
48 | or die " FAIL: cannot connect to port 1200 at localhost"; |
| 49 | 49 | ||
| 50 | print "Success!\n"; |
50 | print "Success!\n"; |
| 51 | 51 | ||
| 52 | print "Reading Macro Array..."; |
52 | print "Reading Macro Array..."; |
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | #get the lengths of the makro arrays: |
55 | #get the lengths of the makro arrays: |
| 56 | $input = @input; |
56 | $input = @input; |
| 57 | $output = @output; |
57 | $output = @output; |
| 58 | if ($input != $output) { |
58 | if ($input != $output) { |
| 59 | print "Input and output makros must be same length\n"; |
59 | print "Input and output makros must be same length\n"; |
| 60 | exit; |
60 | exit; |
| 61 | } |
61 | } |
| 62 | print "Success!\n"; |
62 | print "Success!\n"; |
| 63 | 63 | ||
| 64 | #read line from socket (blocking) |
64 | #read line from socket (blocking) |
| 65 | while ( $line = <$remote> ) { |
65 | while ( $line = <$remote> ) { |
| 66 | if (length($line) > 12) { |
66 | if (length($line) > 12) { |
| 67 | $id = hex(substr($line, 4, 8)); |
67 | $id = hex(substr($line, 4, 8)); |
| 68 | 68 | ||
| 69 | #macro function |
69 | #macro function |
| 70 | for ($i = 0; $i < $input; $i++) { |
70 | for ($i = 0; $i < $input; $i++) { |
| 71 | if ($input[$i] eq substr($line, 0, length($input[$i]))) { |
71 | if ($input[$i] eq substr($line, 0, length($input[$i]))) { |
| 72 | print $remoteMyth $output[$i]; |
72 | print $remoteMyth $output[$i]; |
| 73 | #print "Sending!!\n"; |
73 | #print "Sending!!\n"; |
| 74 | } |
74 | } |
| 75 | } |
75 | } |
| 76 | 76 | ||
| 77 | 77 | ||
| 78 | } |
78 | } |
| 79 | } |
79 | } |
| 80 | 80 | ||