Subversion Repositories HomeAutomation

Rev

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