home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / phon22.zip / PHONE22.SCR < prev   
Text File  |  1994-06-30  |  9KB  |  440 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. !  v2.2a 6/28/94 Mike Tannenbaum 75110,2037 Send comments by email only
  9. !
  10. !  PHONE:
  11. !  Contains modem/phone related logic.
  12. !  Success:  returns %Success
  13. !  Failure:  saves error msg in %FailureMsg and returns %Failure
  14. !
  15. !+V
  16. ! "3.5"
  17. !-V
  18.  
  19. MdmCmd = "";
  20. Z_Sent = %FALSE;
  21.  
  22. WaitTime = 10;
  23. ifndef %mdm_UserID = "";
  24. ifndef %mdm_Password = "";
  25. ifndef %mdm_ECOn = "";
  26. ifndef %mdm_DCOn = "";
  27.  
  28. if %DialType = 2 goto Direct_Connect;
  29.  
  30. goto Do_Phone_Connect;
  31.  
  32. !
  33. ! Subroutines
  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. Do_Phone_Connect:
  49.     RingLimit = 5;
  50.     RingCount = 0;
  51.     UsingModem = %FALSE;
  52.     on cancel goto Phone_Cancelled;
  53.  
  54.     if %DialType = 0 goto Get_Tone_Str;
  55.     DialTypeStr = %mdm_Pulse_Dial;      ! Type = DT_Pulse
  56.     goto Init_Modem;
  57.  
  58. Get_Tone_Str:
  59.     DialTypeStr = %mdm_Tone_Dial;    ! Type = DT_Tone
  60.  
  61. Init_Modem:
  62.     show "Initializing modem";
  63.     MsgStr = "Dialing " & %Phone;
  64.     tries = 0;
  65.  
  66. Send_Reset_String:
  67.     if (%mdm_Reset = "") goto Modem_OK;
  68.     sendm %mdm_Prefix;
  69.     sendm %mdm_Reset;
  70.     sendm %mdm_Suffix;
  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.         "ERROR"     goto Send_Z
  79.     until 40;
  80.  
  81.     tries = tries + 1;
  82.     if tries = 2 goto Two_Tries_Hangup; ! Two failures to send Reset -
  83.                                                     ! hang up and try twice more.
  84.     if tries < 4 goto Send_Reset_String;
  85.  
  86.     wait until WaitTime;
  87.  
  88.     define %ErrorCode = 10;
  89.     FailStr = "Modem not responding";
  90.     goto Phone_Failed;
  91.  
  92. Send_User_ID:
  93.     !
  94.     ! For those modems that support password security...
  95.     !
  96.     send %mdm_UserID & "^M";
  97.     goto Send_Wait;
  98.  
  99. Send_Password:
  100.     !
  101.     ! For those modems that support password security...
  102.     !
  103.     send %mdm_Password & "^M";
  104.     wait
  105.         "User id"   goto Modem_Security_Error,
  106.         %mdm_Ack    goto Send_Reset_String,
  107.         "0"         goto Send_Reset_String
  108.     until 100;
  109.     goto Send_Reset_String;
  110.  
  111. Modem_Security_Error:
  112.     define %ErrorCode = 11;
  113.     define %FailureMsg = "Invalid modem security User ID or password";
  114.     exit %Fatal;
  115.  
  116. Send_Z:
  117.     if %mdm_Reset = "Z" goto Modem_OK;
  118.     if Z_Sent goto Modem_OK;
  119.     wait until 5;
  120.     Z_Sent = %TRUE;
  121.     sendm %mdm_Prefix;
  122.     sendm "Z";
  123.     sendm %mdm_Suffix;
  124.     goto Send_Wait;
  125.  
  126. Modem_OK:
  127.     !show %mdm_Init;
  128.     wait until 10;
  129.     if (%mdm_Init = "") goto Check_Modem_Speaker;
  130.     sendm %mdm_Init;
  131.  
  132.     wait
  133.         %mdm_Ack goto Check_Modem_Speaker,
  134.         "ERROR"     goto Show_Init_Error
  135.     until 33;
  136.     FailStr = "Modem not responding";
  137.     define %ErrorCode = 12;
  138.     goto Phone_Failed;
  139.  
  140. Show_Init_Error:
  141.     show "Error in modem command";
  142.     wait until 10;
  143.  
  144. Check_Modem_Speaker:
  145.     if (%mdm_Speaker <> 0) goto Check_DC;
  146.     MdmCmd = "M0";
  147.  
  148. Check_DC:
  149.     if %mdm_DCOn = "" goto Check_EC;
  150.     MdmCmd = MdmCmd & %mdm_DCOn;
  151.     goto Wait_Ack;
  152.  
  153. Check_EC:
  154.     if %mdm_ECOn = "" goto Wait_Ack;
  155.     MdmCmd = MdmCmd & %mdm_ECOn;
  156.  
  157. Wait_Ack:
  158.     if MdmCmd = "" goto Try_Phone;
  159.     wait until 2;                ! delay for 300 baud modems
  160.     sendm %mdm_Prefix & MdmCmd & %mdm_Suffix;
  161.     wait
  162.         %mdm_Ack    goto Try_Phone,
  163.         "ERROR"     goto Show_Proto_Error
  164.     until 33;
  165.     goto Try_Phone;
  166.  
  167. Show_Proto_Error:
  168.     show "Error in modem command";
  169.  
  170. Try_Phone:
  171.     wait until 10;
  172.     count = 0;
  173.     FailStr = "";
  174. Dial_Phone:
  175.     if (count > %Retry) goto Exit_Error;
  176.  
  177.     show MsgStr;
  178.     
  179.     sendm %mdm_Prefix;
  180.     sendm DialTypeStr & %Phone;
  181.     sendm %mdm_Suffix;
  182.  
  183. Start_Phone_Loop:
  184.     wait
  185.         "CARRIER 2400"   goto Tcarchk,
  186.         "CARRIER 4800"   goto Hcarchk,      
  187.         "CARRIER 9600"   goto Ncarchk,
  188.         "CARRIER 14400"  goto Fcarchk,
  189.         "CONN"           goto Three_Connect,
  190.         %mdm_Failure     goto Modem_Failure,
  191.         "No Dial"        goto No_Dial_Tone,
  192.         "Dial Complete"  goto Dial_Complete,
  193.         "Busy"           goto Line_Busy,
  194.         "Ring"           goto Remote_Ring
  195.     until 556;
  196.  
  197.     FailStr = "Dialing failed";
  198.     goto End_Phone_Loop;
  199.  
  200. Tcarchk:
  201.     BdnoStr = "2400 bps DCE ";
  202.     goto Proto_Check;
  203.  
  204. Hcarchk:
  205.     BdnoStr = "4800 bps DCE ";
  206.     goto Proto_Check;
  207.  
  208. Ncarchk:
  209.     BdnoStr = "9600 bps DCE ";
  210.     goto Proto_Check;
  211.  
  212. Fcarchk:
  213.     BdnoStr = "14400 bps DCE ";
  214.     goto Proto_Check;
  215.  
  216. Proto_Check:
  217.     wait
  218.         "PROTOCOL: V.42"    goto VFour_Test,
  219.         "PROTOCOL: LAP"     goto VFour_Test,
  220.         "PROTOCOL: MNP"     goto Mnp_Test,
  221.         "PROTOCOL: ALT"     goto Mnp_Test,
  222.         "PROTOCOL: NONE"    goto Cnum_Test,
  223.         "CONN"              goto Success_Test
  224.     until 40;
  225.     goto Comp_Test;
  226.  
  227. VFour_Test:
  228.     BdnoStr = BdnoStr & "LAP-M ";
  229.     goto Comp_Test;
  230.  
  231. Mnp_Test:
  232.     BdnoStr = BdnoStr & "MNP ";
  233.     goto Comp_Test;
  234.  
  235. Comp_Test:
  236.     wait
  237.         "COMPRESSION: V.42BIS"   goto Bis_Test,
  238.         "COMPRESSION: MNP"       goto Mfive_Test,
  239.         "COMPRESSION: CLASS 5"   goto Mfive_Test,
  240.         "COMPRESSION: NONE"      goto Cnum_Test,
  241.         "CONN"                   goto Success_Test
  242.     until 20;
  243.     goto Cnum_Test;
  244.  
  245. Bis_Test:
  246.     BdnoStr = BdnoStr & "V.42bis ";
  247.     goto Cnum_Test;
  248.  
  249. Mfive_Test:
  250.     BdnoStr = BdnoStr & "MNP5 ";
  251.     goto Cnum_Test;
  252.  
  253. Cnum_Test:
  254.     wait
  255.         "CONN"    goto Success_Test
  256.     until 90;
  257.     goto Modem_Failure;
  258.  
  259. Success_Test:     
  260.     wait
  261.         "ECT 2400"      goto Twenty_Test,
  262.         "ECT 4800"      goto Eight_Test,
  263.         "ECT 9600"      goto Ninety_Test,
  264.         "ECT 14400"     goto Ndce_Test,
  265.         "ECT 19200"     goto Fdte_Test,
  266.         "ECT 38400"     goto Dbldte_Test
  267.     until 50;
  268.     goto Norpt_Test;
  269.  
  270. Ndce_Test:
  271.     BdnoStr = BdnoStr & "14.4kb DTE";
  272.     show BdnoStr;
  273.     goto Modem_Success;
  274.  
  275. Fdte_Test:
  276.     BdnoStr = BdnoStr & "19.2kb DTE";
  277.     show BdnoStr;
  278.     goto Modem_Success;
  279.  
  280. Dbldte_Test:
  281.     BdnoStr = BdnoStr & "38.4kb DTE";
  282.     show BdnoStr;
  283.     goto Modem_Success;
  284.  
  285. Eight_Test:
  286.     BdnoStr = BdnoStr & "4800 bps DTE";
  287.     show BdnoStr;
  288.     goto Modem_Success;
  289.  
  290. Twenty_Test:
  291.     BdnoStr = BdnoStr & "2400 bps DTE";
  292.     show BdnoStr;
  293.     goto Modem_Success;
  294.  
  295. Ninety_Test:
  296.     BdnoStr = BdnoStr & "9600 bps DTE";
  297.     show BdnoStr;
  298.     goto Modem_Success;
  299.  
  300. Norpt_Test:
  301.     show BdnoStr;
  302.     goto Modem_Success;
  303.  
  304. Three_Connect:
  305.     wait
  306.         "ECT 38400"       goto Super_Connect,            
  307.         "ECT 19200"       goto Fast_Connect,
  308.         "ECT 14400"       goto Fourteen_Connect,
  309.         "ECT 12000"       goto Twelve_Connect,
  310.         "ECT 9600"        goto Ninesix_Connect,
  311.         "ECT 7200"        goto Seven_Connect,
  312.         "ECT 4800"        goto Halfnine_Connect,
  313.         "ECT 2400"        goto Twofor_Connect,
  314.         "ECT 1200^M"      goto Onetwo_Connect,
  315.         "ECT 1200/"       goto Onetwo_Connect
  316.     until 20;
  317.     show "Connect: 300 or Unknown bps";
  318.     goto Modem_Success;
  319.  
  320. Super_Connect:
  321.     Bdrt = "Connect: 38400 bps DTE";
  322.     goto Arqchk;
  323.  
  324. Fast_Connect:
  325.     Bdrt = "Connect: 19200 bps DTE";
  326.     goto Arqchk;
  327.  
  328. Fourteen_Connect:
  329.     Bdrt = "Connect: 14400 bps";
  330.     goto Arqchk;
  331.  
  332. Twelve_Connect:
  333.     Bdrt = "Connect: 12000 bps";
  334.     goto Arqchk;
  335.  
  336. Ninesix_Connect:
  337.     Bdrt = "Connect: 9600 bps";
  338.     goto Arqchk;
  339.  
  340. Seven_Connect:
  341.     Bdrt = "Connect: 7200 bps";
  342.     goto Arqchk;
  343.  
  344. Halfnine_Connect:
  345.     Bdrt = "Connect: 4800 bps";
  346.     goto Arqchk;
  347.  
  348. Twofor_Connect:
  349.     Bdrt = "Connect: 2400 bps";
  350.     goto Arqchk;
  351.  
  352. Onetwo_Connect:
  353.     Bdrt = "Connect: 1200 bps";
  354.     goto Arqchk;
  355.  
  356. Arqchk:
  357.     wait
  358.         "REL" goto Lastst,
  359.         "ARQ" goto Lastst
  360.     until 15;
  361.     show Bdrt;
  362.     goto Modem_Success;
  363.  
  364. Lastst:
  365.     Bdrt = Bdrt & " w/ Error Control";
  366.     show Bdrt;
  367.  
  368. Modem_Success:
  369.     wait until 15;
  370. Direct_Connect:
  371.     exit %Success;
  372.  
  373. Modem_Failure:
  374.     FailStr = "Dialing unsuccessful, check phone number";
  375.     wait until WaitTime;
  376.     goto End_Phone_Loop;
  377.  
  378. No_Dial_Tone:
  379.     FailStr = "No Dialtone";
  380.     define %ErrorCode = 13;
  381.     goto Exit_Failure;
  382.  
  383. Dial_Complete:
  384.     MsgStr = "Dialed " & %Phone & ", awaiting answer";
  385.     show MsgStr;
  386.     goto Start_Phone_Loop;
  387.  
  388. Line_Busy:
  389.     FailStr = "Number is busy";
  390.     wait until 2 * WaitTime;
  391.     send %CR;
  392.  
  393.     wait
  394.         %mdm_Success      goto End_Line_Busy,
  395.         %mdm_Failure      goto End_Line_Busy,
  396.         "No Dial"         goto End_Line_Busy,
  397.         "Dial Complete"   goto End_Line_Busy,
  398.         "Busy"            goto End_Line_Busy,
  399.         "Ring"            goto End_Line_Busy
  400.     until 56;
  401.  
  402. End_Line_Busy:
  403.     wait until WaitTime;
  404.     goto End_Phone_Loop;
  405.  
  406. Remote_Ring:
  407.     RingCount = RingCount + 1;
  408.     if RingCount <= RingLimit goto Show_Ringing;
  409.  
  410.     FailStr = "No answer";
  411.     goto End_Phone_Loop;
  412.  
  413. Show_Ringing:
  414.     MsgStr = %Phone & " is ringing, awaiting answer";
  415.     show MsgStr;
  416.     goto Start_Phone_Loop;
  417.  
  418. End_Phone_Loop:
  419.     MsgStr = FailStr & ", redialing " & %Phone;
  420.     count = count + 1;
  421.     goto Dial_Phone;
  422.  
  423. Phone_Cancelled:
  424.     gosub Hangup_Before_Connect;
  425.     exit Result;
  426.  
  427. Phone_Failed:
  428.     if FailStr <> "" goto Exit_Fatal;
  429.     FailStr = "Dialing failed";
  430.  
  431. Exit_Fatal:
  432.     define %FailureMsg = FailStr;
  433.     exit %Fatal;
  434.  
  435. Exit_Error:
  436.     define %ErrorCode = 14;
  437. Exit_Failure:
  438.     define %FailureMsg = FailStr;
  439.     exit %Failure;
  440.