Rev 2157 | Rev 2159 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2157 | Rev 2158 | ||
|---|---|---|---|
| 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 | { |
|
| - | 84 | if ($port == 1203) |
|
| - | 85 | { |
|
| - | 86 | $socket = atomd_initialize($hostname, $port); |
|
| - | 87 | atomjs_write($socket, "Node_ResetNative('".$hwid."');\n"); |
|
| - | 88 | print atomjs_read_line($socket); |
|
| - | 89 | for ($count = 0; $count < 15; $count++) |
|
| - | 90 | { |
|
| - | 91 | atomjs_write($socket, "Node_ResetPollNative();\n"); |
|
| - | 92 | if (atomjs_read_line($socket) =~ m/true/) |
|
| - | 93 | { |
|
| - | 94 | print "\033[32m" . $hwid . " started okay.\033[0m\n"; |
|
| - | 95 | last; |
|
| - | 96 | } |
|
| - | 97 | usleep(200000); |
|
| - | 98 | } |
|
| - | 99 | } |
|
| - | 100 | else |
|
| 83 | { |
101 | { |
| 84 | $socket = atomd_initialize($hostname, $port); |
102 | $socket = atomd_initialize($hostname, $port); |
| - | 103 | ||
| 85 | usleep(100000); |
104 | usleep(100000); |
| 86 | atomd_kill_promt($socket); |
105 | atomd_kill_promt($socket); |
| 87 | # atomjs_write("Node_Reset('".$hwid."')"); |
- | |
| 88 | atomd_send_command($socket, "Node_Reset $hwid"); |
106 | atomd_send_command($socket, "Node_Reset $hwid"); |
| 89 | print atomd_read_command_response($socket); |
107 | print atomd_read_command_response($socket); |
| 90 | exit(0); |
- | |
| 91 | #my $result = system("atomic -s $hostname -p $port -c \"Node_Reset $hwid\""); |
108 | #my $result = system("atomic -s $hostname -p $port -c \"Node_Reset $hwid\""); |
| 92 | #exit($result); |
109 | #exit($result); |
| - | 110 | } |
|
| 93 | } |
111 | } |
| - | 112 | else |
|
| - | 113 | { |
|
| - | 114 | if ($port == 1203) |
|
| - | 115 | { |
|
| - | 116 | open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n"; |
|
| - | 117 | @filecontents = <FP>; |
|
| - | 118 | close FP; |
|
| - | 119 | $socket = atomd_initialize($hostname, $port); |
|
| - | 120 | ||
| - | 121 | atomjs_write($socket, "Node_ProgramNative('".$hwid."', '".$bios."'"); |
|
| - | 122 | # print "Node_ProgramNative('".$hwid."', '".$bios."'"; |
|
| - | 123 | foreach $filerow (@filecontents) { |
|
| - | 124 | $filerow =~ s/^\s+//; |
|
| - | 125 | $filerow =~ s/\s+$//; |
|
| - | 126 | atomjs_write($socket, ", '" . $filerow . "'"); |
|
| - | 127 | print ", '".$filerow."'"; |
|
| - | 128 | } |
|
| - | 129 | atomjs_write($socket, ");\n"); |
|
| - | 130 | # print ");\n"; |
|
| - | 131 | } |
|
| 94 | else |
132 | else |
| 95 | { |
133 | { |
| 96 | open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n"; |
134 | open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n"; |
| 97 | @filecontents = <FP>; |
135 | @filecontents = <FP>; |
| 98 | close FP; |
136 | close FP; |
| 99 | - | ||
| 100 | $socket = atomd_initialize($hostname, $port); |
137 | $socket = atomd_initialize($hostname, $port); |
| 101 | usleep(100000); |
138 | usleep(100000); |
| 102 | atomd_kill_promt($socket); |
139 | atomd_kill_promt($socket); |
| 103 | 140 | ||
| 104 | #print "Sending Node_ClearHex\n"; |
141 | #print "Sending Node_ClearHex\n"; |
| 105 | atomd_send_command($socket, "Node_ClearHex"); |
142 | atomd_send_command($socket, "Node_ClearHex"); |
| 106 | atomd_kill_promt($socket); |
143 | atomd_kill_promt($socket); |
| 107 | 144 | ||
| 108 | my $linenums = 0; |
145 | my $linenums = 0; |
| 109 | foreach $filerow (@filecontents) { |
146 | foreach $filerow (@filecontents) { |
| 110 | #print "Sending Node_AppendHex $filerow \n"; |
147 | #print "Sending Node_AppendHex $filerow \n"; |
| - | 148 | #$filerow =~ s/^\s+//; |
|
| - | 149 | #$filerow =~ s/\s+$//; |
|
| 111 | atomd_send_command($socket, "Node_AppendHex $filerow"); |
150 | atomd_send_command($socket, "Node_AppendHex $filerow"); |
| 112 | atomd_kill_promt($socket); |
151 | atomd_kill_promt($socket); |
| 113 | $linenums += 1; |
152 | $linenums += 1; |
| 114 | } |
153 | } |
| 115 | #print "Sending Node_ProgramHex $hwid $bios $linenums \n"; |
154 | #print "Sending Node_ProgramHex $hwid $bios $linenums \n"; |
| 116 | atomd_send_command($socket, "Node_ProgramHex $hwid $bios $linenums"); |
155 | atomd_send_command($socket, "Node_ProgramHex $hwid $bios $linenums"); |
| 117 | # atomd_kill_promt($socket); |
- | |
| 118 | - | ||
| 119 | #atomd_send_command($socket, "Node_Program $hwid $bios $filename"); |
- | |
| 120 | 156 | ||
| 121 | print atomd_read_command_response($socket); |
157 | print atomd_read_command_response($socket); |
| 122 | exit(0); |
- | |
| 123 | 158 | ||
| 124 | # my $result = system("atomic -s $hostname -p $port -c \"Node_Program $hwid $bios $filename\""); |
159 | # my $result = system("atomic -s $hostname -p $port -c \"Node_Program $hwid $bios $filename\""); |
| 125 | # exit($result); |
160 | # exit($result); |
| 126 | } |
161 | } |
| 127 | 162 | ||
| 128 | exit(0); |
163 | exit(0); |
| 129 | 164 | ||