#========================================================================= 
#          Copyright © 2001-2004 QUALCOMM Incorporated.
#                     All Rights Reserved.
#========================================================================= 
#! /usr/local/bin/perl -w
use strict;

use lib "$ENV{BREWTOOLSDIR}\\BREW Perl Interface";
use BREWPerlIF;


#########################################################################
# Sample perl application to demonstrate how to put the phone in offline 
# mode and reset the phone.
#########################################################################


#########################################################################
# Variable Declaration Section
#########################################################################

# serial port name to which the device is connected
my $port = "COM1";

my $dllName = "$ENV{BTILDIR}\\OEMLayer\\QCOMOEM.dll";

# place hloder for storing result
my $result;


##########################################################################
# Here starts the actual processing
##########################################################################

# connect to the device
printf "Connecting to device\n" ;
if( BREWPerlIF::ConnecttoDevice($port,$dllName )) {
	print "Connection to Device successful\n";
} else {
	die "Could not connect to the device on specified port $port\n";
}


printf "Putting device offline\n";

# sleep for some time to give device sufficient time to enter into DM mode
sleep(30);
$result = BREWPerlIF::OfflineConnectedDevice();
if($result == 0) {
	printf "Could not put the device in offline mode\n";
}else {
	printf "Device is now in offline mode\n";
}


printf "Resetting Device\n";
$result = BREWPerlIF::ResetConnectedDevice(); 
if($result == 0) {
	printf "Could not reset the device\n";
} else{
	printf "Device reset successfully\n";
}


printf "disconnecting from device\n" ;
sleep(10);
if( BREWPerlIF::ReleaseDevice() ) {
	print "disconnect from the device successful\n";
} else {
	die "Could not disconnect from the device\n";
}