0
|
1 |
#
|
|
2 |
# Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
#
|
|
18 |
# Initial Contributors:
|
|
19 |
# Nokia Corporation - initial contribution.
|
|
20 |
#
|
|
21 |
# Contributors:
|
|
22 |
#
|
|
23 |
# Description:
|
|
24 |
#
|
|
25 |
|
|
26 |
package Symbian::StatAPI;
|
|
27 |
require 5.000;
|
|
28 |
use Win32::API;
|
|
29 |
use Win32::TieRegistry(Delimiter=>"/");
|
|
30 |
use IO::File;
|
|
31 |
use File::Basename;
|
|
32 |
use LWP::Simple;
|
|
33 |
use LWP::UserAgent;
|
|
34 |
use HTTP::Request;
|
|
35 |
use HTTP::Response;
|
|
36 |
use Exporter;
|
|
37 |
use vars qw (@ISA @EXPORT $VERSION);
|
|
38 |
@ISA = qw(Exporter);
|
|
39 |
@EXPORT = qw(
|
|
40 |
&set_dll_folder
|
|
41 |
&set_working_folder
|
|
42 |
&initialise
|
|
43 |
&get_version
|
|
44 |
&set_connection_logging
|
|
45 |
&close_connection_logging
|
|
46 |
&get_device_log_file
|
|
47 |
&set_screenshot_dir
|
|
48 |
&get_last_error
|
|
49 |
&connect_to_target
|
|
50 |
&connect_to_target_multithreaded
|
|
51 |
&disconnect_from_target
|
|
52 |
&set_command_delay
|
|
53 |
&set_image_verification
|
|
54 |
&set_command_logging
|
|
55 |
&get_screenshot
|
|
56 |
&get_device_info
|
|
57 |
&touch_screen
|
|
58 |
&start_application
|
|
59 |
&start_program
|
|
60 |
&open_application
|
|
61 |
&close_application
|
|
62 |
&basic_key_sequence
|
|
63 |
&control_keystroke
|
|
64 |
&combination_keystroke
|
|
65 |
&pause
|
|
66 |
&start_eshell
|
|
67 |
&stop_eshell
|
|
68 |
©_commonfile_to_target
|
|
69 |
©_testfile_to_target
|
|
70 |
©_buildfile_to_target
|
|
71 |
&move_from_target
|
|
72 |
©_from_target
|
|
73 |
&remove_unwanted_file
|
|
74 |
&send_command_file
|
|
75 |
&send_raw_command
|
|
76 |
&hold_key
|
|
77 |
&remove_file
|
|
78 |
&create_folder
|
|
79 |
&remove_folder);
|
|
80 |
|
|
81 |
|
|
82 |
##########################################################################
|
|
83 |
# AUTO-GENERATED BLOCK - DO NOT MODIFY
|
|
84 |
##########################################################################
|
|
85 |
$VERSION = 3.3;
|
|
86 |
##########################################################################
|
|
87 |
|
|
88 |
|
|
89 |
# global variables
|
|
90 |
my $FUNCTION; # dll function entrypoint
|
|
91 |
my $dllname; # dll to call
|
|
92 |
my $def_connection_type; # default (global) connection type
|
|
93 |
my $def_codetype; # default (global) code type
|
|
94 |
my $lasterror; # last error thrown
|
|
95 |
my $imagedir; # image retrieve location
|
|
96 |
my $logfile; # log file to write to
|
|
97 |
my $senddir; # temp send directory
|
|
98 |
my $recvdir; # temp receive directory
|
|
99 |
my $workdir; # stat working directory
|
|
100 |
my $statdir; # stat dll location
|
|
101 |
my $loglevel; # internal logging level
|
|
102 |
|
|
103 |
#TMS required vars
|
|
104 |
my $httpserver; # http server for downloading files
|
|
105 |
my $runno; # needed to obtain build location to download files
|
|
106 |
my $commondir; # common files temp dir
|
|
107 |
my $builddir; # build files location
|
|
108 |
|
|
109 |
|
|
110 |
################################################################
|
|
111 |
# exported functions
|
|
112 |
# Come in 2 levels: Global - apply to all connections,
|
|
113 |
# Local - apply to individual connections
|
|
114 |
################################################################
|
|
115 |
|
|
116 |
################################################################
|
|
117 |
# GLOBAL ENTRYPOINTS
|
|
118 |
# Apply to all connections
|
|
119 |
################################################################
|
|
120 |
|
|
121 |
################################################################
|
|
122 |
# set_dll_folder(<dll folder>);
|
|
123 |
#
|
|
124 |
# Required parameters:
|
|
125 |
# $statdir e.g. "C:\epoc32\tools\STAT";
|
|
126 |
#
|
|
127 |
################################################################
|
|
128 |
sub set_dll_folder
|
|
129 |
{
|
|
130 |
my @cmdline = @_;
|
|
131 |
my $cmdref = \@cmdline;
|
|
132 |
my $dir = $cmdref->[0];
|
|
133 |
|
|
134 |
$statdir = $dir;
|
|
135 |
|
|
136 |
return 1;
|
|
137 |
}
|
|
138 |
|
|
139 |
|
|
140 |
################################################################
|
|
141 |
# set_working_folder(<working folder>);
|
|
142 |
#
|
|
143 |
# Required parameters:
|
|
144 |
# $statdir e.g. "C:\apps\STAT";
|
|
145 |
#
|
|
146 |
################################################################
|
|
147 |
sub set_working_folder
|
|
148 |
{
|
|
149 |
my @cmdline = @_;
|
|
150 |
my $cmdref = \@cmdline;
|
|
151 |
my $dir = $cmdref->[0];
|
|
152 |
|
|
153 |
$workdir = $dir;
|
|
154 |
|
|
155 |
return 1;
|
|
156 |
}
|
|
157 |
|
|
158 |
|
|
159 |
################################################################
|
|
160 |
# Must be the first function called
|
|
161 |
# initialise(@ARGV);
|
|
162 |
# initialise(<dll name>, <connection type>, <code type>, <log level>, <log file>, <send dir>, <recv dir>, <common dir>, <httpserver>, <runno>, <builddir>);
|
|
163 |
#
|
|
164 |
# Required parameters:
|
|
165 |
# $dllname e.g. STAT.DLL;
|
|
166 |
#
|
|
167 |
# Needed only if connection/code types won't change throughout the script
|
|
168 |
# $def_connection_type e.g. 2 (Symbian Serial)
|
|
169 |
# $def_codetype e.g. COM2
|
|
170 |
#
|
|
171 |
# Needed only for logging
|
|
172 |
# $loglevel # internal logging level:
|
|
173 |
# 0 = terse
|
|
174 |
# 1 = noraml
|
|
175 |
# 2 = verbose
|
|
176 |
# 3 = Perl output redirected to log file
|
|
177 |
# $logfile e.g. C:\Apps\Stat\LogFiles\StatPerl.log;
|
|
178 |
#
|
|
179 |
# Needed only for sending/receiving files (must end in 'slash')
|
|
180 |
# $senddir e.g. auto/12267/send/
|
|
181 |
# $recvdir e.g. auto/12267/recv/
|
|
182 |
#
|
|
183 |
# Needed only for sending common files to target (TMS only - must end in 'slash')
|
|
184 |
# $commondir e.g. auto/12267/common/
|
|
185 |
|
|
186 |
# Needed only for sending build files to target (TMS only)
|
|
187 |
# $httpserver e.g. http://lon-adminpool01:8080/AutoTest
|
|
188 |
# $runno e.g. 150
|
|
189 |
# $builddir e.g. auto/12267/build/ (must end in 'slash')
|
|
190 |
#
|
|
191 |
################################################################
|
|
192 |
sub initialise
|
|
193 |
{
|
|
194 |
my @cmdline = @_;
|
|
195 |
my $cmdref = \@cmdline;
|
|
196 |
$dllname = $cmdref->[0];
|
|
197 |
$def_connection_type = $cmdref->[1];
|
|
198 |
$def_codetype = $cmdref->[2];
|
|
199 |
$loglevel = $cmdref->[3];
|
|
200 |
$logfile = $cmdref->[4];
|
|
201 |
$senddir = $cmdref->[5];
|
|
202 |
$recvdir = $cmdref->[6];
|
|
203 |
$commondir = $cmdref->[7];
|
|
204 |
$httpserver = $cmdref->[8];
|
|
205 |
$runno = $cmdref->[9];
|
|
206 |
$builddir = $cmdref->[10];
|
|
207 |
|
|
208 |
# required parameter
|
|
209 |
if (!$dllname)
|
|
210 |
{
|
|
211 |
$lasterror = "DLL name not supplied!";
|
|
212 |
Line(get_last_error());
|
|
213 |
return 0;
|
|
214 |
}
|
|
215 |
|
|
216 |
# adjust log level if necessary
|
|
217 |
if ($loglevel < 0)
|
|
218 |
{
|
|
219 |
$loglevel = 0;
|
|
220 |
}
|
|
221 |
if ($loglevel > 3)
|
|
222 |
{
|
|
223 |
$loglevel = 3;
|
|
224 |
}
|
|
225 |
|
|
226 |
# redirect output to log file if we've supplied one, else will go to screen
|
|
227 |
if ($logfile and ($loglevel eq 3))
|
|
228 |
{
|
|
229 |
print "Redirecting output to [$logfile]...\n";
|
|
230 |
open(STDOUT, ">> $logfile");
|
|
231 |
open(STDERR, ">> $logfile");
|
|
232 |
}
|
|
233 |
|
|
234 |
# reverse '/' to '\\' in filenames
|
|
235 |
$senddir =~ s/\//\\/g;
|
|
236 |
$recvdir =~ s/\//\\/g;
|
|
237 |
$commondir =~ s/\//\\/g;
|
|
238 |
$builddir =~ s/\//\\/g;
|
|
239 |
|
|
240 |
if (!$workdir)
|
|
241 |
{
|
|
242 |
$workdir = "C:\\apps\\stat";
|
|
243 |
}
|
|
244 |
Line("Working directory: $workdir\n");
|
|
245 |
|
|
246 |
if (!$statdir)
|
|
247 |
{
|
|
248 |
$statdir = "C:\\epoc32\\tools\\STAT";
|
|
249 |
}
|
|
250 |
Line("Stat directory: $statdir\n");
|
|
251 |
|
|
252 |
Line("Initialising STAT API:\n DLLName [$dllname]\n Default Connection [$def_connection_type]\n Default Code Type [$def_codetype]\n Log Level [$loglevel]\n LogFile [$logfile]\n Send [$senddir]\n Recv [$recvdir]\n Common [$commondir]\n HTTPServer [$httpserver]\n Run No [$runno]\n Build [$builddir]\n");
|
|
253 |
return 1;
|
|
254 |
}
|
|
255 |
|
|
256 |
|
|
257 |
################################################################
|
|
258 |
# Get the version of the dll
|
|
259 |
################################################################
|
|
260 |
sub get_version
|
|
261 |
{
|
|
262 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdVersion", [V], P);
|
|
263 |
if (defined($FUNCTION))
|
|
264 |
{
|
|
265 |
$ret = $FUNCTION->Call();
|
|
266 |
if ($ret)
|
|
267 |
{
|
|
268 |
return $ret;
|
|
269 |
}
|
|
270 |
else
|
|
271 |
{
|
|
272 |
$lasterror = "Version could not be established\n";
|
|
273 |
}
|
|
274 |
}
|
|
275 |
else
|
|
276 |
{
|
|
277 |
$lasterror = "Function StdVersion not found\n";
|
|
278 |
}
|
|
279 |
|
|
280 |
Line(get_last_error());
|
|
281 |
return 0;
|
|
282 |
}
|
|
283 |
|
|
284 |
|
|
285 |
################################################################
|
|
286 |
# Set logging of stat connection attempts
|
|
287 |
# param0: logfile
|
|
288 |
################################################################
|
|
289 |
sub set_connection_logging
|
|
290 |
{
|
|
291 |
Line("Setting connection logging...");
|
|
292 |
if ($loglevel and $logfile)
|
|
293 |
{
|
|
294 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdSetConnectionLogging", [P], I);
|
|
295 |
if (defined($FUNCTION))
|
|
296 |
{
|
|
297 |
Line("Logging to $logfile");
|
|
298 |
$ret = $FUNCTION->Call($logfile);
|
|
299 |
if ($ret)
|
|
300 |
{
|
|
301 |
return 1;
|
|
302 |
}
|
|
303 |
else
|
|
304 |
{
|
|
305 |
GetDllError(0);
|
|
306 |
}
|
|
307 |
}
|
|
308 |
else
|
|
309 |
{
|
|
310 |
$lasterror = "Function StdSetConnectionLogging not found\n";
|
|
311 |
}
|
|
312 |
}
|
|
313 |
else
|
|
314 |
{
|
|
315 |
$lasterror = "Logging disabled or logfile not supplied";
|
|
316 |
}
|
|
317 |
|
|
318 |
Line(get_last_error());
|
|
319 |
return 0;
|
|
320 |
}
|
|
321 |
|
|
322 |
|
|
323 |
################################################################
|
|
324 |
# Set logging of stat connection attempts
|
|
325 |
# param0: logfile
|
|
326 |
################################################################
|
|
327 |
sub close_connection_logging
|
|
328 |
{
|
|
329 |
Line("Closing connection logging...");
|
|
330 |
if ($loglevel and $logfile)
|
|
331 |
{
|
|
332 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdCloseConnectionLogging", [], V);
|
|
333 |
if (defined($FUNCTION))
|
|
334 |
{
|
|
335 |
Line("Stopping logging to $logfile");
|
|
336 |
$FUNCTION->Call();
|
|
337 |
return 1;
|
|
338 |
}
|
|
339 |
else
|
|
340 |
{
|
|
341 |
$lasterror = "Function StdCloseConnectionLogging not found\n";
|
|
342 |
}
|
|
343 |
}
|
|
344 |
else
|
|
345 |
{
|
|
346 |
$lasterror = "Logging disabled or logfile not supplied";
|
|
347 |
}
|
|
348 |
|
|
349 |
Line(get_last_error());
|
|
350 |
return 0;
|
|
351 |
}
|
|
352 |
|
|
353 |
|
|
354 |
################################################################
|
|
355 |
# Retrieve the device log file to our log and truncate it at that point on the device
|
|
356 |
################################################################
|
|
357 |
sub get_device_log_file
|
|
358 |
{
|
|
359 |
Line("Retrieving log file...");
|
|
360 |
my @cmdline = @_;
|
|
361 |
my $cmdref = \@cmdline;
|
|
362 |
my $hndl = $cmdref->[0];
|
|
363 |
|
|
364 |
if ($loglevel and $logfile)
|
|
365 |
{
|
|
366 |
if ($hndl)
|
|
367 |
{
|
|
368 |
if (SendCommand($hndl, "<B><G><E>"))
|
|
369 |
{
|
|
370 |
return 1;
|
|
371 |
}
|
|
372 |
}
|
|
373 |
else
|
|
374 |
{
|
|
375 |
$lasterror = "Handle not supplied";
|
|
376 |
}
|
|
377 |
}
|
|
378 |
else
|
|
379 |
{
|
|
380 |
$lasterror = "Logging disabled or logfile not supplied";
|
|
381 |
}
|
|
382 |
|
|
383 |
Line(get_last_error());
|
|
384 |
return 0;
|
|
385 |
}
|
|
386 |
|
|
387 |
|
|
388 |
################################################################
|
|
389 |
# Set the output directory for screenshots
|
|
390 |
################################################################
|
|
391 |
sub set_screenshot_dir
|
|
392 |
{
|
|
393 |
Line("Setting screenshot dir...");
|
|
394 |
my @cmdline = @_;
|
|
395 |
my $cmdref = \@cmdline;
|
|
396 |
my $dir = $cmdref->[0];
|
|
397 |
if ($dir)
|
|
398 |
{
|
|
399 |
$imagedir = $dir;
|
|
400 |
|
|
401 |
# reverse '/' to '\\' for DOS
|
|
402 |
$imagedir =~ s/\//\\/g;
|
|
403 |
|
|
404 |
Line("Directory ($imagedir)");
|
|
405 |
return 1;
|
|
406 |
}
|
|
407 |
|
|
408 |
$lasterror = "Directory not supplied";
|
|
409 |
Line(get_last_error());
|
|
410 |
return 0;
|
|
411 |
}
|
|
412 |
|
|
413 |
|
|
414 |
################################################################
|
|
415 |
# Get the last error that occurred
|
|
416 |
################################################################
|
|
417 |
sub get_last_error
|
|
418 |
{
|
|
419 |
# add prefix if not one already
|
|
420 |
if (!(substr($lasterror, 0, 8) =~ "ERROR : "))
|
|
421 |
{
|
|
422 |
$lasterror = "ERROR : $lasterror";
|
|
423 |
}
|
|
424 |
|
|
425 |
return $lasterror;
|
|
426 |
}
|
|
427 |
|
|
428 |
|
|
429 |
################################################################
|
|
430 |
# LOCAL ENTRYPOINTS
|
|
431 |
# Apply to individual connection
|
|
432 |
################################################################
|
|
433 |
|
|
434 |
################################################################
|
|
435 |
# Connect to the target device
|
|
436 |
################################################################
|
|
437 |
sub connect_to_target
|
|
438 |
{
|
|
439 |
Line("Connecting to $statdir/$dllname...");
|
|
440 |
my @cmdline = @_;
|
|
441 |
my $cmdref = \@cmdline;
|
|
442 |
my $connection_type = $cmdref->[0];
|
|
443 |
my $codetype = $cmdref->[1];
|
|
444 |
|
|
445 |
# if we haven't supplied a connection type through here, maybe it was defined during initialise()
|
|
446 |
if (!$connection_type)
|
|
447 |
{
|
|
448 |
$connection_type = $def_connection_type;
|
|
449 |
}
|
|
450 |
|
|
451 |
# if we haven't supplied a code type through here, maybe it was defined during initialise()
|
|
452 |
if (!$codetype)
|
|
453 |
{
|
|
454 |
$codetype = $def_codetype;
|
|
455 |
}
|
|
456 |
|
|
457 |
if ($connection_type)
|
|
458 |
{
|
|
459 |
if ($codetype)
|
|
460 |
{
|
|
461 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdConnect", [I, P, P, P], I);
|
|
462 |
if (defined($FUNCTION))
|
|
463 |
{
|
|
464 |
Line("Connecting ($connection_type, $codetype)...");
|
|
465 |
my $hndl = $FUNCTION->Call($connection_type, $codetype, 0, 0);
|
|
466 |
if ($hndl)
|
|
467 |
{
|
|
468 |
return $hndl;
|
|
469 |
}
|
|
470 |
else
|
|
471 |
{
|
|
472 |
GetDllError(0);
|
|
473 |
}
|
|
474 |
}
|
|
475 |
else
|
|
476 |
{
|
|
477 |
$lasterror = "Function StdConnect not found";
|
|
478 |
}
|
|
479 |
}
|
|
480 |
else
|
|
481 |
{
|
|
482 |
$lasterror = "Code type not supplied";
|
|
483 |
}
|
|
484 |
}
|
|
485 |
else
|
|
486 |
{
|
|
487 |
$lasterror = "Connection type not supplied";
|
|
488 |
}
|
|
489 |
|
|
490 |
Line(get_last_error());
|
|
491 |
return 0;
|
|
492 |
}
|
|
493 |
|
|
494 |
|
|
495 |
################################################################
|
|
496 |
# Connect to the target device in a multithreaded environment
|
|
497 |
################################################################
|
|
498 |
sub connect_to_target_multithreaded
|
|
499 |
{
|
|
500 |
Line("Connecting to $statdir/$dllname (" . get_version() . ")...");
|
|
501 |
my @cmdline = @_;
|
|
502 |
my $cmdref = \@cmdline;
|
|
503 |
my $connection_type = $cmdref->[0];
|
|
504 |
my $codetype = $cmdref->[1];
|
|
505 |
|
|
506 |
# if we haven't supplied a connection type through here, maybe it was defined during initialise()
|
|
507 |
if (!$connection_type)
|
|
508 |
{
|
|
509 |
$connection_type = $def_connection_type;
|
|
510 |
}
|
|
511 |
|
|
512 |
# if we haven't supplied a code type through here, maybe it was defined during initialise()
|
|
513 |
if (!$codetype)
|
|
514 |
{
|
|
515 |
$codetype = $def_codetype;
|
|
516 |
}
|
|
517 |
|
|
518 |
if ($connection_type)
|
|
519 |
{
|
|
520 |
if ($codetype)
|
|
521 |
{
|
|
522 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdConnectMT", [I, P], I);
|
|
523 |
if (defined($FUNCTION))
|
|
524 |
{
|
|
525 |
Line("Connecting ($connection_type, $codetype)...");
|
|
526 |
my $hndl = $FUNCTION->Call($connection_type, $codetype);
|
|
527 |
if ($hndl)
|
|
528 |
{
|
|
529 |
return $hndl;
|
|
530 |
}
|
|
531 |
else
|
|
532 |
{
|
|
533 |
GetDllError(0);
|
|
534 |
}
|
|
535 |
}
|
|
536 |
else
|
|
537 |
{
|
|
538 |
$lasterror = "Function StdConnect not found";
|
|
539 |
}
|
|
540 |
}
|
|
541 |
else
|
|
542 |
{
|
|
543 |
$lasterror = "Code type not supplied";
|
|
544 |
}
|
|
545 |
}
|
|
546 |
else
|
|
547 |
{
|
|
548 |
$lasterror = "Connection type not supplied";
|
|
549 |
}
|
|
550 |
|
|
551 |
Line(get_last_error());
|
|
552 |
return 0;
|
|
553 |
}
|
|
554 |
|
|
555 |
|
|
556 |
################################################################
|
|
557 |
# Disconnect from the target device
|
|
558 |
################################################################
|
|
559 |
sub disconnect_from_target
|
|
560 |
{
|
|
561 |
Line("Disconnecting from $statdir/$dllname...");
|
|
562 |
my @cmdline = @_;
|
|
563 |
my $cmdref = \@cmdline;
|
|
564 |
my $hndl = $cmdref->[0];
|
|
565 |
|
|
566 |
if ($hndl)
|
|
567 |
{
|
|
568 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdDisconnect", [I], I);
|
|
569 |
if (defined($FUNCTION))
|
|
570 |
{
|
|
571 |
Line("Disconnecting $statdir/$dllname ($hndl)...");
|
|
572 |
$ret = $FUNCTION->Call($hndl);
|
|
573 |
if ($ret)
|
|
574 |
{
|
|
575 |
return 1;
|
|
576 |
}
|
|
577 |
else
|
|
578 |
{
|
|
579 |
GetDllError($hndl);
|
|
580 |
}
|
|
581 |
}
|
|
582 |
else
|
|
583 |
{
|
|
584 |
$lasterror = "Function StdDisconnect not found";
|
|
585 |
}
|
|
586 |
}
|
|
587 |
else
|
|
588 |
{
|
|
589 |
$lasterror = "Handle not supplied";
|
|
590 |
}
|
|
591 |
|
|
592 |
Line(get_last_error());
|
|
593 |
return 0;
|
|
594 |
}
|
|
595 |
|
|
596 |
|
|
597 |
################################################################
|
|
598 |
# Set logging of stat commands
|
|
599 |
# param0: logfile
|
|
600 |
# param1: log level
|
|
601 |
# param2: append or overwrite
|
|
602 |
# param3: reserved
|
|
603 |
# param4: reserved
|
|
604 |
################################################################
|
|
605 |
sub set_command_logging
|
|
606 |
{
|
|
607 |
Line("Setting command logging...");
|
|
608 |
my @cmdline = @_;
|
|
609 |
my $cmdref = \@cmdline;
|
|
610 |
my $hndl = $cmdref->[0];
|
|
611 |
if (($loglevel > 1) and $logfile)
|
|
612 |
{
|
|
613 |
if ($hndl)
|
|
614 |
{
|
|
615 |
if ($logfile)
|
|
616 |
{
|
|
617 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdSetCommandLogging", [I, P, P, I, I, P, P], I);
|
|
618 |
if (defined($FUNCTION))
|
|
619 |
{
|
|
620 |
Line("Logging to ($hndl, $logfile, $actual_level)");
|
|
621 |
$ret = $FUNCTION->Call($hndl, $logfile, 0, $loglevel, 0, 0, 0);
|
|
622 |
if ($ret)
|
|
623 |
{
|
|
624 |
return 1;
|
|
625 |
}
|
|
626 |
else
|
|
627 |
{
|
|
628 |
GetDllError($hndl);
|
|
629 |
}
|
|
630 |
}
|
|
631 |
else
|
|
632 |
{
|
|
633 |
$lasterror = "Function StdSetCommandLogging not found\n";
|
|
634 |
}
|
|
635 |
}
|
|
636 |
else
|
|
637 |
{
|
|
638 |
$lasterror = "Logfile not supplied";
|
|
639 |
}
|
|
640 |
}
|
|
641 |
else
|
|
642 |
{
|
|
643 |
$lasterror = "Handle not supplied";
|
|
644 |
}
|
|
645 |
}
|
|
646 |
else
|
|
647 |
{
|
|
648 |
$lasterror = "Logging level incorrect or logfile not supplied";
|
|
649 |
}
|
|
650 |
|
|
651 |
Line(get_last_error());
|
|
652 |
return 0;
|
|
653 |
}
|
|
654 |
|
|
655 |
|
|
656 |
################################################################
|
|
657 |
# Set command delay
|
|
658 |
# param0: delay (in milliseconds). Range 100 (default) -> 30,000
|
|
659 |
# The delay is inserted between complete commands, not between
|
|
660 |
# individual keystrokes.
|
|
661 |
################################################################
|
|
662 |
sub set_command_delay
|
|
663 |
{
|
|
664 |
Line("Setting command delay...");
|
|
665 |
my @cmdline = @_;
|
|
666 |
my $cmdref = \@cmdline;
|
|
667 |
my $hndl = $cmdref->[0];
|
|
668 |
my $delay = $cmdref->[1];
|
|
669 |
if ($hndl)
|
|
670 |
{
|
|
671 |
if ($delay)
|
|
672 |
{
|
|
673 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdSetCommandDelay", [I, I], I);
|
|
674 |
if (defined($FUNCTION))
|
|
675 |
{
|
|
676 |
Line("Delay ($hndl, $delay)");
|
|
677 |
$ret = $FUNCTION->Call($hndl, $delay);
|
|
678 |
if ($ret)
|
|
679 |
{
|
|
680 |
return 1;
|
|
681 |
}
|
|
682 |
else
|
|
683 |
{
|
|
684 |
GetDllError($hndl);
|
|
685 |
}
|
|
686 |
}
|
|
687 |
else
|
|
688 |
{
|
|
689 |
$lasterror = "Function StdSetCommandDelay not found\n";
|
|
690 |
}
|
|
691 |
}
|
|
692 |
else
|
|
693 |
{
|
|
694 |
$lasterror = "Delay not supplied";
|
|
695 |
}
|
|
696 |
}
|
|
697 |
else
|
|
698 |
{
|
|
699 |
$lasterror = "Handle not supplied";
|
|
700 |
}
|
|
701 |
|
|
702 |
Line(get_last_error());
|
|
703 |
return 0;
|
|
704 |
}
|
|
705 |
|
|
706 |
|
|
707 |
################################################################
|
|
708 |
# Set image verification
|
|
709 |
# param0: Ref Dir (string) - the directory where the reference
|
|
710 |
# images are located
|
|
711 |
# param1: Remove old images (bool)
|
|
712 |
# param2: Fudge factor - what percentage (0 -> 100%) of mismatched
|
|
713 |
# pixels are still considered to be a match
|
|
714 |
################################################################
|
|
715 |
sub set_image_verification
|
|
716 |
{
|
|
717 |
Line("Setting image verification...");
|
|
718 |
my @cmdline = @_;
|
|
719 |
my $cmdref = \@cmdline;
|
|
720 |
my $hndl = $cmdref->[0];
|
|
721 |
my $refdir = $cmdref->[1];
|
|
722 |
my $removeImages = $cmdref->[2];
|
|
723 |
my $fudgeFactor = $cmdref->[3];
|
|
724 |
if ($hndl)
|
|
725 |
{
|
|
726 |
if ($refdir)
|
|
727 |
{
|
|
728 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdSetImageVerification", [I, P, I, I], I);
|
|
729 |
if (defined($FUNCTION))
|
|
730 |
{
|
|
731 |
Line("Reference Directory ($hndl, $refdir, $removeImages, $fudgeFactor)");
|
|
732 |
$ret = $FUNCTION->Call($hndl, $refdir, $removeImages, $fudgeFactor);
|
|
733 |
if ($ret)
|
|
734 |
{
|
|
735 |
return 1;
|
|
736 |
}
|
|
737 |
else
|
|
738 |
{
|
|
739 |
GetDllError($hndl);
|
|
740 |
}
|
|
741 |
}
|
|
742 |
else
|
|
743 |
{
|
|
744 |
$lasterror = "Function StdSetImageVerification not found\n";
|
|
745 |
}
|
|
746 |
}
|
|
747 |
else
|
|
748 |
{
|
|
749 |
$lasterror = "Reference Image Directory not supplied";
|
|
750 |
}
|
|
751 |
}
|
|
752 |
else
|
|
753 |
{
|
|
754 |
$lasterror = "Handle not supplied";
|
|
755 |
}
|
|
756 |
|
|
757 |
Line(get_last_error());
|
|
758 |
return 0;
|
|
759 |
}
|
|
760 |
|
|
761 |
|
|
762 |
################################################################
|
|
763 |
# Get a target screenshot
|
|
764 |
################################################################
|
|
765 |
sub get_screenshot
|
|
766 |
{
|
|
767 |
Line("Getting screenshot...");
|
|
768 |
my @cmdline = @_;
|
|
769 |
my $cmdref = \@cmdline;
|
|
770 |
my $hndl = $cmdref->[0];
|
|
771 |
my $name = $cmdref->[1];
|
|
772 |
my $command;
|
|
773 |
if ($hndl)
|
|
774 |
{
|
|
775 |
if ($name)
|
|
776 |
{
|
|
777 |
if ($imagedir)
|
|
778 |
{
|
|
779 |
$command = "<B><#image $imagedir/><S$name><E>";
|
|
780 |
}
|
|
781 |
else
|
|
782 |
{
|
|
783 |
$command = "<B><S$name><E>";
|
|
784 |
}
|
|
785 |
}
|
|
786 |
else
|
|
787 |
{
|
|
788 |
if ($imagedir)
|
|
789 |
{
|
|
790 |
$command = "<B><#image $imagedir/><S><E>";
|
|
791 |
}
|
|
792 |
else
|
|
793 |
{
|
|
794 |
$command = "<B><S><E>";
|
|
795 |
}
|
|
796 |
}
|
|
797 |
|
|
798 |
if (SendCommand($hndl, $command))
|
|
799 |
{
|
|
800 |
return 1;
|
|
801 |
}
|
|
802 |
}
|
|
803 |
else
|
|
804 |
{
|
|
805 |
$lasterror = "Handle not supplied";
|
|
806 |
}
|
|
807 |
|
|
808 |
Line(get_last_error());
|
|
809 |
return 0;
|
|
810 |
}
|
|
811 |
|
|
812 |
|
|
813 |
################################################################
|
|
814 |
# Get Device Information
|
|
815 |
################################################################
|
|
816 |
sub get_device_info
|
|
817 |
{
|
|
818 |
Line("Getting device info...");
|
|
819 |
my @cmdline = @_;
|
|
820 |
my $cmdref = \@cmdline;
|
|
821 |
my $hndl = $cmdref->[0];
|
|
822 |
|
|
823 |
if (SendCommand($hndl, "<B><D><E>"))
|
|
824 |
{
|
|
825 |
return 1;
|
|
826 |
}
|
|
827 |
|
|
828 |
Line(get_last_error());
|
|
829 |
return 0;
|
|
830 |
}
|
|
831 |
|
|
832 |
|
|
833 |
################################################################
|
|
834 |
# 'Touch' the screen at specified co-ordinates
|
|
835 |
################################################################
|
|
836 |
sub touch_screen
|
|
837 |
{
|
|
838 |
Line("Touching screen...");
|
|
839 |
my @cmdline = @_;
|
|
840 |
my $cmdref = \@cmdline;
|
|
841 |
my $hndl = $cmdref->[0];
|
|
842 |
my $xx = $cmdref->[1];
|
|
843 |
my $yy = $cmdref->[2];
|
|
844 |
if ($hndl)
|
|
845 |
{
|
|
846 |
if ($xx and $yy)
|
|
847 |
{
|
|
848 |
if (SendCommand($hndl, "<B><I$xx,$yy><E>"))
|
|
849 |
{
|
|
850 |
return 1;
|
|
851 |
}
|
|
852 |
}
|
|
853 |
else
|
|
854 |
{
|
|
855 |
$lasterror = "X-Y co-ordinates not specified";
|
|
856 |
}
|
|
857 |
}
|
|
858 |
else
|
|
859 |
{
|
|
860 |
$lasterror = "Handle not supplied";
|
|
861 |
}
|
|
862 |
|
|
863 |
Line(get_last_error());
|
|
864 |
return 0;
|
|
865 |
}
|
|
866 |
|
|
867 |
|
|
868 |
################################################################
|
|
869 |
# Start an application and create a new file
|
|
870 |
################################################################
|
|
871 |
sub start_application
|
|
872 |
{
|
|
873 |
Line("Starting application...");
|
|
874 |
my @cmdline = @_;
|
|
875 |
my $cmdref = \@cmdline;
|
|
876 |
my $hndl = $cmdref->[0];
|
|
877 |
my $name = $cmdref->[1];
|
|
878 |
my $doc = $cmdref->[2];
|
|
879 |
if ($hndl)
|
|
880 |
{
|
|
881 |
if ($name)
|
|
882 |
{
|
|
883 |
my $command;
|
|
884 |
if ($doc)
|
|
885 |
{
|
|
886 |
$command = "<B><A$name,$doc><E>";
|
|
887 |
}
|
|
888 |
else
|
|
889 |
{
|
|
890 |
$command = "<B><A$name><E>";
|
|
891 |
}
|
|
892 |
|
|
893 |
if (SendCommand($hndl, $command))
|
|
894 |
{
|
|
895 |
return 1;
|
|
896 |
}
|
|
897 |
}
|
|
898 |
else
|
|
899 |
{
|
|
900 |
$lasterror = "Application name not supplied";
|
|
901 |
}
|
|
902 |
}
|
|
903 |
else
|
|
904 |
{
|
|
905 |
$lasterror = "Handle not supplied";
|
|
906 |
}
|
|
907 |
|
|
908 |
Line(get_last_error());
|
|
909 |
return 0;
|
|
910 |
}
|
|
911 |
|
|
912 |
|
|
913 |
################################################################
|
|
914 |
# Start a program with parameters
|
|
915 |
################################################################
|
|
916 |
sub start_program
|
|
917 |
{
|
|
918 |
Line("Starting program...");
|
|
919 |
my @cmdline = @_;
|
|
920 |
my $cmdref = \@cmdline;
|
|
921 |
my $hndl = $cmdref->[0];
|
|
922 |
my $name = $cmdref->[1];
|
|
923 |
my $param = $cmdref->[2];
|
|
924 |
if ($hndl)
|
|
925 |
{
|
|
926 |
if ($name)
|
|
927 |
{
|
|
928 |
my $command;
|
|
929 |
if ($param)
|
|
930 |
{
|
|
931 |
$command = "<B><J$name,$param><E>";
|
|
932 |
}
|
|
933 |
else
|
|
934 |
{
|
|
935 |
$command = "<B><J$name><E>";
|
|
936 |
}
|
|
937 |
|
|
938 |
if (SendCommand($hndl, $command))
|
|
939 |
{
|
|
940 |
return 1;
|
|
941 |
}
|
|
942 |
}
|
|
943 |
else
|
|
944 |
{
|
|
945 |
$lasterror = "Program name not supplied";
|
|
946 |
}
|
|
947 |
}
|
|
948 |
else
|
|
949 |
{
|
|
950 |
$lasterror = "Handle not supplied";
|
|
951 |
}
|
|
952 |
|
|
953 |
Line(get_last_error());
|
|
954 |
return 0;
|
|
955 |
}
|
|
956 |
|
|
957 |
|
|
958 |
################################################################
|
|
959 |
# Start an application and open an existing new file
|
|
960 |
################################################################
|
|
961 |
sub open_application
|
|
962 |
{
|
|
963 |
Line("Opening application...");
|
|
964 |
my @cmdline = @_;
|
|
965 |
my $cmdref = \@cmdline;
|
|
966 |
my $hndl = $cmdref->[0];
|
|
967 |
my $name = $cmdref->[1];
|
|
968 |
my $doc = $cmdref->[2];
|
|
969 |
if ($hndl)
|
|
970 |
{
|
|
971 |
if ($name and $doc)
|
|
972 |
{
|
|
973 |
if (SendCommand($hndl, "<B><F$name,$doc><E>"))
|
|
974 |
{
|
|
975 |
return 1;
|
|
976 |
}
|
|
977 |
}
|
|
978 |
else
|
|
979 |
{
|
|
980 |
$lasterror = "Application name and file not supplied";
|
|
981 |
}
|
|
982 |
}
|
|
983 |
else
|
|
984 |
{
|
|
985 |
$lasterror = "Handle not supplied";
|
|
986 |
}
|
|
987 |
|
|
988 |
Line(get_last_error());
|
|
989 |
return 0;
|
|
990 |
}
|
|
991 |
|
|
992 |
|
|
993 |
################################################################
|
|
994 |
# Close the current application
|
|
995 |
################################################################
|
|
996 |
sub close_application
|
|
997 |
{
|
|
998 |
Line("Closing application...");
|
|
999 |
my @cmdline = @_;
|
|
1000 |
my $cmdref = \@cmdline;
|
|
1001 |
my $hndl = $cmdref->[0];
|
|
1002 |
if ($hndl)
|
|
1003 |
{
|
|
1004 |
if (SendCommand($hndl, "<B><C><E>"))
|
|
1005 |
{
|
|
1006 |
return 1;
|
|
1007 |
}
|
|
1008 |
}
|
|
1009 |
else
|
|
1010 |
{
|
|
1011 |
$lasterror = "Handle not supplied";
|
|
1012 |
}
|
|
1013 |
|
|
1014 |
Line(get_last_error());
|
|
1015 |
return 0;
|
|
1016 |
}
|
|
1017 |
|
|
1018 |
|
|
1019 |
################################################################
|
|
1020 |
# Send a sequence of basic keystrokes
|
|
1021 |
################################################################
|
|
1022 |
sub basic_key_sequence
|
|
1023 |
{
|
|
1024 |
Line("Sending basic key sequence...");
|
|
1025 |
my @cmdline = @_;
|
|
1026 |
my $cmdref = \@cmdline;
|
|
1027 |
my $hndl = $cmdref->[0];
|
|
1028 |
my $sequence = $cmdref->[1];
|
|
1029 |
if ($hndl)
|
|
1030 |
{
|
|
1031 |
if ($sequence)
|
|
1032 |
{
|
|
1033 |
if (SendCommand($hndl, "<B><K$sequence><E>"))
|
|
1034 |
{
|
|
1035 |
return 1;
|
|
1036 |
}
|
|
1037 |
}
|
|
1038 |
else
|
|
1039 |
{
|
|
1040 |
$lasterror = "Key sequence not supplied";
|
|
1041 |
}
|
|
1042 |
}
|
|
1043 |
else
|
|
1044 |
{
|
|
1045 |
$lasterror = "Handle not supplied";
|
|
1046 |
}
|
|
1047 |
|
|
1048 |
Line(get_last_error());
|
|
1049 |
return 0;
|
|
1050 |
}
|
|
1051 |
|
|
1052 |
|
|
1053 |
################################################################
|
|
1054 |
# Send a control keystroke
|
|
1055 |
################################################################
|
|
1056 |
sub control_keystroke
|
|
1057 |
{
|
|
1058 |
Line("Sending control keystroke...");
|
|
1059 |
my @cmdline = @_;
|
|
1060 |
my $cmdref = \@cmdline;
|
|
1061 |
my $hndl = $cmdref->[0];
|
|
1062 |
my $keystroke = $cmdref->[1];
|
|
1063 |
if ($hndl)
|
|
1064 |
{
|
|
1065 |
if ($keystroke)
|
|
1066 |
{
|
|
1067 |
if (SendCommand($hndl, "<B><L$keystroke><E>"))
|
|
1068 |
{
|
|
1069 |
return 1;
|
|
1070 |
}
|
|
1071 |
}
|
|
1072 |
else
|
|
1073 |
{
|
|
1074 |
$lasterror = "Control keystroke not supplied";
|
|
1075 |
}
|
|
1076 |
}
|
|
1077 |
else
|
|
1078 |
{
|
|
1079 |
$lasterror = "Handle not supplied";
|
|
1080 |
}
|
|
1081 |
|
|
1082 |
Line(get_last_error());
|
|
1083 |
return 0;
|
|
1084 |
}
|
|
1085 |
|
|
1086 |
|
|
1087 |
################################################################
|
|
1088 |
# Send a combination keystroke
|
|
1089 |
################################################################
|
|
1090 |
sub combination_keystroke
|
|
1091 |
{
|
|
1092 |
Line("Sending combination keystroke...");
|
|
1093 |
my @cmdline = @_;
|
|
1094 |
my $cmdref = \@cmdline;
|
|
1095 |
my $hndl = $cmdref->[0];
|
|
1096 |
my $combination = $cmdref->[1];
|
|
1097 |
if ($hndl)
|
|
1098 |
{
|
|
1099 |
if ($combination)
|
|
1100 |
{
|
|
1101 |
if (SendCommand($hndl, "<B><M$combination><E>"))
|
|
1102 |
{
|
|
1103 |
return 1;
|
|
1104 |
}
|
|
1105 |
}
|
|
1106 |
else
|
|
1107 |
{
|
|
1108 |
$lasterror = "Combination keystroke not supplied";
|
|
1109 |
}
|
|
1110 |
}
|
|
1111 |
else
|
|
1112 |
{
|
|
1113 |
$lasterror = "Handle not supplied";
|
|
1114 |
}
|
|
1115 |
|
|
1116 |
Line(get_last_error());
|
|
1117 |
return 0;
|
|
1118 |
}
|
|
1119 |
|
|
1120 |
|
|
1121 |
################################################################
|
|
1122 |
# Pause for milliseconds
|
|
1123 |
################################################################
|
|
1124 |
sub pause
|
|
1125 |
{
|
|
1126 |
Line("Pausing...");
|
|
1127 |
my @cmdline = @_;
|
|
1128 |
my $cmdref = \@cmdline;
|
|
1129 |
my $hndl = $cmdref->[0];
|
|
1130 |
my $pause = $cmdref->[1];
|
|
1131 |
if ($hndl)
|
|
1132 |
{
|
|
1133 |
if ($pause)
|
|
1134 |
{
|
|
1135 |
if (SendCommand($hndl, "<B><P$pause><E>"))
|
|
1136 |
{
|
|
1137 |
return 1;
|
|
1138 |
}
|
|
1139 |
}
|
|
1140 |
else
|
|
1141 |
{
|
|
1142 |
$lasterror = "Value not supplied";
|
|
1143 |
}
|
|
1144 |
}
|
|
1145 |
else
|
|
1146 |
{
|
|
1147 |
$lasterror = "Handle not supplied";
|
|
1148 |
}
|
|
1149 |
|
|
1150 |
Line(get_last_error());
|
|
1151 |
return 0;
|
|
1152 |
}
|
|
1153 |
|
|
1154 |
|
|
1155 |
################################################################
|
|
1156 |
# Start ESHELL command interpreter
|
|
1157 |
################################################################
|
|
1158 |
sub start_eshell
|
|
1159 |
{
|
|
1160 |
Line("Starting ESHELL...");
|
|
1161 |
my @cmdline = @_;
|
|
1162 |
my $cmdref = \@cmdline;
|
|
1163 |
my $hndl = $cmdref->[0];
|
|
1164 |
if ($hndl)
|
|
1165 |
{
|
|
1166 |
if (SendCommand($hndl, "<B><!><E>"))
|
|
1167 |
{
|
|
1168 |
return 1;
|
|
1169 |
}
|
|
1170 |
}
|
|
1171 |
else
|
|
1172 |
{
|
|
1173 |
$lasterror = "Handle not supplied";
|
|
1174 |
}
|
|
1175 |
|
|
1176 |
Line(get_last_error());
|
|
1177 |
return 0;
|
|
1178 |
}
|
|
1179 |
|
|
1180 |
|
|
1181 |
################################################################
|
|
1182 |
# Stop ESHELL command interpreter
|
|
1183 |
################################################################
|
|
1184 |
sub stop_eshell
|
|
1185 |
{
|
|
1186 |
Line("Stopping ESHELL...");
|
|
1187 |
my @cmdline = @_;
|
|
1188 |
my $cmdref = \@cmdline;
|
|
1189 |
my $hndl = $cmdref->[0];
|
|
1190 |
if ($hndl)
|
|
1191 |
{
|
|
1192 |
if (SendCommand($hndl, "<B><!!><E>"))
|
|
1193 |
{
|
|
1194 |
return 1;
|
|
1195 |
}
|
|
1196 |
}
|
|
1197 |
else
|
|
1198 |
{
|
|
1199 |
$lasterror = "Handle not supplied";
|
|
1200 |
}
|
|
1201 |
|
|
1202 |
Line(get_last_error());
|
|
1203 |
return 0;
|
|
1204 |
}
|
|
1205 |
|
|
1206 |
|
|
1207 |
################################################################
|
|
1208 |
# Transfer (copy) common test file to target. Copies a 'common'
|
|
1209 |
# test file to the target board.
|
|
1210 |
################################################################
|
|
1211 |
sub copy_commonfile_to_target
|
|
1212 |
{
|
|
1213 |
Line("Copying commonfile file to target...");
|
|
1214 |
my @cmdline = @_;
|
|
1215 |
my $cmdref = \@cmdline;
|
|
1216 |
my $hndl = $cmdref->[0];
|
|
1217 |
my $source = $cmdref->[1];
|
|
1218 |
my $dest = $cmdref->[2];
|
|
1219 |
if ($hndl)
|
|
1220 |
{
|
|
1221 |
if ($source and $dest)
|
|
1222 |
{
|
|
1223 |
if (SendCommand($hndl, "<B><T$commondir$source,$dest><E>"))
|
|
1224 |
{
|
|
1225 |
return 1;
|
|
1226 |
}
|
|
1227 |
}
|
|
1228 |
else
|
|
1229 |
{
|
|
1230 |
$lasterror = "Source and/or target names not supplied";
|
|
1231 |
}
|
|
1232 |
}
|
|
1233 |
else
|
|
1234 |
{
|
|
1235 |
$lasterror = "Handle not supplied";
|
|
1236 |
}
|
|
1237 |
|
|
1238 |
Line(get_last_error());
|
|
1239 |
return 0;
|
|
1240 |
}
|
|
1241 |
|
|
1242 |
|
|
1243 |
################################################################
|
|
1244 |
# Transfer (copy) test file to target. Copies a specific test
|
|
1245 |
# file to the target board.
|
|
1246 |
################################################################
|
|
1247 |
sub copy_testfile_to_target
|
|
1248 |
{
|
|
1249 |
Line("Copying testfile file to target...");
|
|
1250 |
my @cmdline = @_;
|
|
1251 |
my $cmdref = \@cmdline;
|
|
1252 |
my $hndl = $cmdref->[0];
|
|
1253 |
my $source = $cmdref->[1];
|
|
1254 |
my $dest = $cmdref->[2];
|
|
1255 |
if ($hndl)
|
|
1256 |
{
|
|
1257 |
if ($source and $dest)
|
|
1258 |
{
|
|
1259 |
if (SendCommand($hndl, "<B><T$senddir$source,$dest><E>"))
|
|
1260 |
{
|
|
1261 |
return 1;
|
|
1262 |
}
|
|
1263 |
}
|
|
1264 |
else
|
|
1265 |
{
|
|
1266 |
$lasterror = "Source and/or target names not supplied";
|
|
1267 |
}
|
|
1268 |
}
|
|
1269 |
else
|
|
1270 |
{
|
|
1271 |
$lasterror = "Handle not supplied";
|
|
1272 |
}
|
|
1273 |
|
|
1274 |
Line(get_last_error());
|
|
1275 |
return 0;
|
|
1276 |
}
|
|
1277 |
|
|
1278 |
|
|
1279 |
################################################################
|
|
1280 |
# Transfer (copy) build file to target. Copies a file located
|
|
1281 |
# within a build image to the target board
|
|
1282 |
################################################################
|
|
1283 |
sub copy_buildfile_to_target
|
|
1284 |
{
|
|
1285 |
Line("Copying buildfile file to target...");
|
|
1286 |
|
|
1287 |
if (!$httpserver or !$runno or !builddir)
|
|
1288 |
{
|
|
1289 |
Line("ERROR: TMS Server, run number, or build directory not defined - Build files cannot be transfered");
|
|
1290 |
return 0;
|
|
1291 |
}
|
|
1292 |
|
|
1293 |
my @cmdline = @_;
|
|
1294 |
my $cmdref = \@cmdline;
|
|
1295 |
my $hndl = $cmdref->[0];
|
|
1296 |
my $source = $cmdref->[1];
|
|
1297 |
my $dest = $cmdref->[2];
|
|
1298 |
my $codetype = $cmdref->[2];
|
|
1299 |
if ($hndl)
|
|
1300 |
{
|
|
1301 |
if ($source and $dest)
|
|
1302 |
{
|
|
1303 |
# find the location of the build
|
|
1304 |
$location = GetBuildLocation($codetype);
|
|
1305 |
if ($location)
|
|
1306 |
{
|
|
1307 |
# get the desired file from the TMS
|
|
1308 |
if (DownloadAndSaveFile("$location/$source", "$workdir$builddir$source"))
|
|
1309 |
{
|
|
1310 |
# send the file to the target device
|
|
1311 |
if (SendCommand($hndl, "<B><T$builddir$source,$dest><E>"))
|
|
1312 |
{
|
|
1313 |
return 1;
|
|
1314 |
}
|
|
1315 |
}
|
|
1316 |
else
|
|
1317 |
{
|
|
1318 |
$lasterror = "Could not download file $location/$file";
|
|
1319 |
}
|
|
1320 |
}
|
|
1321 |
else
|
|
1322 |
{
|
|
1323 |
$lasterror = "Build location could not be obtained";
|
|
1324 |
}
|
|
1325 |
}
|
|
1326 |
else
|
|
1327 |
{
|
|
1328 |
$lasterror = "Source and/or target names not supplied";
|
|
1329 |
}
|
|
1330 |
}
|
|
1331 |
else
|
|
1332 |
{
|
|
1333 |
$lasterror = "Handle not supplied";
|
|
1334 |
}
|
|
1335 |
|
|
1336 |
Line(get_last_error());
|
|
1337 |
return 0;
|
|
1338 |
}
|
|
1339 |
|
|
1340 |
|
|
1341 |
################################################################
|
|
1342 |
# Retrieve (move) file from target
|
|
1343 |
################################################################
|
|
1344 |
sub move_from_target
|
|
1345 |
{
|
|
1346 |
Line("Moving file from target...");
|
|
1347 |
my @cmdline = @_;
|
|
1348 |
my $cmdref = \@cmdline;
|
|
1349 |
my $hndl = $cmdref->[0];
|
|
1350 |
my $source = $cmdref->[1];
|
|
1351 |
if ($hndl)
|
|
1352 |
{
|
|
1353 |
if ($source)
|
|
1354 |
{
|
|
1355 |
if (SendCommand($hndl, "<B><X$source,$recvdir><E>"))
|
|
1356 |
{
|
|
1357 |
return 1;
|
|
1358 |
}
|
|
1359 |
}
|
|
1360 |
else
|
|
1361 |
{
|
|
1362 |
$lasterror = "Source name not supplied";
|
|
1363 |
}
|
|
1364 |
}
|
|
1365 |
else
|
|
1366 |
{
|
|
1367 |
$lasterror = "Handle not supplied";
|
|
1368 |
}
|
|
1369 |
|
|
1370 |
Line(get_last_error());
|
|
1371 |
return 0;
|
|
1372 |
}
|
|
1373 |
|
|
1374 |
|
|
1375 |
################################################################
|
|
1376 |
# Retrieve (copy) file from target
|
|
1377 |
################################################################
|
|
1378 |
sub copy_from_target
|
|
1379 |
{
|
|
1380 |
Line("Copying file from target...");
|
|
1381 |
my @cmdline = @_;
|
|
1382 |
my $cmdref = \@cmdline;
|
|
1383 |
my $hndl = $cmdref->[0];
|
|
1384 |
my $source = $cmdref->[1];
|
|
1385 |
if ($hndl)
|
|
1386 |
{
|
|
1387 |
if ($source)
|
|
1388 |
{
|
|
1389 |
if (SendCommand($hndl, "<B><R$source,$recvdir><E>"))
|
|
1390 |
{
|
|
1391 |
return 1;
|
|
1392 |
}
|
|
1393 |
}
|
|
1394 |
else
|
|
1395 |
{
|
|
1396 |
$lasterror = "Source name not supplied";
|
|
1397 |
}
|
|
1398 |
}
|
|
1399 |
else
|
|
1400 |
{
|
|
1401 |
$lasterror = "Handle not supplied";
|
|
1402 |
}
|
|
1403 |
|
|
1404 |
Line(get_last_error());
|
|
1405 |
return 0;
|
|
1406 |
}
|
|
1407 |
|
|
1408 |
|
|
1409 |
################################################################
|
|
1410 |
# Delete unneeded file from target
|
|
1411 |
################################################################
|
|
1412 |
sub remove_file
|
|
1413 |
{
|
|
1414 |
Line("Removing file...");
|
|
1415 |
my @cmdline = @_;
|
|
1416 |
my $cmdref = \@cmdline;
|
|
1417 |
my $hndl = $cmdref->[0];
|
|
1418 |
my $file = $cmdref->[1];
|
|
1419 |
|
|
1420 |
if ($hndl)
|
|
1421 |
{
|
|
1422 |
if ($file)
|
|
1423 |
{
|
|
1424 |
if (SendCommand($hndl, "<B><U$file><E>"))
|
|
1425 |
{
|
|
1426 |
return 1;
|
|
1427 |
}
|
|
1428 |
}
|
|
1429 |
else
|
|
1430 |
{
|
|
1431 |
$lasterror = "File not supplied";
|
|
1432 |
}
|
|
1433 |
}
|
|
1434 |
else
|
|
1435 |
{
|
|
1436 |
$lasterror = "Handle not supplied";
|
|
1437 |
}
|
|
1438 |
|
|
1439 |
Line(get_last_error());
|
|
1440 |
return 0;
|
|
1441 |
}
|
|
1442 |
|
|
1443 |
|
|
1444 |
################################################################
|
|
1445 |
# Creating a folder on the target
|
|
1446 |
################################################################
|
|
1447 |
sub create_folder
|
|
1448 |
{
|
|
1449 |
Line("Creating folder...");
|
|
1450 |
my @cmdline = @_;
|
|
1451 |
my $cmdref = \@cmdline;
|
|
1452 |
my $hndl = $cmdref->[0];
|
|
1453 |
my $folder = $cmdref->[1];
|
|
1454 |
|
|
1455 |
if ($hndl)
|
|
1456 |
{
|
|
1457 |
if ($folder)
|
|
1458 |
{
|
|
1459 |
if (SendCommand($hndl, "<B><N$folder><E>"))
|
|
1460 |
{
|
|
1461 |
return 1;
|
|
1462 |
}
|
|
1463 |
}
|
|
1464 |
else
|
|
1465 |
{
|
|
1466 |
$lasterror = "Folder not supplied";
|
|
1467 |
}
|
|
1468 |
}
|
|
1469 |
else
|
|
1470 |
{
|
|
1471 |
$lasterror = "Handle not supplied";
|
|
1472 |
}
|
|
1473 |
|
|
1474 |
Line(get_last_error());
|
|
1475 |
return 0;
|
|
1476 |
}
|
|
1477 |
|
|
1478 |
|
|
1479 |
################################################################
|
|
1480 |
# Delete unneeded folder from target
|
|
1481 |
################################################################
|
|
1482 |
sub remove_folder
|
|
1483 |
{
|
|
1484 |
Line("Removing folder...");
|
|
1485 |
my @cmdline = @_;
|
|
1486 |
my $cmdref = \@cmdline;
|
|
1487 |
my $hndl = $cmdref->[0];
|
|
1488 |
my $folder = $cmdref->[1];
|
|
1489 |
|
|
1490 |
if ($hndl)
|
|
1491 |
{
|
|
1492 |
if ($folder)
|
|
1493 |
{
|
|
1494 |
if (SendCommand($hndl, "<B><Z$folder><E>"))
|
|
1495 |
{
|
|
1496 |
return 1;
|
|
1497 |
}
|
|
1498 |
}
|
|
1499 |
else
|
|
1500 |
{
|
|
1501 |
$lasterror = "Folder not supplied";
|
|
1502 |
}
|
|
1503 |
}
|
|
1504 |
else
|
|
1505 |
{
|
|
1506 |
$lasterror = "Handle not supplied";
|
|
1507 |
}
|
|
1508 |
|
|
1509 |
Line(get_last_error());
|
|
1510 |
return 0;
|
|
1511 |
}
|
|
1512 |
|
|
1513 |
|
|
1514 |
################################################################
|
|
1515 |
# Hold a key down for a specified time
|
|
1516 |
################################################################
|
|
1517 |
sub hold_key
|
|
1518 |
{
|
|
1519 |
Line("Holding key down for specified time...");
|
|
1520 |
my @cmdline = @_;
|
|
1521 |
my $cmdref = \@cmdline;
|
|
1522 |
my $hndl = $cmdref->[0];
|
|
1523 |
my $key = $cmdref->[1];
|
|
1524 |
my $delaytime = $cmdref->[2];
|
|
1525 |
|
|
1526 |
if ($hndl)
|
|
1527 |
{
|
|
1528 |
if ($key)
|
|
1529 |
{
|
|
1530 |
if ($delaytime)
|
|
1531 |
{
|
|
1532 |
if (SendCommand($hndl, "<B><H$key,$delaytime><E>"))
|
|
1533 |
{
|
|
1534 |
return 1;
|
|
1535 |
}
|
|
1536 |
}
|
|
1537 |
else
|
|
1538 |
{
|
|
1539 |
$lasterror = "Delay time not supplied";
|
|
1540 |
}
|
|
1541 |
}
|
|
1542 |
else
|
|
1543 |
{
|
|
1544 |
$lasterror = "Key not supplied";
|
|
1545 |
}
|
|
1546 |
}
|
|
1547 |
else
|
|
1548 |
{
|
|
1549 |
$lasterror = "Handle not supplied";
|
|
1550 |
}
|
|
1551 |
|
|
1552 |
Line(get_last_error());
|
|
1553 |
return 0;
|
|
1554 |
}
|
|
1555 |
|
|
1556 |
|
|
1557 |
################################################################
|
|
1558 |
# Execute a command file
|
|
1559 |
################################################################
|
|
1560 |
sub send_command_file
|
|
1561 |
{
|
|
1562 |
Line("Sending command file...");
|
|
1563 |
my @cmdline = @_;
|
|
1564 |
my $cmdref = \@cmdline;
|
|
1565 |
my $hndl = $cmdref->[0];
|
|
1566 |
my $file = $cmdref->[1];
|
|
1567 |
if ($hndl)
|
|
1568 |
{
|
|
1569 |
if ($file)
|
|
1570 |
{
|
|
1571 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdSendCommandFile", [I, P, P], I);
|
|
1572 |
if (defined($FUNCTION))
|
|
1573 |
{
|
|
1574 |
Line("Command File ($hndl, $file )");
|
|
1575 |
$ret = $FUNCTION->Call($hndl, $file, 0);
|
|
1576 |
if ($ret)
|
|
1577 |
{
|
|
1578 |
return 1;
|
|
1579 |
}
|
|
1580 |
else
|
|
1581 |
{
|
|
1582 |
GetDllError($hndl);
|
|
1583 |
}
|
|
1584 |
}
|
|
1585 |
else
|
|
1586 |
{
|
|
1587 |
$lasterror = "Function StdSendCommandFile not found\n";
|
|
1588 |
}
|
|
1589 |
}
|
|
1590 |
else
|
|
1591 |
{
|
|
1592 |
$lasterror = "Command file not supplied";
|
|
1593 |
}
|
|
1594 |
}
|
|
1595 |
else
|
|
1596 |
{
|
|
1597 |
$lasterror = "Handle not supplied";
|
|
1598 |
}
|
|
1599 |
|
|
1600 |
Line(get_last_error());
|
|
1601 |
return 0;
|
|
1602 |
}
|
|
1603 |
|
|
1604 |
|
|
1605 |
################################################################
|
|
1606 |
# Execute a raw command
|
|
1607 |
################################################################
|
|
1608 |
sub send_raw_command
|
|
1609 |
{
|
|
1610 |
Line("Executing raw command...");
|
|
1611 |
my @cmdline = @_;
|
|
1612 |
my $cmdref = \@cmdline;
|
|
1613 |
my $hndl = $cmdref->[0];
|
|
1614 |
my $command = $cmdref->[1];
|
|
1615 |
if ($hndl)
|
|
1616 |
{
|
|
1617 |
if ($command)
|
|
1618 |
{
|
|
1619 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdSendRawCommand", [I, P, P], I);
|
|
1620 |
if (defined($FUNCTION))
|
|
1621 |
{
|
|
1622 |
Line("Command File ($hndl, $command)");
|
|
1623 |
$ret = $FUNCTION->Call($hndl, $command, 0);
|
|
1624 |
if ($ret)
|
|
1625 |
{
|
|
1626 |
return 1;
|
|
1627 |
}
|
|
1628 |
else
|
|
1629 |
{
|
|
1630 |
GetDllError($hndl);
|
|
1631 |
}
|
|
1632 |
}
|
|
1633 |
else
|
|
1634 |
{
|
|
1635 |
$lasterror = "Function StdSendRawCommand not found\n";
|
|
1636 |
}
|
|
1637 |
}
|
|
1638 |
else
|
|
1639 |
{
|
|
1640 |
$lasterror = "Command file not supplied";
|
|
1641 |
}
|
|
1642 |
}
|
|
1643 |
else
|
|
1644 |
{
|
|
1645 |
$lasterror = "Handle not supplied";
|
|
1646 |
}
|
|
1647 |
|
|
1648 |
Line(get_last_error());
|
|
1649 |
return 0;
|
|
1650 |
}
|
|
1651 |
|
|
1652 |
|
|
1653 |
################################################################
|
|
1654 |
# PRIVATE FUNCTIONS
|
|
1655 |
################################################################
|
|
1656 |
|
|
1657 |
#############################################################################
|
|
1658 |
# Get the STAT working path from the registry
|
|
1659 |
#############################################################################
|
|
1660 |
sub GetSTATWorkingDirectory
|
|
1661 |
{
|
|
1662 |
my $swkey = $Registry->{"LMachine/software/"};
|
|
1663 |
my $endkey = $swkey->{"symbian/stat/"};
|
|
1664 |
|
|
1665 |
$workdir = $endkey->{"/WorkingPath"};
|
|
1666 |
if (!$workdir)
|
|
1667 |
{
|
|
1668 |
$lasterror = "Cannot obtain STAT work dir from registry";
|
|
1669 |
return 0;
|
|
1670 |
}
|
|
1671 |
|
|
1672 |
$statdir = $endkey->{"/InstallRoot"};
|
|
1673 |
if (!$statdir)
|
|
1674 |
{
|
|
1675 |
$lasterror = "Cannot obtain STAT Install dir from registry";
|
|
1676 |
return 0;
|
|
1677 |
}
|
|
1678 |
|
|
1679 |
# substitute DOS '\' with '/' if needed
|
|
1680 |
$workdir = "$workdir/";
|
|
1681 |
$workdir =~ s/\\/\//g;
|
|
1682 |
$statdir =~ s/\\/\//g;
|
|
1683 |
|
|
1684 |
return 1;
|
|
1685 |
}
|
|
1686 |
|
|
1687 |
|
|
1688 |
################################################################
|
|
1689 |
# Get the error that occurred within the DLL call
|
|
1690 |
################################################################
|
|
1691 |
sub GetDllError
|
|
1692 |
{
|
|
1693 |
my @cmdline = @_;
|
|
1694 |
my $cmdref = \@cmdline;
|
|
1695 |
my $hndl = $cmdref->[0];
|
|
1696 |
|
|
1697 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdGetError", [I], P);
|
|
1698 |
if (defined($FUNCTION))
|
|
1699 |
{
|
|
1700 |
if ($hndl)
|
|
1701 |
{
|
|
1702 |
Line("Handle : ($hndl)");
|
|
1703 |
}
|
|
1704 |
|
|
1705 |
$lasterror = $FUNCTION->Call($hndl);
|
|
1706 |
}
|
|
1707 |
else
|
|
1708 |
{
|
|
1709 |
$lasterror = "Function StdGetError not found";
|
|
1710 |
}
|
|
1711 |
|
|
1712 |
return $lasterror;
|
|
1713 |
}
|
|
1714 |
|
|
1715 |
|
|
1716 |
#############################################################################
|
|
1717 |
# Display a line of text
|
|
1718 |
#############################################################################
|
|
1719 |
sub Line
|
|
1720 |
{
|
|
1721 |
my ($msg) = @_;
|
|
1722 |
|
|
1723 |
if ($msg)
|
|
1724 |
{
|
|
1725 |
($hour, $min, $sec) = (localtime)[2,1,0];
|
|
1726 |
printf("%02d:%02d:%02d $msg\n", $hour, $min, $sec);
|
|
1727 |
STDOUT->autoflush;
|
|
1728 |
STDERR->autoflush;
|
|
1729 |
}
|
|
1730 |
}
|
|
1731 |
|
|
1732 |
|
|
1733 |
###############################################################################################
|
|
1734 |
# Construct a build location depending on the code and build type
|
|
1735 |
###############################################################################################
|
|
1736 |
sub GetBuildLocation
|
|
1737 |
{
|
|
1738 |
my $command;
|
|
1739 |
|
|
1740 |
my @cmdline = @_;
|
|
1741 |
my $cmdref = \@cmdline;
|
|
1742 |
my $codetype = $cmdref->[0];
|
|
1743 |
|
|
1744 |
if (!$httpserver)
|
|
1745 |
{
|
|
1746 |
$lasterror = "TMS Server not defined";
|
|
1747 |
Line(get_last_error());
|
|
1748 |
return 0;
|
|
1749 |
}
|
|
1750 |
|
|
1751 |
# ceate a user agent object
|
|
1752 |
my $ua = new LWP::UserAgent;
|
|
1753 |
$ua->agent("AgentName/0.1 " . $ua->agent);
|
|
1754 |
|
|
1755 |
$req = new HTTP::Request GET => "$httpserver/GetBuildLocation?RunNo=$runno";
|
|
1756 |
$req->header('User-Agent' => $ua->agent);
|
|
1757 |
$req->header('Authorization' => "Basic $encoded");
|
|
1758 |
$req->header('Content-type' => 'binary');
|
|
1759 |
$res = $ua->request($req);
|
|
1760 |
if (!$res->is_success)
|
|
1761 |
{
|
|
1762 |
$lasterror = "Cannot open $httpserver/GetBuildLocation";
|
|
1763 |
Line(get_last_error());
|
|
1764 |
return 0;
|
|
1765 |
}
|
|
1766 |
|
|
1767 |
# decide build type depending on $codetype
|
|
1768 |
my $buildtype = "UREL";
|
|
1769 |
if ($codetype eq "WINS")
|
|
1770 |
{
|
|
1771 |
$buildtype = "UDEB";
|
|
1772 |
}
|
|
1773 |
|
|
1774 |
$command = "$httpserver/" . $res->content() . "/epoc32/release/$codetype/$buildtype";
|
|
1775 |
|
|
1776 |
# remove any carriage returns in the string
|
|
1777 |
$command =~ s/\n//g;
|
|
1778 |
|
|
1779 |
Line("Build location is [$command]");
|
|
1780 |
|
|
1781 |
return $command;
|
|
1782 |
}
|
|
1783 |
|
|
1784 |
|
|
1785 |
###############################################################################################
|
|
1786 |
# Download a single file to a local location
|
|
1787 |
###############################################################################################
|
|
1788 |
sub DownloadAndSaveFile
|
|
1789 |
{
|
|
1790 |
my ($source, $destination) = @_;
|
|
1791 |
|
|
1792 |
# substitute DOS '\' with '/' if needed
|
|
1793 |
$source =~ s/\\/\//g;
|
|
1794 |
$destination =~ s/\\/\//g;
|
|
1795 |
|
|
1796 |
Line("$source => $destination");
|
|
1797 |
|
|
1798 |
# ceate a user agent object
|
|
1799 |
my $ua = new LWP::UserAgent;
|
|
1800 |
$ua->agent("AgentName/0.1 " . $ua->agent);
|
|
1801 |
|
|
1802 |
$req = new HTTP::Request GET => "$source";
|
|
1803 |
$req->header('User-Agent' => $ua->agent);
|
|
1804 |
$req->header('Authorization' => "Basic $encoded");
|
|
1805 |
$req->header('Content-type' => 'binary');
|
|
1806 |
$res = $ua->request($req);
|
|
1807 |
if (!$res->is_success)
|
|
1808 |
{
|
|
1809 |
$lasterror = "Cannot open $source";
|
|
1810 |
Line(get_last_error());
|
|
1811 |
return 0;
|
|
1812 |
}
|
|
1813 |
|
|
1814 |
Line("Saving retrieved file to $destination...");
|
|
1815 |
|
|
1816 |
# save the retrieved contents to disk
|
|
1817 |
my $fh = IO::File->new ("$destination", O_CREAT | O_WRONLY | O_TRUNC);
|
|
1818 |
binmode($fh);
|
|
1819 |
if ($fh)
|
|
1820 |
{
|
|
1821 |
print $fh $res->content();
|
|
1822 |
$fh->autoflush(1);
|
|
1823 |
close($fh);
|
|
1824 |
}
|
|
1825 |
else
|
|
1826 |
{
|
|
1827 |
$lasterror = "Cannot create $destination";
|
|
1828 |
Line(get_last_error());
|
|
1829 |
return 0;
|
|
1830 |
}
|
|
1831 |
|
|
1832 |
return 1;
|
|
1833 |
}
|
|
1834 |
|
|
1835 |
|
|
1836 |
################################################################
|
|
1837 |
# Send a command to the target
|
|
1838 |
################################################################
|
|
1839 |
sub SendCommand
|
|
1840 |
{
|
|
1841 |
my @cmdline = @_;
|
|
1842 |
my $cmdref = \@cmdline;
|
|
1843 |
my $hndl = $cmdref->[0];
|
|
1844 |
my $command = $cmdref->[1];
|
|
1845 |
|
|
1846 |
# substitute Perl '/' with DOS '\' if needed
|
|
1847 |
$command =~ s/\//\\/g;
|
|
1848 |
|
|
1849 |
$FUNCTION = new Win32::API("$statdir/$dllname", "StdSendRawCommand", [I, P, P], I);
|
|
1850 |
if (defined($FUNCTION))
|
|
1851 |
{
|
|
1852 |
Line("Command ($hndl, $command)");
|
|
1853 |
$ret = $FUNCTION->Call($hndl, $command, 0);
|
|
1854 |
if ($ret)
|
|
1855 |
{
|
|
1856 |
return 1;
|
|
1857 |
}
|
|
1858 |
else
|
|
1859 |
{
|
|
1860 |
GetDllError($hndl);
|
|
1861 |
}
|
|
1862 |
}
|
|
1863 |
else
|
|
1864 |
{
|
|
1865 |
$lasterror = "Function StdSendRawCommand not found";
|
|
1866 |
}
|
|
1867 |
|
|
1868 |
return 0;
|
|
1869 |
}
|
|
1870 |
|
|
1871 |
|
|
1872 |
# last line in file
|
|
1873 |
1;
|
|
1874 |
__END__
|