home *** CD-ROM | disk | FTP | other *** search
/ Corel Draw! Unleashed / Corel Draw! Unleashed.iso / wincim / scripts.lib / PHONE.SCR < prev    next >
Encoding:
Text File  |  1993-05-14  |  4.3 KB  |  228 lines

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