home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / am4pmsrc.zip / amc / ring.amc < prev    next >
Text File  |  1996-01-01  |  5KB  |  172 lines

  1. /*********************************************************************/
  2. /* RING.AMC - Make something when it rings                           */
  3. /*                                                                   */
  4. /* This program is called by AM4PM.EXE.                              */
  5. /*                                                                   */
  6. /* Input:  arg(1) The string from DCE resulting in this call         */
  7. /* Input:  arg(2) Number of rings so far                             */
  8. /*                                                                   */
  9. /* Output: 0  Normal. Only AT+VLS=0 is done before waiting           */
  10. /*         1  Full init. Reinit COM-port and everything.             */
  11. /*         2  Terminate AM4PM.                                       */
  12. /*                                                                   */
  13. /*********************************************************************/
  14. signal on syntax
  15. /* signal on failure */
  16.  
  17. SpecialDLE='*#bcde59'
  18.  
  19. CALL AMDPrint 'RING.AMC('arg(1)', 'arg(2)') started'
  20. CALL AMSetLastEventText arg(1)
  21.  
  22. /* Just answer */
  23. CALL AMSendAT('AT+VLS=2{VCON}')
  24.  
  25. CALL AMSetStateText 'Answering call'
  26.  
  27. strGreetFile = 'GREETING.ZVD'
  28. h = time(Hour)
  29.  
  30. if h >= 22 | h <= 1 then
  31. do
  32.    strGreetFile = 'GREETEV.ZVD'
  33. end
  34.  
  35. if h > 1 & h <= 5 then
  36. do
  37.    strGreetFile = 'GREETNI.ZVD'
  38. end
  39.  
  40. if h > 5 & h <= 7 then
  41. do
  42.    strGreetFile = 'GREETMO.ZVD'
  43. end
  44.  
  45. CALL AMSetStateText 'Playing greeting message'
  46.  
  47. DLECode=AMPlayFile(strGreetFile, SpecialDLE)
  48. /* Wait a litle */
  49. if (DLECode=' ') then 
  50.    DLECode=AMWaitDLECode(2500, SpecialDLE)
  51.  
  52. sigdlecode:
  53.  
  54. select
  55. when DLECode='*' then /* User action */
  56.    return ReadCmd(arg(2))
  57. when DLECode='c' | DLECode='#' then
  58.    return StartFax()
  59. when DLECode='5' | DLECode='e' then
  60.    return StartModem()
  61. when DLECode = 'd' | DLECode='b' | DLECode='s' then
  62.    do
  63.       CALL AMSetLastEventText 'No recording'
  64.       return 0
  65.    end
  66. when DLECode='!' then /* Something went wrong */
  67.    return 0;
  68. when DLECode='9' then /* Extended message */
  69.    do
  70.       DLECode=AMPlayFile('INFO.ZVD', SpecialDLE)
  71.       if (DLECode=' ') then 
  72.          DLECode=AMWaitDLECode(2000, SpecialDLE)
  73.       signal sigdlecode
  74.    end
  75. otherwise
  76.    nop
  77. end
  78.  
  79. /* Play the 'beep' */
  80. CALL AMSendAT('AT+VTS=[800,0,12]{OK}')
  81.  
  82. CALL AMSetStateText 'Recording message'
  83.  
  84. CrntMFile=AMOpenRecFile()
  85.  
  86. CALL AMStartRec(3) /* 1 = CELP, 2 = ADPCM2, 3 = ADPCM3 */
  87.  
  88. /* In some countries a dial tone is generated immediately when the calling party hangs up.
  89.    It might then be a good idea to add DLE code 'd' here. */
  90. DLECode=AMWaitDLECode(120000, SpecialDLE'qs')
  91.  
  92. CALL AMEndRec
  93. CALL AMCloseRecFile
  94.  
  95. /* DLECode = 'q' */
  96.  
  97. select
  98. when DLECode='q' then /* Add DLE code 'd' if dial tone is generated when the caller hangs up */
  99.    do
  100.       CALL AMSetLastEventText 'Message stored'
  101.       Descr='Put CID text here'
  102.       DescrEA='FDFF'X || d2c(length(Descr)) || '00'X || Descr
  103.       CALL SysPutEA CrntMfile, '.SUBJECT', DescrEA
  104.       return 0 
  105.    end
  106. otherwise
  107.    'del' CrntMFile
  108.    signal sigdlecode
  109. end
  110.  
  111. Exit 0
  112.  
  113. StartFax:
  114.    CALL AMDPrint 'Fax detected'
  115.    CALL AMSetStateText 'Waiting for fax'
  116.  
  117.    /* Fax2You stuff */
  118.    HotComm=AMGetHotComm()
  119.    SAY 'Starting Fax2You -l %'HotComm '-faxworks -nowait'
  120.    ResCode=AMStartProg('Fax2You -l %'HotComm '-faxworks -nowait')
  121.    SAY 'Fax2You returned' ResCode
  122.    CALL AMReleaseHotComm
  123.    return 1
  124.  
  125.    /* The old stuff */
  126.    CALL AMSendAT 'AT&D0{OK}'  /* Let the connection be open even if the port is closed */
  127.    CALL AMSendAT 'AT+FCLASS=2{OK}'  /* This shouldn't be necessary */
  128.    AMCloseComm()
  129.    AMStartProg('FxRcv -cc')
  130.    CALL AMSetLastEventText 'FxRcv -cc started'
  131.    CALL SysSleep 15 /* Give FaxWorks a chance to open the port */
  132.    /* AM4PM will try to open the port again */
  133. return 1
  134.  
  135.  
  136. StartModem:
  137.    CALL AMDPrint 'Looking for modem'
  138.    CALL AMSetStateText 'Looking for modem'
  139.    CALL AMSendAT 'AT+FCLASS=0{OK}'
  140.    CALL AMSendAT 'ATS35.5=0{OK}'
  141.    CALL AMSendAT 'AT*Q0{OK}'    /* No response to bad signal quality */
  142.    ResCode=AMSendW('ATA')
  143.    select
  144.    when ResCode='NO CARRIER' then
  145.       return 1
  146.    otherwise
  147.       SAY 'Modem detected:' ResCode  
  148.       CALL AMSetLastEventText 'Modem detected'
  149.  
  150.       PARSE VAR ResCode conct localspeed extspeed
  151.       PARSE VAR extspeed thespeed '/' thetype
  152.       thespeed = strip(thespeed)
  153.       SAY 'Starting BBS CON='conct 'Local speed='localspeed 'ext speed='extspeed 'the speed='thespeed
  154.       CALL AMSetLastEventText 'BBS started'
  155.       HotComm=AMGetHotComm()
  156.       ResCode=AMStartProg('MAXP -p'HotComm '-b'thespeed' e:\p\max\max.prm')
  157.       CALL AMDPrint 'MAXP returned' ResCode
  158.       SAY 'MAXP returned' ResCode
  159.       CALL AMReleaseHotComm
  160.       return 1
  161.    end
  162. return 1
  163.  
  164.  
  165. syntax:
  166.    CALL AMLog 'Syntax err: RING.AMC line 'sigl 
  167.    return 1
  168.  
  169. failure:
  170.    CALL AMLog 'Failure: RING.AMC line 'sigl
  171.    return 1
  172.