Rev 518 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 518 | Rev 568 | ||
|---|---|---|---|
| 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 | #for sending time msg: set to 1, else set to 0 |
6 | #for sending time msg: set to 1, else set to 0 |
| 7 | $sendtime = 0; |
7 | $sendtime = 0; |
| 8 | 8 | ||
| 9 | #for printing timestamps on printed messages: set to 1, else set to 0 |
9 | #for printing timestamps on printed messages: set to 1, else set to 0 |
| 10 | $timestamp = 1; |
10 | $timestamp = 1; |
| 11 | 11 | ||
| 12 | #define filters for id of messages, passed messages will be printed on stdout |
12 | #define filters for id of messages, passed messages will be printed on stdout |
| 13 | @acceptmask_ones = (0x00080000, 0x00240000, 0x00040000, 0x00280000); |
13 | @acceptmask_ones = (0x00080000, 0x00240000, 0x00040000, 0x00280000); |
| 14 | @acceptmask_zeros = (0xfff70000, 0xffdb0000, 0xfffb0000, 0xffd70000); |
14 | @acceptmask_zeros = (0xfff70000, 0xffdb0000, 0xfffb0000, 0xffd70000); |
| 15 | @denymask_ones = (); |
15 | @denymask_ones = (); |
| 16 | @denymask_zeros = (); |
16 | @denymask_zeros = (); |
| 17 | 17 | ||
| 18 | @input = (); |
18 | @input = (); |
| 19 | @output = (); |
19 | @output = (); |
| 20 | 20 | ||
| 21 | #define makros, when an input sting is sent on can this perl-script will send the corresponding output string |
21 | #define makros, when an input sting is sent on can this perl-script will send the corresponding output string |
| 22 | 22 | ||
| 23 | # Remote button 1 => desktoplamp toggle |
23 | # Remote button 1 => desktoplamp toggle |
| 24 | push(@input , "PKT 0409000a 1 0 00 00 05 01"); |
24 | push(@input , "PKT 0409000a 1 0 00 00 05 01"); |
| 25 | push(@output, "PKT 08008c00 1 0 03"); |
25 | push(@output, "PKT 08008c00 1 0 03"); |
| 26 | 26 | ||
| 27 | # Remote button 4 down => blinds darker |
27 | # Remote button 4 down => blinds darker |
| 28 | push(@input , "PKT 0409000a 1 0 00 00 05 04"); |
28 | push(@input , "PKT 0409000a 1 0 00 00 05 04"); |
| 29 | push(@output, "PKT 08010200 1 0 00 03"); |
29 | push(@output, "PKT 08010200 1 0 00 03"); |
| 30 | 30 | ||
| 31 | # Remote button 4 up => blinds stop |
31 | # Remote button 4 up => blinds stop |
| 32 | push(@input , "PKT 0409000a 1 0 0f 00 05 04"); |
32 | push(@input , "PKT 0409000a 1 0 0f 00 05 04"); |
| 33 | push(@output, "PKT 08010200 1 0 00 04"); |
33 | push(@output, "PKT 08010200 1 0 00 04"); |
| 34 | 34 | ||
| 35 | # Remote button 6 down => blinds lighter |
35 | # Remote button 6 down => blinds lighter |
| 36 | push(@input , "PKT 0409000a 1 0 00 00 05 06"); |
36 | push(@input , "PKT 0409000a 1 0 00 00 05 06"); |
| 37 | push(@output, "PKT 08010200 1 0 80 03"); |
37 | push(@output, "PKT 08010200 1 0 80 03"); |
| 38 | 38 | ||
| 39 | # Remote button 6 up => blinds stop |
39 | # Remote button 6 up => blinds stop |
| 40 | push(@input , "PKT 0409000a 1 0 0f 00 05 06"); |
40 | push(@input , "PKT 0409000a 1 0 0f 00 05 06"); |
| 41 | push(@output, "PKT 08010200 1 0 00 04"); |
41 | push(@output, "PKT 08010200 1 0 00 04"); |
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | $remote = IO::Socket::INET->new( |
44 | $remote = IO::Socket::INET->new( |
| 45 | Proto => "tcp", |
45 | Proto => "tcp", |
| 46 | PeerAddr => "localhost", |
46 | PeerAddr => "localhost", |
| 47 | PeerPort => "1200", |
47 | PeerPort => "1200", |
| 48 | ) |
48 | ) |
| 49 | or die "cannot connect to port 1200 at localhost"; |
49 | or die "cannot connect to port 1200 at localhost"; |
| 50 | 50 | ||
| 51 | if ($sendtime == 1) { |
51 | if ($sendtime == 1) { |
| 52 | $thr = threads->new(\&sendTime); |
52 | $thr = threads->new(\&sendTime); |
| 53 | $thr->detach; |
53 | $thr->detach; |
| 54 | } |
54 | } |
| 55 | 55 | ||
| 56 | $acceptmask_ones = @acceptmask_ones; |
56 | $acceptmask_ones = @acceptmask_ones; |
| 57 | $acceptmask_zeros = @acceptmask_zeros; |
57 | $acceptmask_zeros = @acceptmask_zeros; |
| 58 | if ($acceptmask_ones != $acceptmask_zeros) { |
58 | if ($acceptmask_ones != $acceptmask_zeros) { |
| 59 | print "Acceptmasks must be same length\n"; |
59 | print "Acceptmasks must be same length\n"; |
| 60 | exit; |
60 | exit; |
| 61 | } |
61 | } |
| 62 | 62 | ||
| 63 | $denymask_ones = @denymask_ones; |
63 | $denymask_ones = @denymask_ones; |
| 64 | $denymask_zeros = @denymask_zeros; |
64 | $denymask_zeros = @denymask_zeros; |
| 65 | if ($denymask_ones != $denymask_zeros) { |
65 | if ($denymask_ones != $denymask_zeros) { |
| 66 | print "Denymasks must be same length\n"; |
66 | print "Denymasks must be same length\n"; |
| 67 | exit; |
67 | exit; |
| 68 | } |
68 | } |
| 69 | 69 | ||
| 70 | #get the lengths of the makro arrays: |
70 | #get the lengths of the makro arrays: |
| 71 | $input = @input; |
71 | $input = @input; |
| 72 | $output = @output; |
72 | $output = @output; |
| 73 | if ($input != $output) { |
73 | if ($input != $output) { |
| 74 | print "Input and output makros must be same length\n"; |
74 | print "Input and output makros must be same length\n"; |
| 75 | exit; |
75 | exit; |
| 76 | } |
76 | } |
| 77 | 77 | ||
| 78 | #read line from socket (blocking) |
78 | #read line from socket (blocking) |
| 79 | while ( $line = <$remote> ) { |
79 | while ( $line = <$remote> ) { |
| 80 | if (length($line) > 12) { |
80 | if (length($line) > 12) { |
| 81 | $id = hex(substr($line, 4, 8)); |
81 | $id = hex(substr($line, 4, 8)); |
| 82 | 82 | ||
| 83 | #macro function |
83 | #macro function |
| 84 | for ($i = 0; $i < $input; $i++) { |
84 | for ($i = 0; $i < $input; $i++) { |
| 85 | if ($input[$i] eq substr($line, 0, length($input[$i]))) { |
85 | if ($input[$i] eq substr($line, 0, length($input[$i]))) { |
| 86 | print $remote $output[$i]; |
86 | print $remote $output[$i]; |
| 87 | } |
87 | } |
| 88 | } |
88 | } |
| 89 | 89 | ||
| 90 | $printed = 0; |
90 | $printed = 0; |
| 91 | $denied = 0; |
91 | $denied = 0; |
| 92 | #filter function |
92 | #filter function |
| 93 | for ($i = 0; $i < $acceptmask_ones && !$printed && !$denied; $i++) { |
93 | for ($i = 0; $i < $acceptmask_ones && !$printed && !$denied; $i++) { |
| 94 | if ((($id & $acceptmask_ones[$i])==$acceptmask_ones[$i]) && (($id & $acceptmask_zeros[$i])==0)) { |
94 | if ((($id & $acceptmask_ones[$i])==$acceptmask_ones[$i]) && (($id & $acceptmask_zeros[$i])==0)) { |
| 95 | #check if denied by $denymask |
95 | #check if denied by $denymask |
| 96 | for ($j = 0; $j < $denymask_ones; $j++) { |
96 | for ($j = 0; $j < $denymask_ones; $j++) { |
| 97 | if ((($id & $denymask_ones[$j])==$denymask_ones[$j]) && (($id & $denymask_zeros[$j])==0)) { |
97 | if ((($id & $denymask_ones[$j])==$denymask_ones[$j]) && (($id & $denymask_zeros[$j])==0)) { |
| 98 | #this message fits the denymask |
98 | #this message fits the denymask |
| 99 | $denied = 1; |
99 | $denied = 1; |
| 100 | } |
100 | } |
| 101 | 101 | ||
| 102 | } |
102 | } |
| 103 | 103 | ||
| 104 | if (!$denied) { |
104 | if (!$denied) { |
| 105 | #print timestamp |
105 | #print timestamp |
| 106 | if ($timestamp == 1) { |
106 | if ($timestamp == 1) { |
| 107 | print localtime()." "; |
107 | print localtime()." "; |
| 108 | } |
108 | } |
| 109 | print $line; |
109 | print $line; |
| 110 | 110 | ||
| 111 | $printed = 1; |
111 | $printed = 1; |
| 112 | } |
112 | } |
| 113 | } |
113 | } |
| 114 | } |
114 | } |
| 115 | } |
115 | } |
| 116 | } |
116 | } |
| 117 | 117 | ||
| 118 | sub sendTime { |
118 | sub sendTime { |
| 119 | $remote = IO::Socket::INET->new( |
119 | $remote = IO::Socket::INET->new( |
| 120 | Proto => "tcp", |
120 | Proto => "tcp", |
| 121 | PeerAddr => "localhost", |
121 | PeerAddr => "localhost", |
| 122 | PeerPort => "1200", |
122 | PeerPort => "1200", |
| 123 | ) |
123 | ) |
| 124 | or die "cannot connect to port 1200 at localhost"; |
124 | or die "cannot connect to port 1200 at localhost"; |
| 125 | 125 | ||
| 126 | while (1) { |
126 | while (1) { |
| 127 | select(undef, undef, undef, 0.5); |
127 | select(undef, undef, undef, 0.5); |
| 128 | print $remote "PKT 00000000 1 0"; |
128 | print $remote "PKT 00000000 1 0"; |
| 129 | } |
129 | } |
| 130 | } |
130 | } |
| 131 | 131 | ||