Rev 1640 | Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1638 | arune | 1 | #!/usr/bin/perl -w |
| 2 | ################################################ |
||
| 3 | # |
||
| 4 | # This file should not be edited for settings |
||
| 5 | # use settings.pl for that |
||
| 6 | # |
||
| 7 | # author: arune @ efnet |
||
| 8 | # |
||
| 9 | ################################################ |
||
| 10 | |||
| 11 | use IO::Socket; |
||
| 12 | use integer; |
||
| 13 | use threads; |
||
| 14 | use Cwd qw(abs_path); |
||
| 15 | use File::Basename; |
||
| 16 | use Getopt::Long; |
||
| 17 | |||
| 18 | $host = "localhost"; |
||
| 19 | $port = 1200; |
||
| 20 | |||
| 21 | if ( @ARGV > 0 ) { |
||
| 22 | GetOptions( "host=s" => \$host, # |
||
| 23 | "port=i" => \$port, # |
||
| 24 | ); |
||
| 25 | } |
||
| 26 | |||
| 27 | |||
| 28 | my $path = dirname(abs_path($0)); |
||
| 29 | |||
| 30 | $remote = IO::Socket::INET->new( |
||
| 31 | Proto => "tcp", |
||
| 32 | PeerAddr => $host, |
||
| 33 | PeerPort => $port, |
||
| 34 | ) |
||
| 35 | or die "Error: Cannot connect to port $port at $host\n"; |
||
| 36 | |||
| 37 | $biosfile = "bios.inc"; |
||
| 38 | open (FP, "+<".$biosfile) or die "Error: Cannot open file $biosfile\n"; |
||
| 39 | @file = <FP>; |
||
| 40 | close FP; |
||
| 41 | $foundrow = 0; |
||
| 42 | foreach $file (@file) { |
||
| 43 | if ($file =~ m/^NODE_HW_ID=/) { |
||
| 44 | $foundrow = 1; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | if ($foundrow == 0) { |
||
| 48 | print "Error: Did not find NODE_HW_ID= in file $biosfile\n"; |
||
| 49 | exit 1; |
||
| 50 | } |
||
| 51 | |||
| 52 | #print "\n"; |
||
| 53 | print "Connect your node to the CAN-network (disconnect it first if it's already connected)\n"; |
||
| 54 | print "Abort with Ctrl+c\n"; |
||
| 55 | #read line from socket (blocking) |
||
| 56 | while ( $line = <$remote> ) { |
||
| 57 | #PKT 00087f00 1 0 39 13 01 20 78 56 34 12 |
||
| 58 | if (length($line) > 12) { |
||
| 59 | $id = hex(substr($line, 4, 8)); |
||
| 60 | $class = ($id & 0x1E000000)>>25; |
||
| 61 | if ($class == 0) { |
||
| 62 | $nmttype = ($id & 0x00FF0000)>>16; |
||
| 63 | if ($nmttype == 8) { |
||
| 64 | print $line.""; |
||
| 65 | #print $class." ".$nmttype."\n"; |
||
| 66 | if (length($line) < 40) { |
||
| 67 | print "Error: A node was started but it did not have a HWID\n"; |
||
| 68 | exit 1; |
||
| 69 | } |
||
| 70 | $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); |
||
| 72 | $hwidhex = sprintf("%08x", $hwid); |
||
| 73 | print "Setting HWID in bios.inc to 0x".$hwidhex."\n"; |
||
| 74 | |||
| 75 | open (FP, "<".$biosfile) or die "Cannot open file $biosfile\n"; |
||
| 76 | @file = <FP>; |
||
| 77 | close FP; |
||
| 78 | open (FP, ">".$biosfile) or die "Cannot open file $biosfile\n"; |
||
| 79 | foreach $file (@file) { |
||
| 80 | $file =~ s/^NODE_HW_ID=.*/NODE_HW_ID=0x$hwidhex/g; |
||
| 81 | print FP $file; |
||
| 82 | } |
||
| 83 | close FP; |
||
| 84 | |||
| 85 | exit 0; |
||
| 86 | |||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | } |
||
| 91 | } |
||
| 92 |