home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / n / newscr.zip / NEWSCR.EXE / PHONE.SCR < prev    next >
Text File  |  1992-08-28  |  5KB  |  204 lines

  1. !---------------------------------------------------------------------!
  2. !                                                                     !
  3. !  Copyright (c) 1991                                                 !
  4. !  by CompuServe Incorporated, Columbus, Ohio                         !
  5. !                                                                     !
  6. !  The information in this software is subject to change without      !
  7. !  notice and should not be construed as a commitment by CompuServe.  !
  8. !                                                                     !
  9. !  PHONE Script:                                                      !
  10. !     Phone Script:  Contains modem/phone related logic.              !
  11. !     Success:  returns %Success                                      !
  12. !     Failure:  saves error msg in %FailureMsg and returns %Failure   !
  13. !                                                                     !
  14. !     $Revision::   1.9      $                                        !
  15. !                                                                     !
  16. !---------------------------------------------------------------------!
  17.  
  18. WaitTime = 10;
  19. goto Do_Phone_Connect;
  20.  
  21. !------------------------!
  22. !     Subroutines        !
  23. !------------------------!
  24.  
  25. Send_Modem_Cmd:
  26.     if (ModemStr = "") goto End_Modem_Cmd;
  27.       sendm %mdm_Prefix;
  28.       sendm ModemStr;
  29.       sendm %mdm_Suffix;
  30.  
  31. End_Modem_Cmd:
  32.     return;
  33.  
  34.  
  35. Hangup_Before_Connect:
  36.     define %LOCAL = 2;
  37.     call %Dir & "disconct.scr" () : Result;
  38.     return;
  39.  
  40. Two_Tries_Hangup:
  41.     gosub Hangup_Before_Connect;
  42.     goto Send_Reset_String;
  43.  
  44.  
  45. !----------------------------------------!
  46. !     Main Program:  Start_Connect       !
  47. !----------------------------------------!
  48.  
  49. Do_Phone_Connect:
  50.  
  51.     RingLimit = 5;
  52.     RingCount = 0;
  53.     UsingModem = %FALSE;
  54.     on cancel goto Phone_Cancelled;
  55.  
  56.     if %DialType = 0 goto Get_Tone_Str;
  57.     DialTypeStr = %mdm_Pulse_Dial;              ! Type = DT_Pulse
  58.     goto Init_Modem;
  59.  
  60. Get_Tone_Str:
  61.     DialTypeStr = %mdm_Tone_Dial;               ! Type = DT_Tone
  62.  
  63. Init_Modem:
  64.     show "Initializing Modem";
  65.     MsgStr = "Dialing " & %Phone;
  66.     tries = 0;
  67.  
  68. Send_Reset_String:
  69.     ModemStr = %mdm_Reset;
  70.     gosub Send_Modem_Cmd;
  71.  
  72.     wait
  73.      %mdm_Ack goto Modem_OK,
  74.      "0" goto Modem_OK
  75.     until 40;
  76.  
  77.     tries = tries + 1;
  78.     if tries = 2 goto Two_Tries_Hangup;  !Two failures to send Reset -
  79.                                          !hang up and try twice more.
  80.     if tries < 4 goto Send_Reset_String;
  81.  
  82.     wait until WaitTime;
  83.  
  84.     FailStr = "Modem not responding";
  85.     goto Phone_Failed;
  86.  
  87. Modem_OK:
  88.     wait until WaitTime;
  89.       if (%mdm_Init = "") goto Check_Modem_Speaker;
  90.       sendm %mdm_Init;
  91.  
  92.     wait
  93.      %mdm_Ack goto End_Wait1
  94.     until 33;
  95. End_Wait1:
  96.  
  97.     wait until WaitTime;
  98.  
  99. Check_Modem_Speaker:
  100.     if (%mdm_Speaker <> 0) goto Try_Phone;
  101.  
  102.     sendm %mdm_Prefix;
  103.     sendm "M0";
  104.     send %CR;
  105.  
  106.     wait
  107.      %mdm_Ack goto End_Wait2
  108.     until 33;
  109. End_Wait2:
  110.  
  111.     wait until WaitTime;
  112.  
  113. Try_Phone:
  114.     count = 0;
  115.     FailStr = "";
  116.  
  117. Dial_Phone:
  118.     if (count > %Retry) goto Phone_Failed;
  119.  
  120.     show MsgStr;
  121.     ModemStr = DialTypeStr & %Phone;
  122.     gosub Send_Modem_Cmd;
  123.  
  124. Start_Phone_Loop:
  125.  
  126.     wait
  127.      %mdm_Success goto Modem_Success,
  128.      %mdm_Failure goto Modem_Failure,
  129.      "No Dial" goto No_Dial_Tone,
  130.      "Dial Complete" goto Dial_Complete,
  131.      "Busy" goto Line_Busy,
  132.      "Ring" goto Remote_Ring
  133.     until 556;
  134.  
  135.     FailStr = "Dialing failed";
  136.     goto Exit_Failure;
  137.  
  138. Modem_Success:
  139.     wait until 2 * WaitTime;
  140.     exit %Success;
  141.  
  142. Modem_Failure:
  143.     FailStr = "Dialing unsuccessful, check phone number";
  144.     wait until WaitTime;
  145.     goto End_Phone_Loop;
  146.  
  147. No_Dial_Tone:
  148.     FailStr = "No Dial";
  149.     goto Phone_Failed;
  150.  
  151. Dial_Complete:
  152.     MsgStr = "Dialed " & %Phone & ", awaiting answer";
  153.     show MsgStr;
  154.     goto Start_Phone_Loop;
  155.  
  156. Line_Busy:
  157.     FailStr = "Number is busy";
  158.     wait until 2 * WaitTime;
  159.     send %CR;
  160.  
  161.     wait
  162.      %mdm_Success goto End_Line_Busy,
  163.      %mdm_Failure goto End_Line_Busy,
  164.      "No Dial" goto End_Line_Busy,
  165.      "Dial Complete" goto End_Line_Busy,
  166.      "Busy" goto End_Line_Busy,
  167.      "Ring" goto End_Line_Busy
  168.     until 56;
  169.  
  170. End_Line_Busy:
  171.     wait until WaitTime;
  172.     goto End_Phone_Loop;
  173.  
  174. Remote_Ring:
  175.     if RingCount <= RingLimit goto Show_Ringing;
  176.  
  177.     FailStr = "No answer";
  178.     goto End_Phone_Loop;
  179.  
  180. Show_Ringing:
  181.     MsgStr = %Phone & " is ringing, awaiting answer";
  182.     show MsgStr;
  183.     goto Start_Phone_Loop;
  184.  
  185. End_Phone_Loop:
  186.     MsgStr = FailStr & ", redialing " & %Phone;
  187.     count = count + 1;
  188.     goto Dial_Phone;
  189.  
  190. Phone_Cancelled:
  191.     gosub Hangup_Before_Connect;
  192.     exit Result;
  193.  
  194. Phone_Failed:
  195.     if FailStr <> "" goto Exit_Failure;
  196.     FailStr = "Dialing failed";
  197.  
  198. Exit_Failure:
  199.     define %FailureMsg = FailStr;
  200.     exit %Failure;
  201.  
  202.  
  203.  
  204.