home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / TURBOPAS / PMODEM.ARK / ROS.MDM < prev    next >
Text File  |  1987-02-22  |  8KB  |  268 lines

  1. { ROSMDM.INC - Remote Operating System Modem Dependent Routines }
  2.  
  3. { File:        ADC4.MDM----->  SMARTEAM.MDM
  4.   Description: This driver is designed to support modems which use the 'AT'
  5.                command set such as the Hayes Smartmodem, the Courier 2400, and
  6.                others.  It ensures that the modem has correctly received the
  7.                command sent from the computer by monitoring the echo from the
  8.                modem.  This prevents potential problems from modems which
  9.                reset or lose characters when a call and a command are received
  10.                simultaneously.
  11.   Date:        7/28/28
  12.   Authors:     Jacques Durosier, Steve Fox
  13.   Credits:     Chris Hueuser, Richard Transue, Steve Holtzclaw
  14.  
  15.   Description: Make computer independent by using calls to channel drivers
  16.                instead of direct port accesses, comment update, and code
  17.                cleanup.
  18.   Date:        9/7/85
  19.   Author:      Mick Gaitor, Steve Fox
  20.  
  21.   Description: Improve operation.
  22.   Date:        10/26/85
  23.   Author:      Steve Fox
  24.  
  25.   Description: Use verbal result codes instead of numeric so that modems
  26.                which do not have a verbal/numeric switch can use closed loop
  27.                driver.
  28.   Date:        4/13/86
  29.   Author:      Steve Fox
  30.  
  31.   Description: Added code to turn speaker off and comment switch settings
  32.                for the ADC 1200 Phone Modem (10) switches.
  33.   Date:        6/12/86
  34.   Author       Terry Smith
  35.  
  36.   The following hardware configuration is assumed:
  37.  
  38.      DCD (pin 8)  is supported and used by the channel procedures
  39.      DTR (pin 20) is supported and used by the channel procedures
  40.      RI  (pin 22) is not supported
  41.  
  42. For the Courier 2400 and the Smarteam 1200, the switches should be set as
  43. follows:
  44.  
  45.      1 = up    DTR supported, do not force to always logic true.
  46.      2 = up    Send result codes as digits.
  47.      3 = down  Send result codes to the host.
  48.      4 = up    Echo characters when in command state.
  49.      5 = down  Do not answer the telephone.
  50.      6 = up    DCD supported, do not force to always logic true.
  51.      7 = up    Single line RJ11 telephone connection to modem.
  52.      8 = down  Enables modem command recognition when in command state.
  53.  
  54.  
  55.     For the ADC 1200 Phone Modem:  Remember  UP = Open   Down = On
  56.  
  57.     1 = down   Enable command recognition
  58.     2 = N/A    Activates beep (your choice)
  59.     3 = up     Use Hayes command set
  60.     4 = down   Do not answer calls
  61.     5 = up     Echo commands in command mode
  62.     6 = down   Send result codes
  63.     7 = up     Send result codes in English
  64.     8 = up     DTR supported
  65.     9 = N/A    Auto redial selector
  66.    10 = up     Respond to DCD
  67.  
  68. }
  69.  
  70. const
  71.     { Modem command strings }
  72.   mdCmdInit   = 'ATH0S0=0S2=3E1X1V1Q0M0'^M;
  73.                { AT                   = get attention
  74.                    H0                 = ensure phone hung up
  75.                      S0=0             = disable modem auto answer function
  76.                          S2=3         = change escape code from '+' to ETX
  77.                              E1       = echo on
  78.                                X1     = extended response set
  79.                                  V1   = word response
  80.                                    Q0 = send modem responses
  81.                }
  82.   mdCmdBusy   = 'ATH1'^M;
  83.   mdCmdHangup = 'ATH'^M;
  84.   mdCmdAns    = 'ATA'^M;
  85.  
  86.     { Modem result codes }
  87.   mdRspOkay   = 'OK';                       { Command executed with no errors }
  88.   mdRspCnct3  = 'CONNECT';                  { Carrier detect at 300 bps }
  89.   mdRspRing   = 'RING';                     { Ring signal detected }
  90.   mdRspNoCar  = 'NO CARRIER';               { Carrier lost or never heard }
  91.   mdRspError  = 'ERROR';                    { Error in command execution }
  92.   mdRspCnct12 = 'CONNECT 1200';             { Carrier detect at 1200 bps }
  93.   mdRspCnct24 = 'CONNECT 2400';             { Carrier detect at 2400 bps }
  94.   mdRspOffhk  = 'OFF HOOK';                 { Modem off hook}
  95.  
  96. type
  97.   Str13       = string[13];
  98.  
  99. procedure mdQuiet;
  100. { Wait for 100 ms of silence }
  101.   var
  102.     i: integer;
  103.   begin
  104.     i := 0;
  105.     repeat
  106.       if ch_inprdy
  107.         then
  108.           begin
  109.             i := ch_inp;
  110.             i := 0
  111.           end
  112.         else
  113.           begin
  114.             delay(5);
  115.             i := succ(i)
  116.           end
  117.     until i >= 20;
  118.   end;
  119.  
  120. function mdReady(sec: integer): boolean;
  121. { Check for input from the modem }
  122.   var
  123.     ctr: integer;
  124.   begin
  125.     ctr := round(6.0 * lps);
  126.     while (not ch_inprdy) and (sec > 0) do  { Loop until ready or timeout }
  127.       begin
  128.         ctr := pred(ctr);
  129.         if ctr <= 0
  130.           then
  131.             begin
  132.               sec := pred(sec);
  133.               ctr := round(6.0 * lps)
  134.             end
  135.       end;
  136.     mdReady := sec > 0
  137.   end;
  138.  
  139. function mdReply(bt: byte; sec: integer): boolean;
  140. { Compare the input to what was sent out }
  141.   begin
  142.     if mdReady(sec)
  143.       then mdReply := bt = ch_inp
  144.       else mdReply := FALSE
  145.   end;
  146.  
  147. function mdResult: Str13;
  148. { Get result code from modem }
  149.   var
  150.     ch: char;
  151.     result: Str13;
  152.   begin
  153.     result := '';
  154.     repeat
  155.       if mdReady(5)
  156.         then ch := chr($7F and ch_inp)      { Get input }
  157.         else
  158.           begin
  159.             result := mdRspError;
  160.             ch := LF
  161.           end;
  162.       if ch in [' '..'_']
  163.         then result := result + ch;
  164.       if length(result) > 12
  165.         then delete(result, 1, 1)
  166.     until ch = LF;
  167. gotoxy (1,1);
  168.     mdResult := result
  169.   end;
  170.  
  171. function mdCommand(stg: StrPr; sec: integer): Str13;
  172. { Send a command string to the modem }
  173.   var
  174.     OK: boolean;
  175.     bt: byte;
  176.     i: integer;
  177.   begin
  178.     mdQuiet;
  179.     i := 1;
  180.     repeat
  181.       bt := ord(stg[i]);
  182.       i := succ(i);
  183.       ch_out(bt);                           { Send the character }
  184.       OK := mdReply(bt, sec)
  185.     until (not OK) or (i > length(stg));
  186.     if OK
  187.       then OK := mdReply(ord(CR), sec);
  188.     if OK
  189.       then OK := mdReply(ord(LF), sec);
  190.     if OK
  191.       then mdCommand := mdResult
  192.       else mdCommand := mdRspError
  193.   end;
  194.  
  195. procedure mdInit;
  196. { Ensure the modem is hung up, initialized, and ready to wait for a ring. }
  197.   var
  198.     tries: integer;
  199.   begin
  200.     tries := 3;
  201.     ch_init;                                { Initialize the remote channel }
  202.     ch_on;
  203.     ch_set(1200);                            { Set the channel speed }
  204.     repeat
  205.       tries := pred(tries)
  206.     until (mdCommand(mdCmdInit, 5) = mdRspOkay) or (tries <= 0);
  207.     mdQuiet
  208.   end;
  209.  
  210. procedure mdBusy;
  211. { Take modem off hook to present a busy signal to incoming callers }
  212.   var
  213.     tries: integer;
  214.   begin
  215.     tries := 3;
  216.     repeat
  217.       tries := pred(tries)
  218.     until (mdCommand(mdCmdBusy, 5) = mdRspOkay) or (tries <= 0)
  219.   end;
  220.  
  221. procedure mdHangup;
  222. { Hangup modem }
  223.   var
  224.     i, tries: integer;
  225.     result: Str13;
  226.   begin
  227.     tries := 3;
  228.     repeat
  229.       ch_off;
  230.       delay(500);
  231.       ch_on;
  232.       if ch_carck
  233.         then
  234.           begin
  235.             delay(1000);
  236.             for i := 1 to 3 do
  237.               ch_out(ord(ETX));
  238.             delay(1000);
  239.             result := mdCommand(mdCmdHangup, 5)
  240.           end;
  241.       tries := pred(tries)
  242.     until not ch_carck or (tries <= 0)
  243.   end;
  244.  
  245. function mdRing: boolean;
  246. { Determine if the phone is ringing }
  247.   begin
  248.     if ch_inprdy
  249.       then mdRing := mdResult = mdRspRing
  250.       else mdRing := FALSE
  251.   end;
  252.  
  253. procedure mdAns;
  254. { Answer call and set system to correct baud rate }
  255.   var
  256.     result: Str13;
  257.   begin
  258.     result := mdCommand(mdCmdAns, 35);      { Let the modem answer }
  259.     if result = mdRspCnct3
  260.       then ch_set(300)
  261.     else if result = mdRspCnct12
  262.       then ch_set(1200)
  263. (*  else if result = mdRspCnct24
  264.       then ch_set(2400)
  265. *)    else mdHangup;
  266.     mdQuiet
  267.   end;
  268.