home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / am4pm08f.zip / ring.amc < prev   
Text File  |  1993-07-14  |  6KB  |  236 lines

  1. /*********************************************************************/
  2. /* RING.AMC - Make something when it rings                           */
  3. /*                                                                   *//* This program is called by AM4PM.EXE.                              */
  4. /*                                                                   *//* Input:  arg(1) The string from DCE resulting in this call         */
  5. /* Input:  arg(2) Number of rings so far                             */
  6. /*                                                                   *//* Output: 0  Normal. Only AT+VLS=0 is done before waiting           */
  7. /*         1  Full init. Reinit COM-port and everything.             */
  8. /*         2  Terminate AM4PM.                                       */
  9. /*                                                                   *//*********************************************************************/
  10. PlayBackCode='123'      /* Code for playing back messages */
  11. ModemCode='secret'     /* Code for accessing OS2YOU */
  12.  
  13. CALL AMDPrint 'RING.AMC('arg(1)', 'arg(2)') started'
  14. CALL AMSetLastEventText arg(1)
  15.  
  16. if \ (arg(1) = 'VCON') then
  17. do
  18.    /* Answer in fewer rings if there are messages waiting */ 
  19.    if vAMMsgs = 0 then rings=vAMRings
  20.                   else rings=vAMRings-1
  21.  
  22.    if arg(2) < rings then return 0
  23. end
  24.  
  25. CALL AMSetStateText 'Playing greeting message'
  26. AMSendW('AT+VLS=2')
  27.  
  28. DLECode=AMPlayFile('GREETING.ZVD')
  29.  
  30. select
  31. when DLECode='*' then
  32.    return ReadCmd()
  33. when DLECode='c' | DLECode='#' then
  34.    return StartFax()
  35. when DLECode='5' then
  36.    return StartModem()
  37. when DLECode='b' then
  38.    do
  39.       CALL AMSetLastEventText 'Busy'
  40.       return 0
  41.    end
  42. when DLECode='!' then
  43.    return 0;
  44. otherwise
  45.    nop
  46. end
  47.  
  48. AMSendW('AT+VTS=[800,0,12]')
  49.  
  50. CALL AMSetStateText 'Recording message'
  51.  
  52. CrntMFile=AMOpenRecFile()
  53.  
  54. CALL AMStartRec(1) /* 1 = CELP, 2 = ADPCM2, 3 = ADPCM3 */
  55.  
  56. DLECode=AMWaitDLECode()
  57.  
  58. CALL AMEndRec
  59. CALL AMCloseRecFile
  60.  
  61. /* DLECode = 'q' */
  62.  
  63. select
  64. when DLECode='c' | DLECode='#' then
  65.    do
  66.       'del' CrntMFile
  67.       return StartFax()
  68.    end
  69. when DLECode='5' | DLECode='s' then
  70.    do
  71.       'del' CrntMFile
  72.       return StartModem()
  73.    end
  74. when DLECode='b' then
  75.    do
  76.       'del' CrntMFile
  77.       CALL AMSetLastEventText 'Busy'
  78.       return 0
  79.    end
  80. when DLECode='q' then
  81.    do
  82.       CALL AMSetLastEventText 'Message stored'
  83.       Descr='Put CID text here'
  84.       DescrEA='FDFF'X || d2c(length(Descr)) || '00'X || Descr
  85.       CALL SysPutEA CrntMfile, '.SUBJECT', DescrEA
  86.       return 0 
  87.    end
  88. when DLECode='*' then
  89.    return ReadCmd()
  90. otherwise
  91.    nop
  92. end
  93.  
  94. Exit 0
  95.  
  96.  
  97.  
  98. ReadCmd:
  99.  
  100.    CALL AMSetStateText 'Waiting for command'
  101.  
  102.    AMSendW('AT+VTS=[1600,0,5]')
  103.    CALL AMStartListenDLECode
  104.  
  105.    UsrCmd=""
  106.    ContProcCmd=1
  107.  
  108.    do while ContProcCmd
  109.       DLECode=AMWaitDLECode()
  110.       select
  111.       when DLECode='q' | DLECode='s' | DLECode='b' | DLECode='c' then
  112.          do
  113.             ContProcCmd=0
  114.          end
  115.       when DLECode='*' then
  116.          do 
  117.             CALL AMEndListenDLECode
  118.             AMSendW('AT+VTS=[1600,0,5]')
  119.             CALL AMStartListenDLECode
  120.             UsrCmd=""
  121.          end
  122.       when DLECode='#' then
  123.          do
  124.             CALL AMEndListenDLECode
  125.             CALL ProcCmd UsrCmd
  126.             CALL AMStartListenDLECode
  127.             UsrCmd=""
  128.          end
  129.       when DLECode >= 0 & DLECode <= 9 then
  130.          UsrCmd = UsrCmd""DLECode
  131.       otherwise
  132.          nop
  133.       end
  134.    end
  135.  
  136.    CALL AMEndListenDLECode
  137. return 0
  138.  
  139.  
  140.  
  141. ProcCmd: arg UsrCmd
  142.  
  143.    CALL AMDPrint 'UsrCmd' UsrCmd
  144.  
  145.    select
  146.    when UsrCmd=PlayBackCode then
  147.       CALL PlayAllFiles 
  148.    otherwise
  149.       AMSendW('AT+VTS=[400,0,10]')
  150.    end
  151.  
  152. return 0
  153.  
  154.  
  155. PlayAllFiles:
  156.  
  157.    CALL AMSetStateText 'Playing back messages'
  158.    CALL AMSetLastEventText 'Playback'
  159.    AMPlayFile('GREET2.ZVD')
  160.  
  161.    CALL SysFileTree 'M*.ZVD', 'file.', 'FO'
  162.    if file.0 = 0 then
  163.    do
  164.        AMPlayFile('NOMSG.ZVD') /* There are no messages */
  165.        return 0
  166.    end
  167.  
  168.    AMPlayFile('SOMEMSGS.ZVD') /* Here comes the messages */
  169.  
  170.    do i=1 to file.0
  171.       DLECode=AMPlayFile(file.i)
  172.       if \ (DLECode='1' | DLECode='2' | DLECode='3') then
  173.       do
  174.          CALL AMStartListenDLECode
  175.          DLECode=AMWaitDLECode()
  176.          CALL AMEndListenDLECode
  177.       end
  178.  
  179.       select
  180.       when DLECode='2' then
  181.          do
  182.            'del' file.i
  183.            AMPlayFile('DELMSG.ZVD') /* Message deleted */
  184.          end
  185.       when DLECode='3' then
  186.          i=i-1
  187.       otherwise
  188.          nop
  189.       end
  190.  
  191.    end
  192.  
  193.    AMPlayFile('ENDMSGS.ZVD') /* That was all messages */
  194.  
  195. return 0
  196.  
  197.  
  198. StartFax:
  199.  
  200.    CALL AMDPrint 'Fax detected'
  201.    CALL AMSetStateText 'Waiting for fax'
  202.    AMSendW('AT&D0') /* Let the connection be open even if the port is closed */
  203.    AMCloseComm()
  204.    AMStartProg('FxRcv -cc')
  205.    CALL AMSetLastEventText 'FxRcv -cc started'
  206.    SysSleep(15) /* Give FaxWorks a chance to open the port */
  207.    /* AM4PM will try to open the port again */
  208. return 1
  209.  
  210.  
  211. StartModem:
  212.  
  213.    CALL AMDPrint 'Looking for modem'
  214.    CALL AMSetStateText 'Looking for modem'
  215.    AMSendW('AT+FCLASS=0')
  216.    ResCode=AMSendW('ATA')
  217.    select
  218.    when ResCode='NO CARRIER' then
  219.       return 1
  220.    otherwise
  221.       do
  222.          CALL AMSetLastEventText 'Modem detected'
  223.          pw=AMSendW('Enter password+(ctrl-j)')
  224.          if pw=ModemCode then
  225.          do
  226.             CALL AMSetLastEventText 'OS2YOU started'
  227.             HotComm=AMGetHotComm()
  228.             ResCode=AMStartProg('Os2You -l' HotComm '-i 300 -f 100 -e cmd.exe')
  229.             CALL AMDPrint 'Os2You returned' ResCode
  230.             CALL AMReleaseHotComm
  231.          end
  232.          return 1
  233.       end
  234.    end
  235. return 0
  236.