home *** CD-ROM | disk | FTP | other *** search
/ 3,500 Cliparts Vectoriels 2 / 3500_V2.iso / compu / csi302f / scripts.lib / phone.scr < prev    next >
Text File  |  1997-01-30  |  6KB  |  281 lines

  1. !
  2. !  Copyright (c) 1996
  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.3F"
  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.     define %State = 2;
  61.     show "Initialisation du modem";
  62.     MsgStr = "NumΘrotation de " & %Phone;
  63.     tries = 0;
  64.  
  65. Send_Reset_String:
  66.     if (%mdm_Reset = "") goto Modem_OK;
  67.     sendm %mdm_Prefix;
  68.     sendm %mdm_Reset;
  69.     sendm %mdm_Suffix;
  70.  
  71. Send_Wait:
  72.     wait
  73.         "User Id"   goto Send_User_ID,
  74.         "Password"  goto Send_Password,
  75.         %mdm_Ack    goto Modem_OK,
  76.         "0"     goto Modem_OK,
  77.         "ERROR"     goto Send_Z
  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.     define %ErrorCode = 10;
  88.     FailStr = "Le modem ne rΘpond pas";
  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 %ErrorCode = 11;
  112.     define %FailureMsg = "User ID ou mot de passe de sΘcuritΘ du modem non valide";
  113.     exit %Fatal;
  114.  
  115. Send_Z:
  116.     if %mdm_Reset = "Z" goto Modem_OK;
  117.     if Z_Sent goto Modem_OK;
  118.     wait until 5;
  119.     Z_Sent = %TRUE;
  120.     sendm %mdm_Prefix;
  121.     sendm "Z";
  122.     sendm %mdm_Suffix;
  123.     goto Send_Wait;
  124.  
  125. Modem_OK:
  126.     wait until 10;
  127.     if (%mdm_Init = "") goto Check_Speed;
  128.     sendm %mdm_Init;
  129.  
  130.     wait
  131.         %mdm_Ack    goto Check_Speed,
  132.         "ERROR"     goto Show_Init_Error
  133.     until 33;
  134.     FailStr = "Le modem ne rΘpond pas";
  135.     define %ErrorCode = 12;
  136.     goto Phone_Failed;
  137.  
  138. Show_Init_Error:
  139.     show "Erreur dans la commande du modem";
  140.     wait until 10;
  141.  
  142. Check_Speed:
  143. !   sendm %mdm_Prefix;
  144. !   sendm "&B1";
  145. !   sendm %mdm_Suffix;
  146.  
  147. !   wait
  148. !       %mdm_Ack    goto Check_Modem_Speaker,
  149. !       "ERROR"     goto Check_Modem_Speaker
  150. !   until 33;
  151.  
  152. Check_Modem_Speaker:
  153.     if (%mdm_Speaker <> 0) goto Check_DC;
  154.     MdmCmd = "M0";
  155.  
  156. Check_DC:
  157.     if %mdm_DCOn = "" goto Check_EC;
  158.     MdmCmd = MdmCmd & %mdm_DCOn;
  159.     goto Wait_Ack;
  160.  
  161. Check_EC:
  162.     if %mdm_ECOn = "" goto Wait_Ack;
  163.     MdmCmd = MdmCmd & %mdm_ECOn;
  164.  
  165. Wait_Ack:
  166.     if MdmCmd = "" goto Try_Phone;
  167.     wait until 2;           ! delay for 300 baud modems
  168.     sendm %mdm_Prefix & MdmCmd & %mdm_Suffix;
  169.  
  170.     wait
  171.         %mdm_Ack    goto Try_Phone,
  172.         "ERROR"     goto Show_Proto_Error
  173.     until 33;
  174.     goto Try_Phone;
  175.  
  176. Show_Proto_Error:
  177.     show "Erreur dans la commande du modem";
  178.  
  179. Try_Phone:
  180.     wait until 10;
  181.     count = 0;
  182.     FailStr = "";
  183. Dial_Phone:
  184.     if (count > %Retry) goto Exit_Error;
  185.     define %ErrorCode = 0;
  186.     define %State = 3;
  187.  
  188.     show MsgStr;
  189.     
  190.     sendm %mdm_Prefix;
  191.     sendm DialTypeStr & %Phone;
  192.     sendm %mdm_Suffix;
  193.  
  194. Start_Phone_Loop:
  195.     wait
  196.         %mdm_Success    goto Modem_Success,
  197.         %mdm_Failure    goto Modem_Failure,
  198.         "No Dial"   goto No_Dial_Tone,
  199.         "Dial Complete" goto Dial_Complete,
  200.         "Busy"      goto Line_Busy,
  201.         "Ring"      goto Remote_Ring
  202.     until 856;
  203.  
  204.     FailStr = "Echec α la numΘrotation";
  205.     goto End_Phone_Loop;
  206.  
  207. Modem_Success:
  208.     wait until 5;
  209. Direct_Connect:
  210.     exit %Success;
  211.  
  212. Modem_Failure:
  213.     FailStr = "NumΘrotation infructueuse";
  214.     wait until WaitTime;
  215.     goto End_Phone_Loop;
  216.  
  217. No_Dial_Tone:
  218.     FailStr = "Pas de tonalitΘ";
  219.     define %ErrorCode = 13;
  220.     goto Exit_Failure;
  221.  
  222. Dial_Complete:
  223.     MsgStr = "NumΘrotation de " & %Phone & " accomplie, en attente de rΘponse";
  224.     show MsgStr;
  225.     goto Start_Phone_Loop;
  226.  
  227. Line_Busy:
  228.     FailStr = "Le numΘro est occupΘ";
  229.     wait until 2 * WaitTime;
  230.     send %CR;
  231.  
  232.     wait
  233.         %mdm_Success    goto End_Line_Busy,
  234.         %mdm_Failure    goto End_Line_Busy,
  235.         "No Dial"   goto End_Line_Busy,
  236.         "Dial Complete" goto End_Line_Busy,
  237.         "Busy"      goto End_Line_Busy,
  238.         "Ring"      goto End_Line_Busy
  239.     until 56;
  240.  
  241. End_Line_Busy:
  242.     define %ErrorCode = 15;
  243.     wait until WaitTime;
  244.     goto End_Phone_Loop;
  245.  
  246. Remote_Ring:
  247.     RingCount = RingCount + 1;
  248.     if RingCount <= RingLimit goto Show_Ringing;
  249.  
  250.     FailStr = "Pas de rΘponse";
  251.     goto End_Phone_Loop;
  252.  
  253. Show_Ringing:
  254.     MsgStr = "Le numΘro " & %Phone & " sonne, en attente de rΘponse";
  255.     show MsgStr;
  256.     goto Start_Phone_Loop;
  257.  
  258. End_Phone_Loop:
  259.     MsgStr = FailStr & ", numΘrotation de " & %Phone;
  260.     count = count + 1;
  261.     goto Dial_Phone;
  262.  
  263. Phone_Cancelled:
  264.     gosub Hangup_Before_Connect;
  265.     exit Result;
  266.  
  267. Phone_Failed:
  268.     if FailStr <> "" goto Exit_Fatal;
  269.     FailStr = "Echec α la numΘrotation";
  270.  
  271. Exit_Fatal:
  272.     define %FailureMsg = FailStr;
  273.     exit %Fatal;
  274.  
  275. Exit_Error:
  276.     if %ErrorCode <> 0 goto Exit_Failure;
  277.     define %ErrorCode = 14;
  278. Exit_Failure:
  279.     define %FailureMsg = FailStr;
  280.     exit %Failure;
  281.