home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703B.ISO / terminal / niftyman / w95nim / program / data.z / SPHONE.SCR < prev    next >
Text File  |  1996-11-19  |  6KB  |  284 lines

  1. !
  2. !  Copyright (c) 1995
  3. !  by NIFTY Corporation, Tokyo, Japan
  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 NIFTY-Serve.
  8. !
  9. !  PHONE:
  10. !    Contains modem/phone related logic.
  11. !    Success:  returns %Success
  12. !    Failure:  saves error msg in %FailureMsg and returns %Failure
  13. !
  14. !+V
  15. ! "3.5"
  16. !-V
  17.  
  18. MdmCmd = "";
  19. Z_Sent = %FALSE;
  20.  
  21. WaitTime = 10;
  22. ifndef %mdm_UserID = "";
  23. ifndef %mdm_Password = "";
  24. ifndef %mdm_ECOn = "";
  25. ifndef %mdm_DCOn = "";
  26.  
  27. if %DialType = 2 goto Direct_Connect;
  28.  
  29. goto Do_Phone_Connect;
  30.  
  31. !
  32. ! Subroutines
  33. !
  34. Hangup_Before_Connect:
  35.     define %LOCAL = 2;
  36. !    call %Dir & "disconct.scr" () : Result;
  37.     return;
  38.  
  39. Two_Tries_Hangup:
  40.     gosub Hangup_Before_Connect;
  41.     goto Send_Reset_String;
  42.  
  43.  
  44. !
  45. ! Main Program:  Start_Connect
  46. !
  47. Do_Phone_Connect:
  48.     RingLimit = 5;
  49.     RingCount = 0;
  50.     UsingModem = %FALSE;
  51.     on cancel goto Phone_Cancelled;
  52.  
  53.     if %DialType = 0 goto Get_Tone_Str;
  54.     DialTypeStr = %mdm_Pulse_Dial;        ! Type = DT_Pulse
  55.     goto Init_Modem;
  56.  
  57. Get_Tone_Str:
  58.     DialTypeStr = %mdm_Tone_Dial;        ! Type = DT_Tone
  59.  
  60. Init_Modem:
  61.     guide "モデムの初期化をしています";
  62.     MsgStr = "Dialing " & %Phone;
  63.     tries = 0;
  64.  
  65. Send_Reset_String:
  66.     goto Modem_OK;
  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.     FailStr = "モデムが反応しません";
  89.     goto Phone_Failed;
  90.  
  91. Send_User_ID:
  92.     !
  93.     ! For those modems that support password security...
  94.     !
  95.     send %mdm_UserID & "^M";
  96.     goto Send_Wait;
  97.  
  98. Send_Password:
  99.     !
  100.     ! For those modems that support password security...
  101.     !
  102.     send %mdm_Password & "^M";
  103.     wait
  104.         "User id"    goto Modem_Security_Error,
  105.         %mdm_Ack    goto Send_Reset_String,
  106.         "0"        goto Send_Reset_String
  107.     until 100;
  108.     goto Send_Reset_String;
  109.  
  110. Modem_Security_Error:
  111.     define %FailureMsg = "シリアルナンバー、アグリメントナンバーが違っています";
  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 = "モデムが反応しません";
  134.     goto Phone_Failed;
  135.  
  136. Show_Init_Error:
  137.     guide "モデムコマンドがエラーを返しています";
  138.     wait until 10;
  139.     %ErrorCode = 1009;
  140.     exit %ErrorCode;
  141.  
  142. Check_Modem_Speaker:
  143.     if (%mdm_Speaker <> 0) goto Check_DC;
  144.     MdmCmd = "M0";
  145.  
  146. Check_DC:
  147.     if %mdm_DCOn = "" goto Check_EC;
  148.     MdmCmd = MdmCmd & %mdm_DCOn;
  149.     goto Wait_Ack;
  150.  
  151. Check_EC:
  152.     if %mdm_ECOn = "" goto Wait_Ack;
  153.     MdmCmd = MdmCmd & %mdm_ECOn;
  154.  
  155. Wait_Ack:
  156.     if MdmCmd = "" goto Try_Phone;
  157.     wait until 2;            ! delay for 300 baud modems
  158.     sendm %mdm_Prefix & MdmCmd & %mdm_Suffix;
  159.  
  160.     wait
  161.         %mdm_Ack    goto Try_Phone,
  162.         "ERROR"        goto Show_Proto_Error
  163.     until 33;
  164.     goto Try_Phone;
  165.  
  166. Show_Proto_Error:
  167.     guide "モデムコマンドがエラーを返しています";
  168.     %ErrorCode = 1009;
  169.     exit %ErrorCode;
  170.  
  171. Try_Phone:
  172.     wait until 10;
  173.     count = 0;
  174.     FailStr = "";
  175. Dial_Phone:
  176.     if (count > %mdm_Retry) goto Exit_Error;
  177. !    if (count > %Retry) goto Exit_Error;
  178.  
  179.     guide MsgStr;
  180.     
  181.     sendm %mdm_Prefix;
  182.     sendm DialTypeStr & %Phone;
  183.     sendm %mdm_Suffix;
  184.  
  185. Start_Phone_Loop:
  186.     wait
  187.         %mdm_Success    goto Modem_Success,
  188.         %mdm_Failure    goto Modem_Failure,
  189.         "No Dial"    goto No_Dial_Tone,
  190.         "Dial Complete"    goto Dial_Complete,
  191.         "Busy"        goto Line_Busy,
  192.         "Ring"        goto Remote_Ring
  193.         %mdm_Ack    goto Modem_Success
  194.     until 556;
  195.  
  196.     FailStr = "Dialing failed";
  197.     goto End_Phone_Loop;
  198.  
  199. Modem_Success:
  200.     wait until 5;
  201. Direct_Connect:
  202.     exit %Success;
  203.  
  204. Modem_Failure:
  205.     FailStr = "ダイヤリングに失敗しました、電話番号を確認してください";
  206.     wait until WaitTime;
  207.     goto End_Phone_Loop;
  208.  
  209. No_Dial_Tone:
  210.     guide "ダイヤルトーンがありません";
  211.     %ErrorCode = 1010;
  212.     exit %ErrorCode;
  213.  
  214. Dial_Complete:
  215.     MsgStr = "アクセスポイント " & %Phone & " にダイヤルしています";
  216.     guide MsgStr;
  217.     goto Start_Phone_Loop;
  218.  
  219. Line_Busy:
  220.     FailStr = "アクセスポイントがビジーです";
  221.     guide "アクセスポイントがビジーです";
  222.     wait until 2 * WaitTime;
  223.     send %CR;
  224.  
  225.     wait
  226.         %mdm_Success    goto End_Line_Busy,
  227.         %mdm_Failure    goto End_Line_Busy,
  228.         "No Dial"    goto End_Line_Busy,
  229.         "Dial Complete"    goto End_Line_Busy,
  230.         "Busy"        goto End_Line_Busy,
  231.         "Ring"        goto End_Line_Busy
  232.     until 56;
  233.  
  234. End_Line_Busy:
  235. !    wait until WaitTime;
  236. Tries = %mdm_Interval;
  237.  
  238. Busy_Loop:
  239.     if Tries = 0 goto End_Phone_Loop;
  240.     guide "リダイヤル待機中、" & Tries & "秒間お待ちください";
  241.     Tries = Tries - 1;
  242.  
  243.     send %CR;
  244.     wait
  245.         %Cancel        goto End_Phone_Loop
  246.     until 10;
  247.     goto Busy_Loop;
  248.  
  249. !    guide "リダイヤル待機中" & %mdm_Interval & "秒間お待ちください";
  250. !    wait until 10 * %mdm_Interval;
  251. !    goto End_Phone_Loop;
  252.  
  253. Remote_Ring:
  254.     RingCount = RingCount + 1;
  255.     if RingCount <= RingLimit goto Show_Ringing;
  256.  
  257.     FailStr = "No answer";
  258.     goto End_Phone_Loop;
  259.  
  260. Show_Ringing:
  261.     MsgStr = %Phone & " 呼び出しを行っています";
  262.     guide MsgStr;
  263.     goto Start_Phone_Loop;
  264.  
  265. End_Phone_Loop:
  266. !    MsgStr = FailStr & " リダイヤルしています " & %Phone;
  267.     MsgStr = %Phone & " へリダイヤルしています ";
  268.     count = count + 1;
  269.     goto Dial_Phone;
  270.  
  271. Phone_Cancelled:
  272.     gosub Hangup_Before_Connect;
  273.     exit Result;
  274.  
  275. Phone_Failed:
  276.     %ErrorCode = 1007;
  277.     exit %ErrorCode;
  278.  
  279. Exit_Error:
  280.     FailStr = "電話がつながりません”
  281.     define %FailureMsg = FailStr;
  282.     %ErrorCode = 1011;
  283.     exit %ErrorCode;
  284.