#!/usr/local/bin/perl5 -w
#========================================================================
#
#              status_report.pl
#
#   This is an example script that enables the SERVICE alert and then 
#   monitors the control port waiting for service changes.  The status
#   command is used to display the change in service.
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#  (c) COPYRIGHT 2001 QUALCOMM, Incorporated. All Rights Reserved
#                     QUALCOMM Proprietary
#
#  Export of this technology or software is regulated by the U.S. Government.
#  Diversion contrary to U.S. law prohibited.
#
#  All ideas, data and information contained in or disclosed by
#  this document are confidential and proprietary information of
#  QUALCOMM Incorporated and all rights therein are expressly reserved.
#  By accepting this material the recipient agrees that this material
#  and the information contained therein are held in confidence and in
#  trust and will not be used, copied, reproduced in whole or in part,
#  nor its contents revealed in any manner to others without the express
#  written permission of QUALCOMM Incorporated.
#
#========================================================================

#===========================================================================
#               INCLUDE FILES
#===========================================================================

use strict;
use CommLib;
use AtCmdLib;

#===========================================================================
#               DEFINITIONS AND DECLARATIONS
#===========================================================================

# Set global to specify that Control port is on COM1

$CommLib::COM_CONTROL="COM1";

#===========================================================================
#                   MAIN SCRIPT
#===========================================================================

#---------------------------------------------------------------------------
# Initialize CommLib
#---------------------------------------------------------------------------

comm_lib_init();

#---------------------------------------------------------------------------
# Config CommLib to use the control port.
#---------------------------------------------------------------------------

comm_set_config($COMM_CONFIG_CONTROL);

#---------------------------------------------------------------------------
# Enable the service alert
#---------------------------------------------------------------------------

my $response = at_enable_service_alert();

# Make sure we got the OK

if (!($response =~ /OK/))
{
  print "Error: AT\$QCSA=1 did not return an OK response\n";
}

#---------------------------------------------------------------------------
# Sit and wait for service alerts 
#---------------------------------------------------------------------------

print "Waiting for service alerts\n";
sleep 1;

for(;;)
{
  $response = at_wait_for_alert();

  if ($response =~ /SERVICE/)
  {
    #-----------------------------------------------------------------------
    # Got the service alert, get and display the status information
    #-----------------------------------------------------------------------

    print_status( at_qcstatus() );
    print "\n\n";
  }

  else
  {
    print "Unexpected response code: $response\n";
  }
}

#---------------------------------------------------------------------------
# Shutdown CommLib
#---------------------------------------------------------------------------

comm_lib_shutdown();

