Subversion Repositories HomeAutomation

Rev

Rev 2161 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2161 Rev 2164
Line 156... Line 156...
156
            die $response;
156
            die $response;
157
        }
157
        }
158
        print $response;
158
        print $response;
159
#atomd_disconnect($socket);
159
#atomd_disconnect($socket);
160
        $success = 0;
160
        $success = 0;
-
 
161
        $alreadyprintfull = 0;
161
        for ($count = 0; $count < 150; $count++)
162
        for ($count = 0; $count < 150; $count++)
162
        {
163
        {
163
            atomjs_write($socket, "Node_ProgramPollNative();\n");
164
            atomjs_write($socket, "Node_ProgramPollNative();\n");
164
            if (atomjs_read_line($socket) =~ m/true/)
165
            if (atomjs_read_line($socket) =~ m/true/)
165
            {
166
            {
-
 
167
                print progress_bar( 100, 100, 40, '=' );
166
                print "\033[32m" . $hwid . " started okay.\033[0m\n";
168
                print "\n\033[32m" . $hwid . " started okay.\033[0m\n";
167
                $success = 1;
169
                $success = 1;
168
                last;
170
                last;
169
            }
171
            }
-
 
172
            atomjs_write($socket, "Node_GetProgramProgress('".$hwid."');\n");
-
 
173
            $response = atomjs_read_line($socket);
-
 
174
            if ($response =~ m/Error/)
-
 
175
            {
-
 
176
                die $response;
-
 
177
            }
-
 
178
            $response =~ s/^\s+//;
-
 
179
            $response =~ s/\s+$//;
-
 
180
            if ($response > 99)
-
 
181
            {
-
 
182
                $response = 99;
-
 
183
            }
-
 
184
            #print $response."\n";
-
 
185
            print progress_bar( $response, 100, 40, '=' );
-
 
186
           
170
            usleep(200000);
187
            usleep(200000);
171
        }
188
        }
172
        if ($success == 0)
189
        if ($success == 0)
173
        {
190
        {
174
            print "\033[31mTimed out waiting for program to finish.\033[0m\n";
191
            print "\n\033[31mTimed out waiting for program to finish.\033[0m\n";
175
        }
192
        }
176
    }
193
    }
177
    else
194
    else
178
    {
195
    {
179
        open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n";
196
        open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n";
180
        @filecontents = <FP>;
197
        @filecontents = <FP>;
181
        close FP;
198
        close FP;
182
        $socket = atomd_initialize($hostname, $port);
199
        $socket = atomd_initialize($hostname, $port);
183
        usleep(100000);
200
        usleep(100000);
184
        atomd_kill_promt($socket);
201
        atomd_kill_promt($socket);
185
   
202
   
186
        #print "Sending Node_ClearHex\n";
203
        #print "Sending Node_ClearHex\n";
187
        atomd_send_command($socket, "Node_ClearHex");
204
        atomd_send_command($socket, "Node_ClearHex");
188
        atomd_kill_promt($socket);
205
        atomd_kill_promt($socket);
189
   
206
   
190
        my $linenums = 0;
207
        my $linenums = 0;
Line 206... Line 223...
206
#       exit($result);
223
#       exit($result);
207
    }
224
    }
208
}
225
}
209
 
226
 
210
exit(0);
227
exit(0);
-
 
228
 
-
 
229
# wget-style. routine by tachyon
-
 
230
# at http://tachyon.perlmonk.org/
-
 
231
sub progress_bar {
-
 
232
    my ( $got, $total, $width, $char ) = @_;
-
 
233
    $width ||= 25; $char ||= '=';
-
 
234
    my $num_width = length $total;
-
 
235
    sprintf "|%-${width}s| (%.2f%%)\r",
-
 
236
        $char x (($width-1)*$got/$total). '>',
-
 
237
        $got, $total, 100*$got/+$total;
-
 
238
}
-
 
239