Subversion Repositories HomeAutomation

Rev

Rev 1913 | Rev 2157 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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