Subversion Repositories HomeAutomation

Rev

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

  1. #!/usr/bin/perl
  2.  
  3. # Written by Mattias Runge 20089
  4.  
  5. use IO::Socket;
  6.  
  7. $| = 1;
  8.  
  9. $numArgs = $#ARGV + 1;
  10.  
  11. my $hostname = "localhost";
  12. my $port = 1202;
  13. my $filename = "";
  14. my $hwid = "";
  15. my $bios = "false";
  16. my $reset = "false";
  17.  
  18. foreach $argnum (0 .. $#ARGV)
  19. {
  20.     if ($ARGV[$argnum] eq "-h")
  21.     {
  22.         $hostname = $ARGV[$argnum+1];
  23.         next;
  24.  
  25.     }
  26.     elsif ($ARGV[$argnum] eq "-p")
  27.     {
  28.         $port = $ARGV[$argnum+1];
  29.         next;
  30.  
  31.     }
  32.     elsif ($ARGV[$argnum] eq "-i")
  33.     {
  34.         $hwid = $ARGV[$argnum+1];
  35.         next;
  36.  
  37.     }
  38.     elsif ($ARGV[$argnum] eq "-f")
  39.     {
  40.         $filename = $ARGV[$argnum+1];
  41.         next;
  42.  
  43.     }
  44.     elsif ($ARGV[$argnum] eq "-b")
  45.     {
  46.         $bios = "true";
  47.     }
  48.     elsif ($ARGV[$argnum] eq "-r")
  49.     {
  50.         $reset = "true";
  51.     }
  52. }
  53.  
  54. if ($hwid eq "")
  55. {
  56.     die "You must specify a hardware id!\n";
  57.     exit 1;
  58. }
  59.  
  60. #0x14f90d1f to 0x1f0df914
  61. @hwidChars = split(//, $hwid);
  62. $hwid = @hwidChars[0]. @hwidChars[1]. @hwidChars[8]. @hwidChars[9]. @hwidChars[6]. @hwidChars[7]. @hwidChars[4]. @hwidChars[5]. @hwidChars[2]. @hwidChars[3];
  63.  
  64. print "atomDude settings:\n";
  65. print "Hardware id: " . $hwid . "\n";
  66. print "Atom address: " . $hostname . ":" . $port . "\n";
  67. print "Hexfile: " . $filename . "\n";
  68. print "Parameters: " . "\n";
  69.  
  70. my $sock = new IO::Socket::INET(
  71.                 PeerAddr => $hostname,
  72.                 PeerPort => $port,
  73.                 Proto => 'tcp'
  74.                 );
  75. die "Could not create socket: $!\n" unless $sock;
  76. print "Connected to Atom\n";
  77.  
  78. if ($filename ne "")
  79. {
  80.     open(FILE, $filename) || die("Could not open file!");
  81.     @fileData=<FILE>;
  82.     close(FILE);
  83.     print "Hexfile loaded\n";
  84.  
  85.     print $sock "programNode('", $hwid, "','";
  86.  
  87.     foreach $line (@fileData)
  88.     {
  89.         print $sock $line;
  90.     }
  91.  
  92.     print $sock "', ", $bios, ");\n";
  93.  
  94.     my $pLoop = 1;
  95.  
  96.     while ($pLoop eq 1)
  97.     {
  98.         $sock->recv($text, 128);
  99.        
  100.         if (rindex($text, "STOP") ne -1)
  101.         {
  102.             print $text;
  103.             $pLoop = 0;
  104.         }
  105.         elsif ($text ne '')
  106.         {
  107.             print $text;
  108.         }
  109.         else
  110.         {
  111.             print "Connection closed by other side!\n";
  112.             close($sock);
  113.             exit 1;
  114.         }
  115.     }
  116. }
  117.  
  118. if ($reset eq "true")
  119. {
  120.     print $sock "resetNode('", $hwid, "');\n";
  121.  
  122.     my $rLoop = 1;
  123.    
  124.     while ($rLoop eq 1)
  125.     {
  126.         $sock->recv($text, 128);
  127.         print $text;
  128.        
  129.         if (rindex($text, "Success") ne -1)
  130.         {
  131.             $rLoop = 0;
  132.         }
  133.         elsif (rindex($text, "Failed") ne -1)
  134.         {
  135.             close($sock);
  136.             exit 1;
  137.         }
  138.         elsif ($text eq '')
  139.         {
  140.             print "Connection closed by other side!\n";
  141.             close($sock);
  142.             exit 1;
  143.         }
  144.     }
  145. }
  146.  
  147. close($sock);
  148. exit 0;
  149.