#========================================================================= 
#          Copyright © 2001-2004 QUALCOMM Incorporated.
#                     All Rights Reserved.
#========================================================================= 

# A very simple Perl5 script for Grinder
#! /usr/local/bin/perl -w 

#Please keep these two lines in all the sample scripts that you are writing for this version of Grinder
use GrinderPl;
use enum qw( AVK_ASTERISK=1000 AVK_NUMBER_SIGN AVK_SELECT AVK_UP AVK_DOWN AVK_LEFT AVK_RIGHT AVK_SEND AVK_CLR AVK_END);
################################################################################################


################################################################################################
#
# A Grinder perl application to configure Shaker on the phone.
#
#	1) It initializes the perl module.
#	2) Loads the default settings.
#	3) Initializes the phone.
#	4) Starts the Shaker.
#	5) Gets the free memory and the free efs on the phone.
#	6) Fills the required amount of memory.
#	7) Creates the TCP and UDP sockets.
#	8) Releases Shaker.
#	9) Sets the Grinder settings and starts it on the phone.
#	10) Closes Shaker and stops the Grinder and releases the perl module.
#
################################################################################################

#Load the default settings ..
GrinderPl::InitPerlModule();
GrinderPl::LoadSettings(0);

$i = 100;
if(GrinderPl::InitDevice("COM1")) {
	#Start configuring shaker
	if (GrinderPl::StartShaker())  {
	
		#Get free memory on the phone
		$i = GrinderPl::GetFreeMemory();
		if($i != -1) {
			$i = 100;
			#Fill 100 bytes of phone memory
			if(GrinderPl::FillMemory1($i)) {
				#print("Filled x bytes of memory\n");
			}
		}

		# Get free efs on the phone
		$i = GrinderPl::GetFreeEfs();
		if($i != -1) {
			$i = 100;
			#Fill 100 bytes of efs
			if(GrinderPl::FillEfs1($i)) {
				#print("Filled x bytes of efs\n");
			}
		}

		#Create 2 tcp sockets
		if(!GrinderPl::CreateSocket(0, 2)) {
			print("Error while creating sockets\n");
		}
		

		#Create 2 udp sockets
		if(!GrinderPl::CreateSocket(1, 2)) {
			print("Error while creating sockets\n");
		}


		#End Shaker configuration
		GrinderPl::ReleaseShaker();	

		#Set Grinder settings
		GrinderPl::SetStartSeed(2);
		GrinderPl::SetEndSeed(10);
		GrinderPl::SetEventsPerGrind(2);
		GrinderPl::SetEventInterval(1000);
		GrinderPl::StartGrinder("COM1"); 
		
		#Stop Shaker
		GrinderPl::CloseShaker();

		#Stop Grinder. This API should be called only after closing Shaker.
		GrinderPl::StopGrinder();
	}
}
GrinderPl::ReleasePerlModule();
