Rev 1640 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1640 | Rev 1643 | ||
|---|---|---|---|
| Line 107... | Line 107... | ||
| 107 | 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"; |
| 108 | print "Abort with Ctrl+c\n"; |
108 | print "Abort with Ctrl+c\n"; |
| 109 | #read line from socket (blocking) |
109 | #read line from socket (blocking) |
| 110 | while ( $line = <$remote> ) { |
110 | while ( $line = <$remote> ) { |
| 111 | #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 |
| 112 |
|
112 | if (length($line) > 12) { |
| - | 113 | # Find can id |
|
| 113 |
|
114 | $id = hex(substr($line, 4, 8)); |
| - | 115 | # Find can id class |
|
| 114 |
|
116 | $class = ($id & 0x1E000000)>>25; |
| - | 117 | # If class is nmt |
|
| 115 |
|
118 | if ($class == 0) { |
| - | 119 | # Find nmt type |
|
| 116 |
|
120 | $nmttype = ($id & 0x00FF0000)>>16; |
| - | 121 | # If nmt type is bios started |
|
| 117 |
|
122 | if ($nmttype == 8) { |
| 118 |
|
123 | print $line.""; |
| 119 | #print $class." ".$nmttype."\n"; |
- | |
| 120 |
|
124 | if (length($line) < 40) { |
| 121 |
|
125 | print "Error: A node was started but it did not have a HWID\n"; |
| 122 |
|
126 | exit 1; |
| 123 |
|
127 | } |
| - | 128 | ||
| - | 129 | # Find hw id from data field |
|
| 124 |
|
130 | $hwid = (hex(substr($line, 38, 2)) << 24) + (hex(substr($line, 35, 2)) << 16) |
| 125 |
|
131 | + (hex(substr($line, 32, 2)) << 8) + (hex(substr($line, 29, 2)) << 0); |
| 126 |
|
132 | $hwidhex = sprintf("%08x", $hwid); |
| 127 |
|
133 | 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 | } |
- | |
| 139 | 134 | ||
| - | 135 | # Find device type from data field |
|
| - | 136 | $devtype = hex(substr($line, 26, 2)); |
|
| - | 137 | if ($devtype == 0) |
|
| - | 138 | { |
|
| - | 139 | print "\nWarning: Unknown device type, will not set MCU settings\n\n"; |
|
| - | 140 | } |
|
| - | 141 | elsif ($devtype < $numdevices) |
|
| - | 142 | { |
|
| - | 143 | print "Setting device type to ".$devices[$devtype][0]."\n"; |
|
| - | 144 | $devsettings = 1; |
|
| - | 145 | } |
|
| - | 146 | ||
| - | 147 | # Open bios.inc and replace all settings |
|
| 140 |
|
148 | open (FP, "<".$biosfile) or die "Cannot open file $biosfile\n"; |
| 141 |
|
149 | @file = <FP>; |
| 142 |
|
150 | close FP; |
| 143 |
|
151 | open (FP, ">".$biosfile) or die "Cannot open file $biosfile\n"; |
| 144 |
|
152 | foreach $file (@file) { |
| 145 |
|
153 | $file =~ s/^NODE_HW_ID=.*/NODE_HW_ID=0x$hwidhex/g; |
| 146 |
|
154 | if ($devsettings==1) |
| 147 |
|
155 | { |
| 148 |
|
156 | $file =~ s/^MCU=.*/MCU=$devices[$devtype][0]/g; |
| 149 |
|
157 | $file =~ s/^HIGHFUSE=.*/HIGHFUSE=$devices[$devtype][1]/g; |
| 150 |
|
158 | $file =~ s/^LOWFUSE=.*/LOWFUSE=$devices[$devtype][2]/g; |
| 151 |
|
159 | $file =~ s/^EXTFUSE=.*/EXTFUSE=$devices[$devtype][3]/g; |
| 152 |
|
160 | $file =~ s/^BOOT_START=.*/BOOT_START=$devices[$devtype][4]/g; |
| 153 |
|
161 | } |
| 154 |
|
162 | print FP $file; |
| 155 |
|
163 | } |
| 156 |
|
164 | close FP; |
| 157 | 165 | ||
| 158 |
|
166 | exit 0; |
| 159 | 167 | } |
|
| 160 |
|
168 | } |
| 161 | } |
- | |
| 162 | - | ||
| 163 | } |
169 | } |
| 164 | } |
170 | } |
| 165 | 171 | ||