Subversion Repositories HomeAutomation

Rev

Rev 964 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  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. #Set autoflush on ( http://www.perlmonks.org/?node_id=20590 )
  12. $| = 1;
  13.  
  14. use IO::Socket;
  15. use integer;
  16. use threads;
  17.  
  18. #for printing timestamps on printed messages: set to 1, else set to 0
  19. $timestamp = 1;
  20.  
  21. $host = "localhost";
  22. $port = 1200;
  23.  
  24. require "settings.pl";
  25.  
  26. $remote = IO::Socket::INET->new(
  27.                     Proto    => "tcp",
  28.                     PeerAddr => $host,
  29.                     PeerPort => $port,
  30.                 )
  31.                or die "cannot connect to port $port at $host";
  32.  
  33. print "Connected to canDaemon. Printf strings on can will be printed below.\n";
  34. print "Don't forget to terminate your strings with '\\n'.\n";
  35.  
  36. $newline = 1;
  37. #read line from socket (blocking)
  38. while ( $line = <$remote> ) {
  39.     if (length($line) > 12) {
  40.         #$idhex = substr($line, 4, 8);
  41.         $id = hex(substr($line, 4, 8));
  42.         if ($id == hex("1f000080")) {
  43.             #@data = ();
  44.             if ($newline == 1) {
  45.                 if ($timestamp == 1) {
  46.                     print localtime()." ";
  47.                 }
  48.                 $newline = 0;
  49.             }
  50.             for ($i = 17; $i < length($line); $i=$i+3) {
  51.                 print pack("c", hex(substr($line, $i, 2)));
  52.                 if (hex(substr($line, $i, 2)) == 10) {
  53.                     $newline = 1;
  54.                 }
  55.             }
  56.         }
  57.     }
  58. }
  59.  
  60.