home *** CD-ROM | disk | FTP | other *** search
/ Computer Buyer 1996 May / buyer-0596.iso / wincim / scripts.lib / PHONE.SCR < prev    next >
Text File  |  1995-12-05  |  5KB  |  269 lines

  1. !
  2. !  Copyright (c) 1995
  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.8.1"
  15. !-V
  16.  
  17. MdmCmd = "";
  18. Z_Sent = %FALSE;
  19.  
  20. WaitTime = 10;
  21. ifndef %mdm_UserID = "";
  22. ifndef %mdm_Password = "";
  23. ifndef %mdm_ECOn = "";
  24. ifndef %mdm_DCOn = "";
  25.  
  26. if %DialType = 2 goto Direct_Connect;
  27.  
  28. goto Do_Phone_Connect;
  29.  
  30. !
  31. ! Subroutines
  32. !
  33. Hangup_Before_Connect:
  34.     define %LOCAL = 2;
  35.     call %Dir & "disconct.scr" () : Result;
  36.     return;
  37.  
  38. Two_Tries_Hangup:
  39.     gosub Hangup_Before_Connect;
  40.     goto Send_Reset_String;
  41.  
  42.  
  43. !
  44. ! Main Program:  Start_Connect
  45. !
  46. Do_Phone_Connect:
  47.     RingLimit = 5;
  48.     RingCount = 0;
  49.     UsingModem = %FALSE;
  50.     on cancel goto Phone_Cancelled;
  51.  
  52.     if %DialType = 0 goto Get_Tone_Str;
  53.     DialTypeStr = %mdm_Pulse_Dial;        ! Type = DT_Pulse
  54.     goto Init_Modem;
  55.  
  56. Get_Tone_Str:
  57.     DialTypeStr = %mdm_Tone_Dial;        ! Type = DT_Tone
  58.  
  59. Init_Modem:
  60.     show "Initializing modem";
  61.     MsgStr = "Dialing " & %Phone;
  62.     tries = 0;
  63.  
  64. Send_Reset_String:
  65.     if (%mdm_Reset = "") goto Modem_OK;
  66.     sendm %mdm_Prefix;
  67.     sendm %mdm_Reset;
  68.     sendm %mdm_Suffix;
  69.  
  70. Send_Wait:
  71.     wait
  72.         "User Id"    goto Send_User_ID,
  73.         "Password"    goto Send_Password,
  74.         %mdm_Ack    goto Modem_OK,
  75.         "0"        goto Modem_OK,
  76.         "ERROR"        goto Send_Z
  77.     until 40;
  78.  
  79.     tries = tries + 1;
  80.     if tries = 2 goto Two_Tries_Hangup;    ! Two failures to send Reset -
  81.                         ! hang up and try twice more.
  82.     if tries < 4 goto Send_Reset_String;
  83.  
  84.     wait until WaitTime;
  85.  
  86.     define %ErrorCode = 10;
  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 %ErrorCode = 11;
  111.     define %FailureMsg = "Invalid modem security User ID or password";
  112.     exit %Fatal;
  113.  
  114. Send_Z:
  115.     if %mdm_Reset = "Z" goto Modem_OK;
  116.     if Z_Sent goto Modem_OK;
  117.     wait until 5;
  118.     Z_Sent = %TRUE;
  119.     sendm %mdm_Prefix;
  120.     sendm "Z";
  121.     sendm %mdm_Suffix;
  122.     goto Send_Wait;
  123.  
  124. Modem_OK:
  125.     wait until 10;
  126.     if (%mdm_Init = "") goto Check_Modem_Speaker;
  127.     sendm %mdm_Init;
  128.  
  129.     wait
  130.         %mdm_Ack    goto Check_Modem_Speaker,
  131.         "ERROR"        goto Show_Init_Error
  132.     until 33;
  133.     FailStr = "Modem not responding";
  134.     define %ErrorCode = 12;
  135.     goto Phone_Failed;
  136.  
  137. Show_Init_Error:
  138.     show "Error in modem command";
  139.     wait until 10;
  140.  
  141. Check_Modem_Speaker:
  142.     if (%mdm_Speaker <> 0) goto Check_DC;
  143.     MdmCmd = "M0";
  144.  
  145. Check_DC:
  146.     if %mdm_DCOn = "" goto Check_EC;
  147.     MdmCmd = MdmCmd & %mdm_DCOn;
  148.     goto Wait_Ack;
  149.  
  150. Check_EC:
  151.     if %mdm_ECOn = "" goto Wait_Ack;
  152.     MdmCmd = MdmCmd & %mdm_ECOn;
  153.  
  154. Wait_Ack:
  155.     if MdmCmd = "" goto Try_Phone;
  156.     wait until 2;            ! delay for 300 baud modems
  157.     sendm %mdm_Prefix & MdmCmd & %mdm_Suffix;
  158.  
  159.     wait
  160.         %mdm_Ack    goto Try_Phone,
  161.         "ERROR"        goto Show_Proto_Error
  162.     until 33;
  163.     goto Try_Phone;
  164.  
  165. Show_Proto_Error:
  166.     show "Error in modem command";
  167.  
  168. Try_Phone:
  169.     wait until 10;
  170.     count = 0;
  171.     FailStr = "";
  172. Dial_Phone:
  173.     if (count > %Retry) goto Exit_Error;
  174.     define %ErrorCode = 0;
  175.  
  176.     show MsgStr;
  177.     
  178.     sendm %mdm_Prefix;
  179.     sendm DialTypeStr & %Phone;
  180.     sendm %mdm_Suffix;
  181.  
  182. Start_Phone_Loop:
  183.     wait
  184.         %mdm_Success    goto Modem_Success,
  185.         %mdm_Failure    goto Modem_Failure,
  186.         "No Dial"    goto No_Dial_Tone,
  187.         "Dial Complete"    goto Dial_Complete,
  188.         "Busy"        goto Line_Busy,
  189.         "Ring"        goto Remote_Ring
  190.     until 856;
  191.  
  192.     FailStr = "Dialing failed";
  193.     goto End_Phone_Loop;
  194.  
  195. Modem_Success:
  196.     wait until 5;
  197. Direct_Connect:
  198.     exit %Success;
  199.  
  200. Modem_Failure:
  201.     FailStr = "Dialing unsuccessful";
  202.     wait until WaitTime;
  203.     goto End_Phone_Loop;
  204.  
  205. No_Dial_Tone:
  206.     FailStr = "No Dialtone";
  207.     define %ErrorCode = 13;
  208.     goto Exit_Failure;
  209.  
  210. Dial_Complete:
  211.     MsgStr = "Dialed " & %Phone & ", awaiting answer";
  212.     show MsgStr;
  213.     goto Start_Phone_Loop;
  214.  
  215. Line_Busy:
  216.     FailStr = "Number is busy";
  217.     wait until 2 * WaitTime;
  218.     send %CR;
  219.  
  220.     wait
  221.         %mdm_Success    goto End_Line_Busy,
  222.         %mdm_Failure    goto End_Line_Busy,
  223.         "No Dial"    goto End_Line_Busy,
  224.         "Dial Complete"    goto End_Line_Busy,
  225.         "Busy"        goto End_Line_Busy,
  226.         "Ring"        goto End_Line_Busy
  227.     until 56;
  228.  
  229. End_Line_Busy:
  230.     define %ErrorCode = 15;
  231.     wait until WaitTime;
  232.     goto End_Phone_Loop;
  233.  
  234. Remote_Ring:
  235.     RingCount = RingCount + 1;
  236.     if RingCount <= RingLimit goto Show_Ringing;
  237.  
  238.     FailStr = "No answer";
  239.     goto End_Phone_Loop;
  240.  
  241. Show_Ringing:
  242.     MsgStr = %Phone & " is ringing, awaiting answer";
  243.     show MsgStr;
  244.     goto Start_Phone_Loop;
  245.  
  246. End_Phone_Loop:
  247.     MsgStr = FailStr & ", redialing " & %Phone;
  248.     count = count + 1;
  249.     goto Dial_Phone;
  250.  
  251. Phone_Cancelled:
  252.     gosub Hangup_Before_Connect;
  253.     exit Result;
  254.  
  255. Phone_Failed:
  256.     if FailStr <> "" goto Exit_Fatal;
  257.     FailStr = "Dialing failed";
  258.  
  259. Exit_Fatal:
  260.     define %FailureMsg = FailStr;
  261.     exit %Fatal;
  262.  
  263. Exit_Error:
  264.     if %ErrorCode <> 0 goto Exit_Failure;
  265.     define %ErrorCode = 14;
  266. Exit_Failure:
  267.     define %FailureMsg = FailStr;
  268.     exit %Failure;
  269.