
(*----------------------------------------------------------------------*)
(*                   HangUpPhone  --- Hang up the phone                 *)
(*----------------------------------------------------------------------*)

PROCEDURE HangUpPhone;

(*----------------------------------------------------------------------*)
(*                                                                      *)
(*     Procedure:  HangUpPhone                                          *)
(*                                                                      *)
(*     Purpose:    Hangs up the phone.                                  *)
(*                                                                      *)
(*     Calling Sequence:                                                *)
(*                                                                      *)
(*        HangUpPhone;                                                  *)
(*                                                                      *)
(*                                                                      *)
(*     Calls:                                                           *)
(*                                                                      *)
(*        DELAY                                                         *)
(*        Send_Modem_Command                                            *)
(*        Async_Term_Ready                                              *)
(*        Async_Receive_With_Timeout                                    *)
(*                                                                      *)
(*     Remarks:                                                         *)
(*                                                                      *)
(*        If a modem command delay string and a mode hang-up string     *)
(*        are specified, they are used.  If not, the phone is hung      *)
(*        up by dropping DTR.                                           *)
(*                                                                      *)
(*----------------------------------------------------------------------*)

VAR
   Garbage_Ch: INTEGER;
   Done_Flag : BOOLEAN;

BEGIN (* HangUpPhone *)
                                   (* If modem hang-up command given, *)
                                   (* use it.                         *)

   IF Modem_Hang_Up <> '' THEN
      BEGIN

         DELAY( Modem_Escape_Time );

         Send_Modem_Command( Modem_Escape );

         DELAY( Modem_Escape_Time );

         Send_Modem_Command( Modem_Hang_Up );

         DELAY( Modem_Escape_Time );

      END;
                                   (* If no hangup command provided, *)
                                   (* or it didn't work, drop DTR.   *)

   IF ( Modem_Hang_Up = '' ) OR ( Async_Carrier_Detect ) THEN
      BEGIN

         Async_Term_Ready( FALSE );

         DELAY( One_Second_Delay );

         Async_Term_Ready( TRUE );

      END;
                                   (* Swallow any garbage characters *)
   Async_Purge_Buffer;

END   (* HangUpPhone *);