Rev 753 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 753 | arune | 1 | #!/usr/bin/perl -w |
| 2 | ################################################ |
||
| 3 | # |
||
| 4 | # This file should not be edited for settings |
||
| 5 | # use settings.pl for that |
||
| 6 | # |
||
| 7 | # author: arune @ efnet |
||
| 8 | # |
||
| 9 | ################################################ |
||
| 10 | |||
| 11 | use IO::Socket; |
||
| 12 | use integer; |
||
| 13 | use threads; |
||
| 14 | |||
| 15 | #for sending time msg: set to 1, else set to 0 |
||
| 16 | $sendtime = 0; |
||
| 17 | |||
| 18 | #for printing timestamps on printed messages: set to 1, else set to 0 |
||
| 19 | $timestamp = 1; |
||
| 20 | |||
| 21 | #define filters for id of messages, passed messages will be printed on stdout |
||
| 22 | @acceptmask_ones = (); |
||
| 23 | @acceptmask_zeros = (); |
||
| 24 | @denymask_ones = (); |
||
| 25 | @denymask_zeros = (); |
||
| 26 | |||
| 27 | @input = (); |
||
| 28 | @output = (); |
||
| 29 | |||
| 30 | $host = "localhost"; |
||
| 31 | $port = 1200; |
||
| 32 | $wiki = "http://localhost"; |
||
| 33 | $namespace = "homeautomation:livestats"; |
||
| 34 | $pagename = "default"; |
||
| 35 | |||
| 36 | require "settings.pl"; |
||
| 37 | require "dokuwiki.pl"; |
||
| 38 | #dokuwikipost("http://www.arune.se/temp/post.php", "homeautomation:livestats:arune", "texten att posta", "med summary"); |
||
| 39 | #dokuwikipost($wiki."/doku.php", $namespace.":".$pagename, "texten att posta", "med summary"); |
||
| 40 | |||
| 41 | $remote = IO::Socket::INET->new( |
||
| 42 | Proto => "tcp", |
||
| 43 | PeerAddr => $host, |
||
| 44 | PeerPort => $port, |
||
| 45 | ) |
||
| 46 | or die "cannot connect to port $port at $host"; |
||
| 47 | |||
| 48 | #read line from socket (blocking) |
||
| 49 | while ( $line = <$remote> ) { |
||
| 50 | if (length($line) > 12) { |
||
| 51 | $id = hex(substr($line, 4, 8)); |
||
| 52 | |||
| 53 | #macro function |
||
| 54 | for ($i = 0; $i < $input; $i++) { |
||
| 55 | if ($input[$i] eq substr($line, 0, length($input[$i]))) { |
||
| 56 | print $remote $output[$i]; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | $printed = 0; |
||
| 61 | $denied = 0; |
||
| 62 | #filter function |
||
| 63 | for ($i = 0; $i < $acceptmask_ones && !$printed && !$denied; $i++) { |
||
| 64 | if ((($id & $acceptmask_ones[$i])==$acceptmask_ones[$i]) && (($id & $acceptmask_zeros[$i])==0)) { |
||
| 65 | #check if denied by $denymask |
||
| 66 | for ($j = 0; $j < $denymask_ones; $j++) { |
||
| 67 | if ((($id & $denymask_ones[$j])==$denymask_ones[$j]) && (($id & $denymask_zeros[$j])==0)) { |
||
| 68 | #this message fits the denymask |
||
| 69 | $denied = 1; |
||
| 70 | } |
||
| 71 | |||
| 72 | } |
||
| 73 | |||
| 74 | if (!$denied) { |
||
| 75 | #print timestamp |
||
| 76 | if ($timestamp == 1) { |
||
| 77 | print localtime()." "; |
||
| 78 | } |
||
| 79 | print $line; |
||
| 80 | |||
| 81 | $printed = 1; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | sub sendTime { |
||
| 89 | $remote = IO::Socket::INET->new( |
||
| 90 | Proto => "tcp", |
||
| 91 | PeerAddr => $host, |
||
| 92 | PeerPort => $port, |
||
| 93 | ) |
||
| 94 | or die "cannot connect to port $port at $host"; |
||
| 95 | |||
| 96 | while (1) { |
||
| 97 | select(undef, undef, undef, 0.5); |
||
| 98 | print $remote "PKT 00000000 1 0"; |
||
| 99 | } |
||
| 100 | } |