#!/usr/bin/perl -w 

if (defined $ARGV[0]) {
    $nodeid = $ARGV[0];
} else {
    $nodeid = 1;
}
    
open OUT, ">/opt/tinyos-1.x/tos/system/tos.h" || 
    die "cannot write /opt/tinyos-1.x/tos/system/tos.h";
open IN, "/opt/tinyos-1.x/tos/system/tos.h.orig" || 
    die "cannot read /opt/tinyos-1.x/tos/system/tos.h.orig";

while (<IN>) {
    if (/uint16_t TOS_LOCAL_ADDRESS = 1;/) {
	print OUT "uint16_t TOS_LOCAL_ADDRESS = $nodeid;\n";
    } else {
	print OUT;
    }
}

close OUT;
close IN;

system("MIB510=/dev/ttyS0 make mica2 install");
