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