Rev 1638 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1638 | Rev 1640 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | #!/usr/bin/perl -w |
1 | #!/usr/bin/perl -w |
| 2 | ################################################ |
2 | ################################################ |
| 3 | # |
- | |
| 4 | # This file should not be edited for settings |
- | |
| 5 | # use settings.pl for that |
- | |
| 6 | # |
3 | # |
| 7 | # author: arune @ efnet |
4 | # author: arune @ efnet |
| 8 | # |
5 | # |
| 9 | ################################################ |
6 | ################################################ |
| 10 | 7 | ||
| Line 16... | Line 13... | ||
| 16 | use Getopt::Long; |
13 | use Getopt::Long; |
| 17 | 14 | ||
| 18 | $host = "localhost"; |
15 | $host = "localhost"; |
| 19 | $port = 1200; |
16 | $port = 1200; |
| 20 | 17 | ||
| - | 18 | # Get hostname and port from command line arguments |
|
| 21 | if ( @ARGV > 0 ) { |
19 | if ( @ARGV > 0 ) { |
| 22 | GetOptions( "host=s" => \$host, # |
20 | GetOptions( "host=s" => \$host, # |
| 23 | "port=i" => \$port, # |
21 | "port=i" => \$port, # |
| 24 | ); |
22 | ); |
| 25 | } |
23 | } |
| 26 | - | ||
| 27 | 24 | ||
| 28 | my $path = dirname(abs_path($0)); |
25 | my $path = dirname(abs_path($0)); |
| 29 | 26 | ||
| - | 27 | # Read devices from separate file |
|
| - | 28 | if (-e $path."/devices.pl") { |
|
| - | 29 | require $path."/devices.pl"; |
|
| - | 30 | } else { |
|
| - | 31 | print "Error: No devices.pl was found in ".$path.". \n\n"; |
|
| - | 32 | exit 1; |
|
| - | 33 | } |
|
| - | 34 | ||
| - | 35 | # Length of devices array |
|
| - | 36 | $numdevices=@devices; |
|
| - | 37 | ||
| - | 38 | # Connect to candaemon |
|
| 30 | $remote = IO::Socket::INET->new( |
39 | $remote = IO::Socket::INET->new( |
| 31 | Proto => "tcp", |
40 | Proto => "tcp", |
| 32 | PeerAddr => $host, |
41 | PeerAddr => $host, |
| 33 | PeerPort => $port, |
42 | PeerPort => $port, |
| 34 | ) |
43 | ) |
| 35 | or die "Error: Cannot connect to port $port at $host\n"; |
44 | or die "Error: Cannot connect to port $port at $host\n"; |
| 36 | 45 | ||
| 37 | $biosfile = "bios.inc"; |
46 | $biosfile = "bios.inc"; |
| 38 | open (FP, "+<".$biosfile) or die "Error: Cannot open file $biosfile\n"; |
47 | open (FP, "+<".$biosfile) or die "Error: Cannot open file $biosfile\n"; |
| 39 | @file = <FP>; |
48 | @file = <FP>; |
| 40 | close FP; |
49 | close FP; |
| - | 50 | ||
| - | 51 | # Check bios.inc for the settings that should be updated |
|
| - | 52 | my $foundidrow = 0; |
|
| - | 53 | my $foundmcurow = 0; |
|
| - | 54 | my $foundhfrow = 0; |
|
| - | 55 | my $foundlfrow = 0; |
|
| 41 |
|
56 | my $foundefrow = 0; |
| - | 57 | my $foundbootrow = 0; |
|
| 42 | foreach $file (@file) { |
58 | foreach $file (@file) { |
| 43 | if ($file =~ m/^NODE_HW_ID=/) { |
59 | if ($file =~ m/^NODE_HW_ID=/) { |
| - | 60 | print "\nCurrent id-setting: ".$file."\n"; |
|
| 44 |
|
61 | $foundidrow = 1; |
| - | 62 | } |
|
| - | 63 | if ($file =~ m/^MCU=/) { |
|
| - | 64 | $foundmcurow = 1; |
|
| - | 65 | } |
|
| - | 66 | if ($file =~ m/^HIGHFUSE=/) { |
|
| - | 67 | $foundhfrow = 1; |
|
| - | 68 | } |
|
| - | 69 | if ($file =~ m/^LOWFUSE=/) { |
|
| - | 70 | $foundlfrow = 1; |
|
| 45 | } |
71 | } |
| - | 72 | if ($file =~ m/^EXTFUSE=/) { |
|
| - | 73 | $foundefrow = 1; |
|
| - | 74 | } |
|
| - | 75 | if ($file =~ m/^BOOT_START=/) { |
|
| - | 76 | $foundbootrow = 1; |
|
| - | 77 | } |
|
| 46 | } |
78 | } |
| 47 | if ( |
79 | if ($foundidrow == 0) { |
| 48 | print "Error: Did not find NODE_HW_ID= in file $biosfile\n"; |
80 | print "Error: Did not find NODE_HW_ID= in file $biosfile\n"; |
| 49 | exit 1; |
81 | exit 1; |
| 50 | } |
82 | } |
| - | 83 | if ($foundmcurow == 0) { |
|
| - | 84 | print "Error: Did not find MCU= in file $biosfile\n"; |
|
| - | 85 | exit 1; |
|
| - | 86 | } |
|
| - | 87 | if ($foundhfrow == 0) { |
|
| - | 88 | print "Error: Did not find HIGHFUSE= in file $biosfile\n"; |
|
| - | 89 | exit 1; |
|
| - | 90 | } |
|
| - | 91 | if ($foundlfrow == 0) { |
|
| - | 92 | print "Error: Did not find LOWFUSE= in file $biosfile\n"; |
|
| - | 93 | exit 1; |
|
| - | 94 | } |
|
| - | 95 | if ($foundefrow == 0) { |
|
| - | 96 | print "Error: Did not find EXTFUSE= in file $biosfile\n"; |
|
| - | 97 | exit 1; |
|
| - | 98 | } |
|
| - | 99 | if ($foundbootrow == 0) { |
|
| - | 100 | print "Error: Did not find BOOT_START= in file $biosfile\n"; |
|
| - | 101 | exit 1; |
|
| - | 102 | } |
|
| - | 103 | ||
| - | 104 | # Define variable to know if a device was found |
|
| - | 105 | my $devsettings=0; |
|
| 51 | 106 | ||
| 52 | #print "\n"; |
- | |
| 53 | print "Connect your node to the CAN-network (disconnect it first if it's already connected)\n"; |
107 | print "Connect your node to the CAN-network (disconnect it first if it's already connected)\n"; |
| 54 | print "Abort with Ctrl+c\n"; |
108 | print "Abort with Ctrl+c\n"; |
| 55 | #read line from socket (blocking) |
109 | #read line from socket (blocking) |
| 56 | while ( $line = <$remote> ) { |
110 | while ( $line = <$remote> ) { |
| 57 | #PKT 00087f00 1 0 39 13 01 20 78 56 34 12 |
111 | #PKT 00087f00 1 0 39 13 01 20 78 56 34 12 |
| Line 69... | Line 123... | ||
| 69 | } |
123 | } |
| 70 | $hwid = (hex(substr($line, 38, 2))<<24)+(hex(substr($line, 35, 2))<<16)+ |
124 | $hwid = (hex(substr($line, 38, 2))<<24)+(hex(substr($line, 35, 2))<<16)+ |
| 71 | (hex(substr($line, 32, 2))<<8)+(hex(substr($line, 29, 2))<<0); |
125 | (hex(substr($line, 32, 2))<<8)+(hex(substr($line, 29, 2))<<0); |
| 72 | $hwidhex = sprintf("%08x", $hwid); |
126 | $hwidhex = sprintf("%08x", $hwid); |
| 73 | print "Setting HWID in bios.inc to 0x".$hwidhex."\n"; |
127 | print "Setting HWID in bios.inc to 0x".$hwidhex."\n"; |
| - | 128 | ||
| - | 129 | $devtype = hex(substr($line, 26, 2)); |
|
| - | 130 | if ($devtype == 0) |
|
| - | 131 | { |
|
| - | 132 | print "\nWarning: Unknown device type, will not set MCU settings\n\n"; |
|
| - | 133 | } |
|
| - | 134 | elsif ($devtype < $numdevices) |
|
| - | 135 | { |
|
| - | 136 | print "Setting device type to ".$devices[$devtype][0]."\n"; |
|
| - | 137 | $devsettings = 1; |
|
| - | 138 | } |
|
| 74 | 139 | ||
| 75 | open (FP, "<".$biosfile) or die "Cannot open file $biosfile\n"; |
140 | open (FP, "<".$biosfile) or die "Cannot open file $biosfile\n"; |
| 76 | @file = <FP>; |
141 | @file = <FP>; |
| 77 | close FP; |
142 | close FP; |
| 78 | open (FP, ">".$biosfile) or die "Cannot open file $biosfile\n"; |
143 | open (FP, ">".$biosfile) or die "Cannot open file $biosfile\n"; |
| 79 | foreach $file (@file) { |
144 | foreach $file (@file) { |
| 80 | $file =~ s/^NODE_HW_ID=.*/NODE_HW_ID=0x$hwidhex/g; |
145 | $file =~ s/^NODE_HW_ID=.*/NODE_HW_ID=0x$hwidhex/g; |
| - | 146 | if ($devsettings==1) |
|
| - | 147 | { |
|
| - | 148 | $file =~ s/^MCU=.*/MCU=$devices[$devtype][0]/g; |
|
| - | 149 | $file =~ s/^HIGHFUSE=.*/HIGHFUSE=$devices[$devtype][1]/g; |
|
| - | 150 | $file =~ s/^LOWFUSE=.*/LOWFUSE=$devices[$devtype][2]/g; |
|
| - | 151 | $file =~ s/^EXTFUSE=.*/EXTFUSE=$devices[$devtype][3]/g; |
|
| - | 152 | $file =~ s/^BOOT_START=.*/BOOT_START=$devices[$devtype][4]/g; |
|
| - | 153 | } |
|
| 81 | print FP $file; |
154 | print FP $file; |
| 82 | } |
155 | } |
| 83 | close FP; |
156 | close FP; |
| 84 | 157 | ||
| 85 | exit 0; |
158 | exit 0; |