#!/usr/bin/perl -w
################################################
#
# This file should not be edited for settings
# use settings.pl for that
#
# author: arune @ efnet
#
################################################
use IO::Socket;
use integer;
use threads;
use File::Basename;
use Getopt::Long;
$host = "localhost";
$port = 1200;
if ( @ARGV > 0 ) {
GetOptions( "host=s" => \$host, #
"port=i" => \$port, #
);
}
my $path = dirname(abs_path($0));
$remote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => $host,
PeerPort => $port,
)
or die "Error: Cannot connect to port $port at $host\n";
$biosfile = "bios.inc";
open (FP
, "+<".$biosfile) or die "Error: Cannot open file $biosfile\n";
@file = <FP>;
$foundrow = 0;
foreach $file (@file) {
if ($file =~ m/^NODE_HW_ID=/) {
$foundrow = 1;
}
}
if ($foundrow == 0) {
print "Error: Did not find NODE_HW_ID= in file $biosfile\n";
}
#print "\n";
print "Connect your node to the CAN-network (disconnect it first if it's already connected)\n";
print "Abort with Ctrl+c\n";
#read line from socket (blocking)
while ( $line = <$remote> ) {
#PKT 00087f00 1 0 39 13 01 20 78 56 34 12
$class = ($id & 0x1E000000)>>25;
if ($class == 0) {
$nmttype = ($id & 0x00FF0000)>>16;
if ($nmttype == 8) {
#print $class." ".$nmttype."\n";
print "Error: A node was started but it did not have a HWID\n";
}
print "Setting HWID in bios.inc to 0x".$hwidhex."\n";
open (FP
, "<".$biosfile) or die "Cannot open file $biosfile\n";
@file = <FP>;
open (FP
, ">".$biosfile) or die "Cannot open file $biosfile\n";
foreach $file (@file) {
$file =~ s/^NODE_HW_ID=.*/NODE_HW_ID=0x$hwidhex/g;
}
}
}
}
}