Subversion Repositories HomeAutomation

Rev

Rev 1877 | Rev 1890 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #!/usr/bin/perl
  2.  
  3. # Written by Mattias Runge 2008-2010
  4.  
  5. use Cwd 'abs_path';
  6. use File::Basename;
  7.  
  8. $| = 1;
  9.  
  10. $numArgs = $#ARGV + 1;
  11.  
  12. my $hostname = "localhost";
  13. my $port = 1201;
  14. my $filename = "";
  15. my $hwid = "";
  16. my $bios = 0;
  17. my $reset = "false";
  18.  
  19. foreach $argnum (0 .. $#ARGV)
  20. {
  21.     if ($ARGV[$argnum] eq "-h")
  22.     {
  23.         $hostname = $ARGV[$argnum+1];
  24.         next;
  25.  
  26.     }
  27.     elsif ($ARGV[$argnum] eq "-p")
  28.     {
  29.         $port = $ARGV[$argnum+1];
  30.         next;
  31.  
  32.     }
  33.     elsif ($ARGV[$argnum] eq "-i")
  34.     {
  35.         $hwid = $ARGV[$argnum+1];
  36.         next;
  37.  
  38.     }
  39.     elsif ($ARGV[$argnum] eq "-f")
  40.     {
  41.         $filename = abs_path($ARGV[$argnum+1]);
  42.         next;
  43.  
  44.     }
  45.     elsif ($ARGV[$argnum] eq "-b")
  46.     {
  47.         $bios = 1;
  48.     }
  49.     elsif ($ARGV[$argnum] eq "-r")
  50.     {
  51.         $reset = "true";
  52.     }
  53. }
  54.  
  55. if ($hwid eq "")
  56. {
  57.     die "You must specify a hardware id!\n";
  58.     exit 1;
  59. }
  60.  
  61. my $path = dirname(abs_path($0));
  62.  
  63. # Read atom functions from separate file
  64. if (-e $path."/setConfig/AtomLib.pl") {
  65.     require $path."/setConfig/AtomLib.pl";
  66. } else {
  67.     print "Error: No AtomLib.pl was found in ".$path.". \n\n";
  68.     exit 1;
  69. }
  70.  
  71.  
  72. #0x14f90d1f to 0x1f0df914
  73. @hwidChars = split(//, $hwid);
  74. $hwid = $hwidChars[0]. $hwidChars[1]. uc($hwidChars[8]. $hwidChars[9]. $hwidChars[6]. $hwidChars[7]. $hwidChars[4]. $hwidChars[5]. $hwidChars[2]. $hwidChars[3]);
  75.  
  76. print "atomDude settings:\n";
  77. print "Hardware id: " . $hwid . "\n";
  78. print "Atom address: " . $hostname . ":" . $port . "\n";
  79. print "Hexfile: " . $filename . "\n";
  80. print "Parameters: " . "\n";
  81.  
  82. if ($reset eq "true" && $filename eq "")
  83. {
  84.     $socket = atomd_initialize($hostname, $port);
  85.     atomd_send_command($socket, "Node_Reset $hwid");
  86.     print atomd_read_command_response($socket);
  87.     exit(1);
  88.     #my $result = system("atomic -s $hostname -p $port -c \"Node_Reset $hwid\"");
  89.     #exit($result);
  90. }
  91. else
  92. {
  93.     $socket = atomd_initialize($hostname, $port);
  94.     atomd_send_command($socket, "Node_Program $hwid $bios $filename");
  95.     print atomd_read_command_response($socket);
  96.     exit(1);
  97.     #my $result = system("atomic -s $hostname -p $port -c \"Node_Program $hwid $bios $filename\"");
  98.     #    exit($result);
  99. }
  100.  
  101. exit(0);
  102.