Subversion Repositories HomeAutomation

Rev

Rev 1640 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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