Subversion Repositories HomeAutomation

Rev

Rev 1668 | Rev 1881 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1667 runge 1
#!/usr/bin/perl -w
2
################################################
3
#
4
# author: arune @ efnet
5
#
6
################################################
7
 
8
use IO::Socket;
9
use integer;
10
use threads;
11
use Cwd qw(abs_path);
12
use File::Basename;
13
use Getopt::Long;
14
 
15
$host = "localhost";
16
$port = 1201;
17
 
18
# Get hostname and port from command line arguments
19
if ( @ARGV > 0 ) {
20
    GetOptions( "host=s"    => \$host,          #
21
            "port=i"    => \$port,          #
22
                        );
23
}
24
 
25
my $path = dirname(abs_path($0));
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
$biosfile = "bios.inc";
36
open (FP, "+<".$biosfile) or die "Error: Cannot open file $biosfile\n";
37
@file = <FP>;
38
close FP;
39
 
40
 
41
# Check bios.inc for the settings that should be updated
42
my $foundidrow = 0;
43
my $foundmcurow = 0;
44
my $foundhfrow = 0;
45
my $foundlfrow = 0;
46
my $foundefrow = 0;
47
my $foundbootrow = 0;
48
foreach $file (@file) {
49
    if ($file =~ m/^NODE_HW_ID=/) {
50
        print "\nCurrent id-setting: ".$file."\n";
51
        $foundidrow = 1;
52
    }
53
    if ($file =~ m/^MCU=/) {
54
        $foundmcurow = 1;
55
    }
56
    if ($file =~ m/^HIGHFUSE=/) {
57
        $foundhfrow = 1;
58
    }
59
    if ($file =~ m/^LOWFUSE=/) {
60
        $foundlfrow = 1;
61
    }
62
    if ($file =~ m/^EXTFUSE=/) {
63
        $foundefrow = 1;
64
    }
65
    if ($file =~ m/^BOOT_START=/) {
66
        $foundbootrow = 1;
67
    }
68
}
69
if ($foundidrow == 0) {
70
    print "Error: Did not find NODE_HW_ID= in file $biosfile\n";
71
    exit 1;
72
}
73
if ($foundmcurow == 0) {
74
    print "Error: Did not find MCU= in file $biosfile\n";
75
    exit 1;
76
}
77
if ($foundhfrow == 0) {
78
    print "Error: Did not find HIGHFUSE= in file $biosfile\n";
79
    exit 1;
80
}
81
if ($foundlfrow == 0) {
82
    print "Error: Did not find LOWFUSE= in file $biosfile\n";
83
    exit 1;
84
}
85
if ($foundefrow == 0) {
86
    print "Error: Did not find EXTFUSE= in file $biosfile\n";
87
    exit 1;
88
}
89
if ($foundbootrow == 0) {
90
    print "Error: Did not find BOOT_START= in file $biosfile\n";
91
    exit 1;
92
}
93
 
94
my $hwid = "";
95
my @device = ();
96
 
97
print "/usr/bin/atomic -s $host -p $port -c \"Node_WaitForInformation\"\n";
1878 arune 98
#my @lines = qx{/usr/bin/atomic -s $host -p $port -c \"Node_GetInformation 0xB23F54EA\"};
99
my @lines = qx{/usr/bin/atomic -s $host -p $port -c \"Node_WaitForInformation\"};
1667 runge 100
 
101
foreach (@lines)
102
{
103
    my $line = $_;
104
    print($_);
105
    chomp($line);
106
 
107
    if (index($line, "Id") != -1)
108
    {
109
        my $temp = substr($line, index($line, ":") + 1);
110
 
111
        $temp =~ s/^\s+//;
112
        $temp =~ s/\s+$//;
113
 
114
        my @hwidChars = split(//, $temp);
115
        $hwid = $hwidChars[0]. $hwidChars[1]. $hwidChars[8]. $hwidChars[9]. $hwidChars[6]. $hwidChars[7]. $hwidChars[4]. $hwidChars[5]. $hwidChars[2]. $hwidChars[3];
116
 
117
        print "Setting HWID in bios.inc to ".$hwid."\n";
118
    }
1878 arune 119
    elsif (index($line, "Device Type") != -1)
1667 runge 120
    {
121
        $devicename = substr($line, index($line, ":") + 1);
122
 
123
        $devicename =~ s/^\s+//;
124
        $devicename =~ s/\s+$//;
125
 
126
        @device = $devices[0];
127
 
128
        foreach (@devices)
129
        {
1668 runge 130
            if (@{$_}[0] eq $devicename)
1667 runge 131
            {
132
                @device = @{$_};
133
            }
134
        }
135
 
1668 runge 136
        if ($device[0] eq "unknown")
1667 runge 137
        {
138
            print "\nWarning: Unknown device type, will not set MCU settings\n\n";
139
        }
140
        else
141
        {
142
            print "Setting device type to ".$device[0]."\n";
143
        }
144
    }
145
}
146
 
147
if ($hwid eq "")
148
{
149
    exit(1);
150
}
151
 
152
# Open bios.inc and replace all settings
153
open (FP, "<".$biosfile) or die "Cannot open file $biosfile\n";
154
@file = <FP>;
155
close FP;
156
open (FP, ">".$biosfile) or die "Cannot open file $biosfile\n";
157
foreach $file (@file) {
158
    $file =~ s/^NODE_HW_ID=.*/NODE_HW_ID=$hwid/g;
1668 runge 159
    if ($device[0] ne "unknown")
1667 runge 160
    {
161
        $file =~ s/^MCU=.*/MCU=$device[0]/g;
162
        $file =~ s/^HIGHFUSE=.*/HIGHFUSE=$device[1]/g;
163
        $file =~ s/^LOWFUSE=.*/LOWFUSE=$device[2]/g;
164
        $file =~ s/^EXTFUSE=.*/EXTFUSE=$device[3]/g;
165
        $file =~ s/^BOOT_START=.*/BOOT_START=$device[4]/g;
166
    }
167
    print FP $file;
168
}
169
close FP;
170
 
1668 runge 171
exit(0);
1667 runge 172
 
173