#######################################################################
## proc send_expect_init
## 
## Copyright (c) David L. Fisher, 1999
## 
## This software is copyrighted David L. Fisher.  The following 
## terms apply to all files associated with the software unless
## explicitly disclaimed in individual files.
## 
## The author hereby grants permission to use, copy, modify,
## distribute, and license this software and its documentation for any
## purpose, provided that existing copyright notices are retained in
## all copies and that this notice is included verbatim in any
## distributions. No written agreement, license, or royalty fee is
## required for any of the authorized uses. Modifications to this
## software may be copyrighted by their authors and need not follow
## the licensing terms described here, provided that the new terms are
## clearly indicated on the first page of each file where they apply. 
## 
## IN NO EVENT SHALL THE AUTHOR OR DISTRIBUTORS BE LIABLE TO ANY PARTY
## FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
## ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
## DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
## POSSIBILITY OF SUCH DAMAGE.
## 
## THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
## NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
## AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
## MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
## 
## GOVERNMENT USE: If you are acquiring this software on behalf of the 
## U.S. government, the Government shall have only "Restricted Rights"
## in the software and related documentation as defined in the Federal 
## Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
## are acquiring the software on behalf of the Department of Defense,
## the software shall be classified as "Commercial Computer Software"
## and the Government shall have only "Restricted Rights" as defined
## in Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the
## foregoing, the authors grant the U.S. Government and others acting
## in its behalf permission to use and distribute the software in
## accordance with the terms specified in this license.
## 
#######################################################################

#######################################################################
## NAME
##      send_expect_init
##
## DESCRIPTION
##      Initialize all settings for the send_expect interface
##
## INPUTS
##      NONE
##
## OUTPUTS
##      NONE
##
#######################################################################
proc send_expect_init { } {

    global sendGlobals;
    global send_slow;
    global files;

    ## don't know if we have the logging mechanisms yet, so...
    puts  -nonewline stderr "Initializing send_expect...";

    ##----------------------------------------------------------------------
    ## set maximum failure persistence for each transmission mode
    ## except the character-by-character mode; to disable the mode
    ## rejection, set the FailMax values to 0 - this will cause the
    ## interface to use all available modes each time 
    ##----------------------------------------------------------------------
    set sendGlobals(Mode1FailMax)       5;
    set sendGlobals(Mode2FailMax)       5;
    set sendGlobals(Mode3FailMax)       5;
    set sendGlobals(Mode1Failures)      0;
    set sendGlobals(Mode2Failures)      0;
    set sendGlobals(Mode3Failures)      0;

    ##----------------------------------------------------------------------
    ## use this element to specify which mode to start trying with
    ## this can be 1, 2, or 3 - any other values will case the default
    ## 1 to be used 
    ##----------------------------------------------------------------------
    set sendGlobals(useMode)            1;
    set sendGlobals(thisMode)           0;

    ##----------------------------------------------------------------------
    ## transmission errors in the send procedures are considered SEVERE
    ## because if they fail, the harness no longer knows where it is and
    ## what's going on (some commands can also create anomolous conditions
    ## in the system under test)
    ##----------------------------------------------------------------------
    set sendGlobals(sendErrorSeverity)  SEVERE;

    ##----------------------------------------------------------------------
    ## counter for the number of times a transmission had to be killed and
    ## re-attempted;
    ## killed is a placeholder for filenames for any transmission attempt
    ## that had to be killed and retried
    ##----------------------------------------------------------------------
    set sendGlobals(numSent)            0;
    set sendGlobals(kills)              0;
    set sendGlobals(killed)             0;

    ##----------------------------------------------------------------------
    ## set up diagnostics info and performance -
    ## to make the harness run the fastest, set sleepTime 0 and diagFile 0
    ## no diagnostics will be logged for the execution if this is the case
    ##----------------------------------------------------------------------
    set sendGlobals(errors)             0;
    set sendGlobals(diagFile)           send.diagnostics;
    set sendGlobals(logDiags)           1;
    set sendGlobals(sleepTime)          0;
    set sendGlobals(success)            0;
    set sendGlobals(error)              1;
    
    ##----------------------------------------------------------------------
    ## set up special characters
    ##----------------------------------------------------------------------
    set sendGlobals(kill)               \025;    ## control-U
    set sendGlobals(terminator)         "\r";    ## carriage-return
                                                 ## termination 
    set sendGlobals(crTerminated)       0;       ## indicates last
                                                 ## character is a
                                                 ## carriage-return 

    ##----------------------------------------------------------------------
    ## general stuff
    ##----------------------------------------------------------------------
    set sendGlobals(stringSent)         "";      ## part of string that was sent
                                                 ## successfully
    set sendGlobals(command)            "";      ## entire string to be sent
    set sendGlobals(delay)              .001;    ## 1 ms delay for send_slow
                                                 ## list
    set sendGlobals(interval)           1;       ## add delay between every
                                                 ## character (send_slow list)
    set sendGlobals(ssFlag)             "";      ## send_slow flag for exp_send
                                                 ## (disabled initially)
    set sendGlobals(caught)             0;       ## number of error caught by
                                                 ## send_only

    ## make sure we have a valid send_slow list
    if { ![info exists send_slow] } {
        set send_slow "$sendGlobals(interval) $sendGlobals(delay)";
    }
    puts stderr "Done";
}




