home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / com / am4pm / ring.cmd < prev   
Encoding:
Text File  |  1993-05-29  |  5.1 KB  |  211 lines

  1. /*********************************************************************/
  2. /* RING.CMD - Make something when it rings                           */
  3. /*                                                                   */
  4. /* This program is called by AM4PM.EXE.                              */
  5. /*                                                                   */
  6. /* Input:  None                                                      */
  7. /*                                                                   */
  8. /* Output: 0  Normal. Only AT+VLS=0 is done before waiting           */
  9. /*         1  Full init. Reinit COM-port and everything.             */
  10. /*         2  Terminate AM4PM.                                       */
  11. /*                                                                   */
  12. /*********************************************************************/
  13.  
  14. CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  15. CALL SysLoadFuncs
  16.  
  17. CALL AMDPrint 'RING.AM started'
  18. CALL AMSetStateText 'Playing greeting message'
  19.  
  20. AMSendW('AT+VLS=2')
  21.  
  22. DLECode=AMPlayFile('GREETING.ZVD')
  23.  
  24. select
  25. when DLECode='*' then
  26.    return ReadCmd()
  27. when DLECode='c' | DLECode='5' | DLECode='#' then
  28.    return StartFaxOrModem()
  29. when DLECode='b' then
  30.    do
  31.       CALL AMSetLastEventText 'Busy'
  32.       return 0
  33.    end
  34. otherwise
  35.    nop
  36. end
  37.  
  38. AMSendW('AT+VTS=[800,0,12]')
  39.  
  40. CALL AMSetStateText 'Recording message'
  41.  
  42. CrntMFile=AMOpenRecFile()
  43.  
  44. CALL AMStartRec(1) /* 1 = CELP, 2 = ADPCM2, 3 = ADPCM3 */
  45.  
  46. DLECode=AMWaitDLECode()
  47.  
  48. CALL AMEndRec
  49. CALL AMCloseRecFile
  50.  
  51. select
  52. when DLECode='c' | DLECode='5' | DLECode='#' | DLECode='s' then
  53.    do
  54.       'del' CrntMFile
  55.       return StartFaxOrModem()
  56.    end
  57. when DLECode='b' then
  58.    do
  59.       'del' CrntMFile
  60.       CALL AMSetLastEventText 'Busy'
  61.       return 0
  62.    end
  63. when DLECode='q' then
  64.    do
  65.       CALL AMSetLastEventText 'Message stored'
  66.       return 0 
  67.    end
  68. when DLECode='*' then
  69.    return ReadCmd()
  70. otherwise
  71.    nop
  72. end
  73.  
  74. Exit 0
  75.  
  76.  
  77.  
  78. ReadCmd:
  79.  
  80.    CALL AMSetStateText 'Waiting for command'
  81.  
  82.    AMSendW('AT+VTS=[1600,0,5]')
  83.    CALL AMStartListenDLECode
  84.  
  85.    UsrCmd=""
  86.    ContProcCmd=1
  87.  
  88.    do while ContProcCmd
  89.       DLECode=AMWaitDLECode()
  90.       select
  91.       when DLECode='q' | DLECode='s' | DLECode='b' | DLECode='c' then
  92.          do
  93.             ContProcCmd=0
  94.          end
  95.       when DLECode='*' then
  96.          do 
  97.             CALL AMEndListenDLECode
  98.             AMSendW('AT+VTS=[1600,0,5]')
  99.             CALL AMStartListenDLECode
  100.             UsrCmd=""
  101.          end
  102.       when DLECode='#' then
  103.          do
  104.             CALL AMEndListenDLECode
  105.             CALL ProcCmd UsrCmd
  106.             CALL AMStartListenDLECode
  107.             UsrCmd=""
  108.          end
  109.       when DLECode >= 0 & DLECode <= 9 then
  110.          UsrCmd = UsrCmd""DLECode
  111.       otherwise
  112.          nop
  113.       end
  114.    end
  115.  
  116.    CALL AMEndListenDLECode
  117. return 0
  118.  
  119.  
  120.  
  121. ProcCmd: arg UsrCmd
  122.  
  123.    CALL AMDPrint 'UsrCmd' UsrCmd
  124.  
  125.    select
  126.    when UsrCmd='123' then
  127.       CALL PlayAllFiles 
  128.    otherwise
  129.       AMSendW('AT+VTS=[400,0,10]')
  130.    end
  131.  
  132. return 0
  133.  
  134.  
  135. PlayAllFiles:
  136.  
  137.    CALL AMSetStateText 'Playing back messages'
  138.    CALL AMSetLastEventText 'Playback'
  139.    AMPlayFile('GREET2.ZVD')
  140.  
  141.    CALL SysFileTree 'M*.ZVD', 'file.', 'FO'
  142.    if file.0 = 0 then
  143.    do
  144.        AMPlayFile('NOMSG.ZVD') /* There are no messages */
  145.        return 0
  146.    end
  147.  
  148.    AMPlayFile('SOMEMSGS.ZVD') /* Here comes the messages */
  149.  
  150.    do i=1 to file.0
  151.       DLECode=AMPlayFile(file.i)
  152.       if \ (DLECode='1' | DLECode='2' | DLECode='3') then
  153.       do
  154.          CALL AMStartListenDLECode
  155.          DLECode=AMWaitDLECode()
  156.          CALL AMEndListenDLECode
  157.       end
  158.  
  159.       /* Interpret user action: 
  160.          1 - next message, 2 - delete message, 3 - replay message 
  161.       */
  162.       select
  163.       when DLECode='2' then
  164.          do
  165.            'del' file.i
  166.            AMPlayFile('DELMSG.ZVD') /* Message deleted */
  167.          end
  168.       when DLECode='3' then
  169.          i=i-1
  170.       otherwise
  171.          nop
  172.       end
  173.  
  174.    end
  175.  
  176.    AMPlayFile('ENDMSGS.ZVD') /* That was all messages */
  177.  
  178. return 0
  179.  
  180.  
  181. StartFaxOrModem:
  182.  
  183.    CALL AMSetStateText 'Looking for fax or modem'
  184.    AMSendW('AT#B1+FCLASS=6')
  185.    AMSendW('AT+FLID=Thomas Olsson')
  186.    AMSendW('AT#P46 31 822239')
  187.    ResCode=AMSendW('ATA')
  188.    select
  189.    when ResCode='CONNECT FAX' then
  190.       do
  191.         CALL AMSetLastEventText 'ReFax2 started'
  192.         HotComm=AMGetHotComm()
  193.         ResCode=AMStartProg('ReFax2' HotComm 'fax\')
  194.         CALL AMDPrint 'Refax returned' ResCode
  195.         CALL AMReleaseHotComm
  196.         return 1
  197.       end
  198.    when ResCode='NO CARRIER' then
  199.       return 1
  200.    otherwise
  201.       do
  202.          CALL AMSetLastEventText 'Modem detected'
  203.          pw=AMSendW('Enter password+(ctrl-j)')
  204.          if pw='secret' then
  205.          do
  206.             CALL AMSetLastEventText 'OS2YOU started'
  207.             HotComm=AMGetHotComm()
  208.             ResCode=AMStartProg('Os2You -l' HotComm '-i 300 -f 100 -e cmd.exe')
  209.             CALL AMDPrint 'Os2You returned' ResCode
  210.             CALL AMReleaseHotComm
  211.             return 1
  212.          end
  213.       end
  214.    end
  215. return 0
  216.