Rev 2159 | Rev 2164 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2159 | Rev 2161 | ||
|---|---|---|---|
| 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 | ############################## RESET ############################## |
|
| 82 | if ($reset eq "true" && $filename eq "") |
83 | if ($reset eq "true" && $filename eq "") |
| 83 | { |
84 | { |
| 84 | if ($port == 1203) |
85 | if ($port == 1203) |
| 85 | { |
86 | { |
| 86 | $socket = atomd_initialize($hostname, $port); |
87 | $socket = atomd_initialize($hostname, $port); |
| 87 | atomjs_write($socket, "Node_ResetNative('".$hwid."');\n"); |
88 | atomjs_write($socket, "Node_ResetNative('".$hwid."');\n"); |
| 88 |
|
89 | $response = atomjs_read_line($socket); |
| - | 90 | if ($response =~ m/Error/) |
|
| - | 91 | { |
|
| - | 92 | die $response; |
|
| - | 93 | } |
|
| - | 94 | print $response; |
|
| - | 95 | ||
| 89 | $success = 0; |
96 | $success = 0; |
| 90 | for ($count = 0; $count < 15; $count++) |
97 | for ($count = 0; $count < 15; $count++) |
| 91 | { |
98 | { |
| 92 | atomjs_write($socket, "Node_ResetPollNative();\n"); |
99 | atomjs_write($socket, "Node_ResetPollNative();\n"); |
| 93 | if (atomjs_read_line($socket) =~ m/true/) |
100 | if (atomjs_read_line($socket) =~ m/true/) |
| 94 | { |
101 | { |
| 95 | print "\033[32m" . $hwid . " started okay.\033[0m\n"; |
102 | print "\033[32m" . $hwid . " started okay.\033[0m\n"; |
| 96 | $success = 1; |
103 | $success = 1; |
| 97 | last; |
104 | last; |
| 98 | } |
- | |
| 99 | usleep(200000); |
- | |
| 100 | } |
- | |
| 101 | if ($success == 0) |
- | |
| 102 | { |
- | |
| 103 | print "\033[31mTimed out waiting for reset.\033[0m\n"; |
- | |
| 104 | } |
- | |
| 105 | } |
105 | } |
| - | 106 | usleep(200000); |
|
| 106 |
|
107 | } |
| - | 108 | if ($success == 0) |
|
| 107 | { |
109 | { |
| - | 110 | print "\033[31mTimed out waiting for reset.\033[0m\n"; |
|
| - | 111 | } |
|
| - | 112 | } |
|
| - | 113 | else |
|
| - | 114 | { |
|
| 108 | $socket = atomd_initialize($hostname, $port); |
115 | $socket = atomd_initialize($hostname, $port); |
| 109 | 116 | ||
| 110 | usleep(100000); |
117 | usleep(100000); |
| 111 | atomd_kill_promt($socket); |
118 | atomd_kill_promt($socket); |
| 112 | atomd_send_command($socket, "Node_Reset $hwid"); |
119 | atomd_send_command($socket, "Node_Reset $hwid"); |
| 113 | print atomd_read_command_response($socket); |
120 | print atomd_read_command_response($socket); |
| 114 | #my $result = system("atomic -s $hostname -p $port -c \"Node_Reset $hwid\""); |
121 | #my $result = system("atomic -s $hostname -p $port -c \"Node_Reset $hwid\""); |
| 115 | #exit($result); |
122 | #exit($result); |
| 116 | } |
123 | } |
| 117 | } |
124 | } |
| - | 125 | ############################## REPROGRAM ############################## |
|
| 118 | else |
126 | else |
| 119 | { |
127 | { |
| 120 | if ($port == 1203) |
128 | if ($port == 1203) |
| 121 | { |
129 | { |
| 122 | open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n"; |
130 | open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n"; |
| 123 | @filecontents = <FP>; |
131 | @filecontents = <FP>; |
| 124 | close FP; |
132 | close FP; |
| 125 | $socket = atomd_initialize($hostname, $port); |
133 | $socket = atomd_initialize($hostname, $port); |
| 126 | atomjs_write($socket, "Node_ClearHex();\n"); |
134 | atomjs_write($socket, "Node_ClearHex();\n"); |
| 127 | atomjs_read_line($socket); |
135 | atomjs_read_line($socket); |
| 128 | my $linenums = 0; |
136 | my $linenums = 0; |
| 129 | foreach $filerow (@filecontents) |
137 | foreach $filerow (@filecontents) |
| 130 | { |
138 | { |
| 131 | $filerow =~ s/^\s+//; |
139 | $filerow =~ s/^\s+//; |
| 132 | $filerow =~ s/\s+$//; |
140 | $filerow =~ s/\s+$//; |
| 133 | $linenums += 1; |
141 | $linenums += 1; |
| 134 | $command = "Node_AppendHexNative('".$filerow."');\n"; |
142 | $command = "Node_AppendHexNative('".$filerow."');\n"; |
| 135 | atomjs_write($socket, $command); |
143 | atomjs_write($socket, $command); |
| 136 | atomjs_read_line($socket); |
144 | $response = atomjs_read_line($socket); |
| - | 145 | if ($response =~ m/Error/) |
|
| - | 146 | { |
|
| - | 147 | die $response; |
|
| - | 148 | } |
|
| 137 | } |
149 | } |
| 138 | $command = "Node_ProgramNative('".$hwid."', '".$bios."', '".$linenums."');\n"; |
150 | $command = "Node_ProgramNative('".$hwid."', '".$bios."', '".$linenums."');\n"; |
| 139 | atomjs_write($socket, $command); |
151 | atomjs_write($socket, $command); |
| 140 | #print $command; |
152 | #print $command; |
| 141 |
|
153 | $response = atomjs_read_line($socket); |
| - | 154 | if ($response =~ m/Error/) |
|
| - | 155 | { |
|
| - | 156 | die $response; |
|
| - | 157 | } |
|
| - | 158 | print $response; |
|
| 142 |
|
159 | #atomd_disconnect($socket); |
| 143 |
|
160 | $success = 0; |
| 144 |
|
161 | for ($count = 0; $count < 150; $count++) |
| 145 |
|
162 | { |
| 146 |
|
163 | atomjs_write($socket, "Node_ProgramPollNative();\n"); |
| 147 |
|
164 | if (atomjs_read_line($socket) =~ m/true/) |
| 148 |
|
165 | { |
| 149 |
|
166 | print "\033[32m" . $hwid . " started okay.\033[0m\n"; |
| 150 |
|
167 | $success = 1; |
| 151 |
|
168 | last; |
| 152 |
|
169 | } |
| 153 |
|
170 | usleep(200000); |
| 154 |
|
171 | } |
| 155 |
|
172 | if ($success == 0) |
| 156 |
|
173 | { |
| 157 |
|
174 | print "\033[31mTimed out waiting for program to finish.\033[0m\n"; |
| 158 |
|
175 | } |
| 159 | } |
176 | } |
| 160 | else |
177 | else |
| 161 | { |
178 | { |
| 162 | open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n"; |
179 | open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n"; |
| 163 | @filecontents = <FP>; |
180 | @filecontents = <FP>; |
| 164 | close FP; |
181 | close FP; |
| 165 | $socket = atomd_initialize($hostname, $port); |
182 | $socket = atomd_initialize($hostname, $port); |
| 166 | usleep(100000); |
183 | usleep(100000); |
| 167 | atomd_kill_promt($socket); |
184 | atomd_kill_promt($socket); |
| 168 | 185 | ||
| 169 | #print "Sending Node_ClearHex\n"; |
186 | #print "Sending Node_ClearHex\n"; |
| 170 | atomd_send_command($socket, "Node_ClearHex"); |
187 | atomd_send_command($socket, "Node_ClearHex"); |
| 171 | atomd_kill_promt($socket); |
188 | atomd_kill_promt($socket); |
| 172 | 189 | ||
| 173 | my $linenums = 0; |
190 | my $linenums = 0; |
| 174 | foreach $filerow (@filecontents) |
191 | foreach $filerow (@filecontents) |
| 175 | { |
192 | { |
| 176 | #print "Sending Node_AppendHex $filerow \n"; |
193 | #print "Sending Node_AppendHex $filerow \n"; |
| 177 | #$filerow =~ s/^\s+//; |
194 | #$filerow =~ s/^\s+//; |
| 178 | #$filerow =~ s/\s+$//; |
195 | #$filerow =~ s/\s+$//; |
| 179 | atomd_send_command($socket, "Node_AppendHex $filerow"); |
196 | atomd_send_command($socket, "Node_AppendHex $filerow"); |
| 180 | atomd_kill_promt($socket); |
197 | atomd_kill_promt($socket); |
| 181 | $linenums += 1; |
198 | $linenums += 1; |
| 182 | } |
199 | } |
| 183 | #print "Sending Node_ProgramHex $hwid $bios $linenums \n"; |
200 | #print "Sending Node_ProgramHex $hwid $bios $linenums \n"; |
| 184 | atomd_send_command($socket, "Node_ProgramHex $hwid $bios $linenums"); |
201 | atomd_send_command($socket, "Node_ProgramHex $hwid $bios $linenums"); |
| 185 | 202 | ||
| 186 | print atomd_read_command_response($socket); |
203 | print atomd_read_command_response($socket); |
| 187 | 204 | ||
| 188 | # my $result = system("atomic -s $hostname -p $port -c \"Node_Program $hwid $bios $filename\""); |
205 | # my $result = system("atomic -s $hostname -p $port -c \"Node_Program $hwid $bios $filename\""); |
| 189 | # exit($result); |
206 | # exit($result); |
| 190 | } |
207 | } |
| 191 | } |
208 | } |
| 192 | 209 | ||
| 193 | exit(0); |
210 | exit(0); |
| 194 | 211 | ||